jasny-bootstrap.js 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. /*!
  2. * Jasny Bootstrap v3.1.3 (http://jasny.github.io/bootstrap)
  3. * Copyright 2012-2014 Arnold Daniels
  4. * Licensed under Apache-2.0 (https://github.com/jasny/bootstrap/blob/master/LICENSE)
  5. */
  6. if (typeof jQuery === 'undefined') { throw new Error('Jasny Bootstrap\'s JavaScript requires jQuery') }
  7. /* ========================================================================
  8. * Bootstrap: transition.js v3.1.3
  9. * http://getbootstrap.com/javascript/#transitions
  10. * ========================================================================
  11. * Copyright 2011-2014 Twitter, Inc.
  12. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  13. * ======================================================================== */
  14. +function ($) {
  15. 'use strict';
  16. // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/)
  17. // ============================================================
  18. function transitionEnd() {
  19. var el = document.createElement('bootstrap')
  20. var transEndEventNames = {
  21. WebkitTransition : 'webkitTransitionEnd',
  22. MozTransition : 'transitionend',
  23. OTransition : 'oTransitionEnd otransitionend',
  24. transition : 'transitionend'
  25. }
  26. for (var name in transEndEventNames) {
  27. if (el.style[name] !== undefined) {
  28. return { end: transEndEventNames[name] }
  29. }
  30. }
  31. return false // explicit for ie8 ( ._.)
  32. }
  33. if ($.support.transition !== undefined) return // Prevent conflict with Twitter Bootstrap
  34. // http://blog.alexmaccaw.com/css-transitions
  35. $.fn.emulateTransitionEnd = function (duration) {
  36. var called = false, $el = this
  37. $(this).one($.support.transition.end, function () { called = true })
  38. var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
  39. setTimeout(callback, duration)
  40. return this
  41. }
  42. $(function () {
  43. $.support.transition = transitionEnd()
  44. })
  45. }(window.jQuery);
  46. /* ========================================================================
  47. * Bootstrap: offcanvas.js v3.1.3
  48. * http://jasny.github.io/bootstrap/javascript/#offcanvas
  49. * ========================================================================
  50. * Copyright 2013-2014 Arnold Daniels
  51. *
  52. * Licensed under the Apache License, Version 2.0 (the "License")
  53. * you may not use this file except in compliance with the License.
  54. * You may obtain a copy of the License at
  55. *
  56. * http://www.apache.org/licenses/LICENSE-2.0
  57. *
  58. * Unless required by applicable law or agreed to in writing, software
  59. * distributed under the License is distributed on an "AS IS" BASIS,
  60. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  61. * See the License for the specific language governing permissions and
  62. * limitations under the License.
  63. * ======================================================================== */
  64. +function ($) { "use strict";
  65. // OFFCANVAS PUBLIC CLASS DEFINITION
  66. // =================================
  67. var OffCanvas = function (element, options) {
  68. this.$element = $(element)
  69. this.options = $.extend({}, OffCanvas.DEFAULTS, options)
  70. this.state = null
  71. this.placement = null
  72. if (this.options.recalc) {
  73. this.calcClone()
  74. $(window).on('resize', $.proxy(this.recalc, this))
  75. }
  76. if (this.options.autohide)
  77. $(document).on('click', $.proxy(this.autohide, this))
  78. if (this.options.toggle) this.toggle()
  79. if (this.options.disablescrolling) {
  80. this.options.disableScrolling = this.options.disablescrolling
  81. delete this.options.disablescrolling
  82. }
  83. }
  84. OffCanvas.DEFAULTS = {
  85. toggle: true,
  86. placement: 'auto',
  87. autohide: true,
  88. recalc: true,
  89. disableScrolling: true
  90. }
  91. OffCanvas.prototype.offset = function () {
  92. switch (this.placement) {
  93. case 'left':
  94. case 'right': return this.$element.outerWidth()
  95. case 'top':
  96. case 'bottom': return this.$element.outerHeight()
  97. }
  98. }
  99. OffCanvas.prototype.calcPlacement = function () {
  100. if (this.options.placement !== 'auto') {
  101. this.placement = this.options.placement
  102. return
  103. }
  104. if (!this.$element.hasClass('in')) {
  105. this.$element.css('visiblity', 'hidden !important').addClass('in')
  106. }
  107. var horizontal = $(window).width() / this.$element.width()
  108. var vertical = $(window).height() / this.$element.height()
  109. var element = this.$element
  110. function ab(a, b) {
  111. if (element.css(b) === 'auto') return a
  112. if (element.css(a) === 'auto') return b
  113. var size_a = parseInt(element.css(a), 10)
  114. var size_b = parseInt(element.css(b), 10)
  115. return size_a > size_b ? b : a
  116. }
  117. this.placement = horizontal >= vertical ? ab('left', 'right') : ab('top', 'bottom')
  118. if (this.$element.css('visibility') === 'hidden !important') {
  119. this.$element.removeClass('in').css('visiblity', '')
  120. }
  121. }
  122. OffCanvas.prototype.opposite = function (placement) {
  123. switch (placement) {
  124. case 'top': return 'bottom'
  125. case 'left': return 'right'
  126. case 'bottom': return 'top'
  127. case 'right': return 'left'
  128. }
  129. }
  130. OffCanvas.prototype.getCanvasElements = function() {
  131. // Return a set containing the canvas plus all fixed elements
  132. var canvas = this.options.canvas ? $(this.options.canvas) : this.$element
  133. var fixed_elements = canvas.find('*').filter(function() {
  134. return $(this).css('position') === 'fixed'
  135. }).not(this.options.exclude)
  136. return canvas.add(fixed_elements)
  137. }
  138. OffCanvas.prototype.slide = function (elements, offset, callback) {
  139. // Use jQuery animation if CSS transitions aren't supported
  140. if (!$.support.transition) {
  141. var anim = {}
  142. anim[this.placement] = "+=" + offset
  143. return elements.animate(anim, 350, callback)
  144. }
  145. var placement = this.placement
  146. var opposite = this.opposite(placement)
  147. elements.each(function() {
  148. if ($(this).css(placement) !== 'auto')
  149. $(this).css(placement, (parseInt($(this).css(placement), 10) || 0) + offset)
  150. if ($(this).css(opposite) !== 'auto')
  151. $(this).css(opposite, (parseInt($(this).css(opposite), 10) || 0) - offset)
  152. })
  153. this.$element
  154. .one($.support.transition.end, callback)
  155. .emulateTransitionEnd(350)
  156. }
  157. OffCanvas.prototype.disableScrolling = function() {
  158. var bodyWidth = $('body').width()
  159. var prop = 'padding-' + this.opposite(this.placement)
  160. if ($('body').data('offcanvas-style') === undefined) {
  161. $('body').data('offcanvas-style', $('body').attr('style') || '')
  162. }
  163. $('body').css('overflow', 'hidden')
  164. if ($('body').width() > bodyWidth) {
  165. var padding = parseInt($('body').css(prop), 10) + $('body').width() - bodyWidth
  166. setTimeout(function() {
  167. $('body').css(prop, padding)
  168. }, 1)
  169. }
  170. }
  171. OffCanvas.prototype.show = function () {
  172. if (this.state) return
  173. var startEvent = $.Event('show.bs.offcanvas')
  174. this.$element.trigger(startEvent)
  175. if (startEvent.isDefaultPrevented()) return
  176. this.state = 'slide-in'
  177. this.calcPlacement();
  178. var elements = this.getCanvasElements()
  179. var placement = this.placement
  180. var opposite = this.opposite(placement)
  181. var offset = this.offset()
  182. if (elements.index(this.$element) !== -1) {
  183. $(this.$element).data('offcanvas-style', $(this.$element).attr('style') || '')
  184. this.$element.css(placement, -1 * offset)
  185. this.$element.css(placement); // Workaround: Need to get the CSS property for it to be applied before the next line of code
  186. }
  187. elements.addClass('canvas-sliding').each(function() {
  188. if ($(this).data('offcanvas-style') === undefined) $(this).data('offcanvas-style', $(this).attr('style') || '')
  189. if ($(this).css('position') === 'static') $(this).css('position', 'relative')
  190. if (($(this).css(placement) === 'auto' || $(this).css(placement) === '0px') &&
  191. ($(this).css(opposite) === 'auto' || $(this).css(opposite) === '0px')) {
  192. $(this).css(placement, 0)
  193. }
  194. })
  195. if (this.options.disableScrolling) this.disableScrolling()
  196. var complete = function () {
  197. if (this.state != 'slide-in') return
  198. this.state = 'slid'
  199. elements.removeClass('canvas-sliding').addClass('canvas-slid')
  200. this.$element.trigger('shown.bs.offcanvas')
  201. }
  202. setTimeout($.proxy(function() {
  203. this.$element.addClass('in')
  204. this.slide(elements, offset, $.proxy(complete, this))
  205. }, this), 1)
  206. }
  207. OffCanvas.prototype.hide = function (fast) {
  208. if (this.state !== 'slid') return
  209. var startEvent = $.Event('hide.bs.offcanvas')
  210. this.$element.trigger(startEvent)
  211. if (startEvent.isDefaultPrevented()) return
  212. this.state = 'slide-out'
  213. var elements = $('.canvas-slid')
  214. var placement = this.placement
  215. var offset = -1 * this.offset()
  216. var complete = function () {
  217. if (this.state != 'slide-out') return
  218. this.state = null
  219. this.placement = null
  220. this.$element.removeClass('in')
  221. elements.removeClass('canvas-sliding')
  222. elements.add(this.$element).add('body').each(function() {
  223. $(this).attr('style', $(this).data('offcanvas-style')).removeData('offcanvas-style')
  224. })
  225. this.$element.trigger('hidden.bs.offcanvas')
  226. }
  227. elements.removeClass('canvas-slid').addClass('canvas-sliding')
  228. setTimeout($.proxy(function() {
  229. this.slide(elements, offset, $.proxy(complete, this))
  230. }, this), 1)
  231. }
  232. OffCanvas.prototype.toggle = function () {
  233. if (this.state === 'slide-in' || this.state === 'slide-out') return
  234. this[this.state === 'slid' ? 'hide' : 'show']()
  235. }
  236. OffCanvas.prototype.calcClone = function() {
  237. this.$calcClone = this.$element.clone()
  238. .html('')
  239. .addClass('offcanvas-clone').removeClass('in')
  240. .appendTo($('body'))
  241. }
  242. OffCanvas.prototype.recalc = function () {
  243. if (this.$calcClone.css('display') === 'none' || (this.state !== 'slid' && this.state !== 'slide-in')) return
  244. this.state = null
  245. this.placement = null
  246. var elements = this.getCanvasElements()
  247. this.$element.removeClass('in')
  248. elements.removeClass('canvas-slid')
  249. elements.add(this.$element).add('body').each(function() {
  250. $(this).attr('style', $(this).data('offcanvas-style')).removeData('offcanvas-style')
  251. })
  252. }
  253. OffCanvas.prototype.autohide = function (e) {
  254. if ($(e.target).closest(this.$element).length === 0) this.hide()
  255. }
  256. // OFFCANVAS PLUGIN DEFINITION
  257. // ==========================
  258. var old = $.fn.offcanvas
  259. $.fn.offcanvas = function (option) {
  260. return this.each(function () {
  261. var $this = $(this)
  262. var data = $this.data('bs.offcanvas')
  263. var options = $.extend({}, OffCanvas.DEFAULTS, $this.data(), typeof option === 'object' && option)
  264. if (!data) $this.data('bs.offcanvas', (data = new OffCanvas(this, options)))
  265. if (typeof option === 'string') data[option]()
  266. })
  267. }
  268. $.fn.offcanvas.Constructor = OffCanvas
  269. // OFFCANVAS NO CONFLICT
  270. // ====================
  271. $.fn.offcanvas.noConflict = function () {
  272. $.fn.offcanvas = old
  273. return this
  274. }
  275. // OFFCANVAS DATA-API
  276. // =================
  277. $(document).on('click.bs.offcanvas.data-api', '[data-toggle=offcanvas]', function (e) {
  278. var $this = $(this), href
  279. var target = $this.attr('data-target')
  280. || e.preventDefault()
  281. || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
  282. var $canvas = $(target)
  283. var data = $canvas.data('bs.offcanvas')
  284. var option = data ? 'toggle' : $this.data()
  285. e.stopPropagation()
  286. if (data) data.toggle()
  287. else $canvas.offcanvas(option)
  288. })
  289. }(window.jQuery);
  290. /* ============================================================
  291. * Bootstrap: rowlink.js v3.1.3
  292. * http://jasny.github.io/bootstrap/javascript/#rowlink
  293. * ============================================================
  294. * Copyright 2012-2014 Arnold Daniels
  295. *
  296. * Licensed under the Apache License, Version 2.0 (the "License");
  297. * you may not use this file except in compliance with the License.
  298. * You may obtain a copy of the License at
  299. *
  300. * http://www.apache.org/licenses/LICENSE-2.0
  301. *
  302. * Unless required by applicable law or agreed to in writing, software
  303. * distributed under the License is distributed on an "AS IS" BASIS,
  304. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  305. * See the License for the specific language governing permissions and
  306. * limitations under the License.
  307. * ============================================================ */
  308. +function ($) { "use strict";
  309. var Rowlink = function (element, options) {
  310. this.$element = $(element)
  311. this.options = $.extend({}, Rowlink.DEFAULTS, options)
  312. this.$element.on('click.bs.rowlink', 'td:not(.rowlink-skip)', $.proxy(this.click, this))
  313. }
  314. Rowlink.DEFAULTS = {
  315. target: "a"
  316. }
  317. Rowlink.prototype.click = function(e) {
  318. var target = $(e.currentTarget).closest('tr').find(this.options.target)[0]
  319. if ($(e.target)[0] === target) return
  320. e.preventDefault();
  321. if (target.click) {
  322. target.click()
  323. } else if (document.createEvent) {
  324. var evt = document.createEvent("MouseEvents");
  325. evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  326. target.dispatchEvent(evt);
  327. }
  328. }
  329. // ROWLINK PLUGIN DEFINITION
  330. // ===========================
  331. var old = $.fn.rowlink
  332. $.fn.rowlink = function (options) {
  333. return this.each(function () {
  334. var $this = $(this)
  335. var data = $this.data('bs.rowlink')
  336. if (!data) $this.data('bs.rowlink', (data = new Rowlink(this, options)))
  337. })
  338. }
  339. $.fn.rowlink.Constructor = Rowlink
  340. // ROWLINK NO CONFLICT
  341. // ====================
  342. $.fn.rowlink.noConflict = function () {
  343. $.fn.rowlink = old
  344. return this
  345. }
  346. // ROWLINK DATA-API
  347. // ==================
  348. $(document).on('click.bs.rowlink.data-api', '[data-link="row"]', function (e) {
  349. if ($(e.target).closest('.rowlink-skip').length !== 0) return
  350. var $this = $(this)
  351. if ($this.data('bs.rowlink')) return
  352. $this.rowlink($this.data())
  353. $(e.target).trigger('click.bs.rowlink')
  354. })
  355. }(window.jQuery);
  356. /* ===========================================================
  357. * Bootstrap: inputmask.js v3.1.0
  358. * http://jasny.github.io/bootstrap/javascript/#inputmask
  359. *
  360. * Based on Masked Input plugin by Josh Bush (digitalbush.com)
  361. * ===========================================================
  362. * Copyright 2012-2014 Arnold Daniels
  363. *
  364. * Licensed under the Apache License, Version 2.0 (the "License")
  365. * you may not use this file except in compliance with the License.
  366. * You may obtain a copy of the License at
  367. *
  368. * http://www.apache.org/licenses/LICENSE-2.0
  369. *
  370. * Unless required by applicable law or agreed to in writing, software
  371. * distributed under the License is distributed on an "AS IS" BASIS,
  372. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  373. * See the License for the specific language governing permissions and
  374. * limitations under the License.
  375. * ========================================================== */
  376. +function ($) { "use strict";
  377. var isIphone = (window.orientation !== undefined)
  378. var isAndroid = navigator.userAgent.toLowerCase().indexOf("android") > -1
  379. var isIE = window.navigator.appName == 'Microsoft Internet Explorer'
  380. // INPUTMASK PUBLIC CLASS DEFINITION
  381. // =================================
  382. var Inputmask = function (element, options) {
  383. if (isAndroid) return // No support because caret positioning doesn't work on Android
  384. this.$element = $(element)
  385. this.options = $.extend({}, Inputmask.DEFAULTS, options)
  386. this.mask = String(this.options.mask)
  387. this.init()
  388. this.listen()
  389. this.checkVal() //Perform initial check for existing values
  390. }
  391. Inputmask.DEFAULTS = {
  392. mask: "",
  393. placeholder: "_",
  394. definitions: {
  395. '9': "[0-9]",
  396. 'a': "[A-Za-z]",
  397. 'w': "[A-Za-z0-9]",
  398. '*': "."
  399. }
  400. }
  401. Inputmask.prototype.init = function() {
  402. var defs = this.options.definitions
  403. var len = this.mask.length
  404. this.tests = []
  405. this.partialPosition = this.mask.length
  406. this.firstNonMaskPos = null
  407. $.each(this.mask.split(""), $.proxy(function(i, c) {
  408. if (c == '?') {
  409. len--
  410. this.partialPosition = i
  411. } else if (defs[c]) {
  412. this.tests.push(new RegExp(defs[c]))
  413. if (this.firstNonMaskPos === null)
  414. this.firstNonMaskPos = this.tests.length - 1
  415. } else {
  416. this.tests.push(null)
  417. }
  418. }, this))
  419. this.buffer = $.map(this.mask.split(""), $.proxy(function(c, i) {
  420. if (c != '?') return defs[c] ? this.options.placeholder : c
  421. }, this))
  422. this.focusText = this.$element.val()
  423. this.$element.data("rawMaskFn", $.proxy(function() {
  424. return $.map(this.buffer, function(c, i) {
  425. return this.tests[i] && c != this.options.placeholder ? c : null
  426. }).join('')
  427. }, this))
  428. }
  429. Inputmask.prototype.listen = function() {
  430. if (this.$element.attr("readonly")) return
  431. var pasteEventName = (isIE ? 'paste' : 'input') + ".mask"
  432. this.$element
  433. .on("unmask.bs.inputmask", $.proxy(this.unmask, this))
  434. .on("focus.bs.inputmask", $.proxy(this.focusEvent, this))
  435. .on("blur.bs.inputmask", $.proxy(this.blurEvent, this))
  436. .on("keydown.bs.inputmask", $.proxy(this.keydownEvent, this))
  437. .on("keypress.bs.inputmask", $.proxy(this.keypressEvent, this))
  438. .on(pasteEventName, $.proxy(this.pasteEvent, this))
  439. }
  440. //Helper Function for Caret positioning
  441. Inputmask.prototype.caret = function(begin, end) {
  442. if (this.$element.length === 0) return
  443. if (typeof begin == 'number') {
  444. end = (typeof end == 'number') ? end : begin
  445. return this.$element.each(function() {
  446. if (this.setSelectionRange) {
  447. this.setSelectionRange(begin, end)
  448. } else if (this.createTextRange) {
  449. var range = this.createTextRange()
  450. range.collapse(true)
  451. range.moveEnd('character', end)
  452. range.moveStart('character', begin)
  453. range.select()
  454. }
  455. })
  456. } else {
  457. if (this.$element[0].setSelectionRange) {
  458. begin = this.$element[0].selectionStart
  459. end = this.$element[0].selectionEnd
  460. } else if (document.selection && document.selection.createRange) {
  461. var range = document.selection.createRange()
  462. begin = 0 - range.duplicate().moveStart('character', -100000)
  463. end = begin + range.text.length
  464. }
  465. return {
  466. begin: begin,
  467. end: end
  468. }
  469. }
  470. }
  471. Inputmask.prototype.seekNext = function(pos) {
  472. var len = this.mask.length
  473. while (++pos <= len && !this.tests[pos]);
  474. return pos
  475. }
  476. Inputmask.prototype.seekPrev = function(pos) {
  477. while (--pos >= 0 && !this.tests[pos]);
  478. return pos
  479. }
  480. Inputmask.prototype.shiftL = function(begin,end) {
  481. var len = this.mask.length
  482. if (begin < 0) return
  483. for (var i = begin, j = this.seekNext(end); i < len; i++) {
  484. if (this.tests[i]) {
  485. if (j < len && this.tests[i].test(this.buffer[j])) {
  486. this.buffer[i] = this.buffer[j]
  487. this.buffer[j] = this.options.placeholder
  488. } else
  489. break
  490. j = this.seekNext(j)
  491. }
  492. }
  493. this.writeBuffer()
  494. this.caret(Math.max(this.firstNonMaskPos, begin))
  495. }
  496. Inputmask.prototype.shiftR = function(pos) {
  497. var len = this.mask.length
  498. for (var i = pos, c = this.options.placeholder; i < len; i++) {
  499. if (this.tests[i]) {
  500. var j = this.seekNext(i)
  501. var t = this.buffer[i]
  502. this.buffer[i] = c
  503. if (j < len && this.tests[j].test(t))
  504. c = t
  505. else
  506. break
  507. }
  508. }
  509. },
  510. Inputmask.prototype.unmask = function() {
  511. this.$element
  512. .unbind(".mask")
  513. .removeData("inputmask")
  514. }
  515. Inputmask.prototype.focusEvent = function() {
  516. this.focusText = this.$element.val()
  517. var len = this.mask.length
  518. var pos = this.checkVal()
  519. this.writeBuffer()
  520. var that = this
  521. var moveCaret = function() {
  522. if (pos == len)
  523. that.caret(0, pos)
  524. else
  525. that.caret(pos)
  526. }
  527. moveCaret()
  528. setTimeout(moveCaret, 50)
  529. }
  530. Inputmask.prototype.blurEvent = function() {
  531. this.checkVal()
  532. if (this.$element.val() !== this.focusText)
  533. this.$element.trigger('change')
  534. }
  535. Inputmask.prototype.keydownEvent = function(e) {
  536. var k = e.which
  537. //backspace, delete, and escape get special treatment
  538. if (k == 8 || k == 46 || (isIphone && k == 127)) {
  539. var pos = this.caret(),
  540. begin = pos.begin,
  541. end = pos.end
  542. if (end - begin === 0) {
  543. begin = k != 46 ? this.seekPrev(begin) : (end = this.seekNext(begin - 1))
  544. end = k == 46 ? this.seekNext(end) : end
  545. }
  546. this.clearBuffer(begin, end)
  547. this.shiftL(begin, end - 1)
  548. return false
  549. } else if (k == 27) {//escape
  550. this.$element.val(this.focusText)
  551. this.caret(0, this.checkVal())
  552. return false
  553. }
  554. }
  555. Inputmask.prototype.keypressEvent = function(e) {
  556. var len = this.mask.length
  557. var k = e.which,
  558. pos = this.caret()
  559. if (e.ctrlKey || e.altKey || e.metaKey || k < 32) {//Ignore
  560. return true
  561. } else if (k) {
  562. if (pos.end - pos.begin !== 0) {
  563. this.clearBuffer(pos.begin, pos.end)
  564. this.shiftL(pos.begin, pos.end - 1)
  565. }
  566. var p = this.seekNext(pos.begin - 1)
  567. if (p < len) {
  568. var c = String.fromCharCode(k)
  569. if (this.tests[p].test(c)) {
  570. this.shiftR(p)
  571. this.buffer[p] = c
  572. this.writeBuffer()
  573. var next = this.seekNext(p)
  574. this.caret(next)
  575. }
  576. }
  577. return false
  578. }
  579. }
  580. Inputmask.prototype.pasteEvent = function() {
  581. var that = this
  582. setTimeout(function() {
  583. that.caret(that.checkVal(true))
  584. }, 0)
  585. }
  586. Inputmask.prototype.clearBuffer = function(start, end) {
  587. var len = this.mask.length
  588. for (var i = start; i < end && i < len; i++) {
  589. if (this.tests[i])
  590. this.buffer[i] = this.options.placeholder
  591. }
  592. }
  593. Inputmask.prototype.writeBuffer = function() {
  594. return this.$element.val(this.buffer.join('')).val()
  595. }
  596. Inputmask.prototype.checkVal = function(allow) {
  597. var len = this.mask.length
  598. //try to place characters where they belong
  599. var test = this.$element.val()
  600. var lastMatch = -1
  601. for (var i = 0, pos = 0; i < len; i++) {
  602. if (this.tests[i]) {
  603. this.buffer[i] = this.options.placeholder
  604. while (pos++ < test.length) {
  605. var c = test.charAt(pos - 1)
  606. if (this.tests[i].test(c)) {
  607. this.buffer[i] = c
  608. lastMatch = i
  609. break
  610. }
  611. }
  612. if (pos > test.length)
  613. break
  614. } else if (this.buffer[i] == test.charAt(pos) && i != this.partialPosition) {
  615. pos++
  616. lastMatch = i
  617. }
  618. }
  619. if (!allow && lastMatch + 1 < this.partialPosition) {
  620. this.$element.val("")
  621. this.clearBuffer(0, len)
  622. } else if (allow || lastMatch + 1 >= this.partialPosition) {
  623. this.writeBuffer()
  624. if (!allow) this.$element.val(this.$element.val().substring(0, lastMatch + 1))
  625. }
  626. return (this.partialPosition ? i : this.firstNonMaskPos)
  627. }
  628. // INPUTMASK PLUGIN DEFINITION
  629. // ===========================
  630. var old = $.fn.inputmask
  631. $.fn.inputmask = function (options) {
  632. return this.each(function () {
  633. var $this = $(this)
  634. var data = $this.data('bs.inputmask')
  635. if (!data) $this.data('bs.inputmask', (data = new Inputmask(this, options)))
  636. })
  637. }
  638. $.fn.inputmask.Constructor = Inputmask
  639. // INPUTMASK NO CONFLICT
  640. // ====================
  641. $.fn.inputmask.noConflict = function () {
  642. $.fn.inputmask = old
  643. return this
  644. }
  645. // INPUTMASK DATA-API
  646. // ==================
  647. $(document).on('focus.bs.inputmask.data-api', '[data-mask]', function (e) {
  648. var $this = $(this)
  649. if ($this.data('bs.inputmask')) return
  650. $this.inputmask($this.data())
  651. })
  652. }(window.jQuery);
  653. /* ===========================================================
  654. * Bootstrap: fileinput.js v3.1.3
  655. * http://jasny.github.com/bootstrap/javascript/#fileinput
  656. * ===========================================================
  657. * Copyright 2012-2014 Arnold Daniels
  658. *
  659. * Licensed under the Apache License, Version 2.0 (the "License")
  660. * you may not use this file except in compliance with the License.
  661. * You may obtain a copy of the License at
  662. *
  663. * http://www.apache.org/licenses/LICENSE-2.0
  664. *
  665. * Unless required by applicable law or agreed to in writing, software
  666. * distributed under the License is distributed on an "AS IS" BASIS,
  667. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  668. * See the License for the specific language governing permissions and
  669. * limitations under the License.
  670. * ========================================================== */
  671. +function ($) { "use strict";
  672. var isIE = window.navigator.appName == 'Microsoft Internet Explorer'
  673. // FILEUPLOAD PUBLIC CLASS DEFINITION
  674. // =================================
  675. var Fileinput = function (element, options) {
  676. this.$element = $(element)
  677. this.$input = this.$element.find(':file')
  678. if (this.$input.length === 0) return
  679. this.name = this.$input.attr('name') || options.name
  680. this.$hidden = this.$element.find('input[type=hidden][name="' + this.name + '"]')
  681. if (this.$hidden.length === 0) {
  682. this.$hidden = $('<input type="hidden">').insertBefore(this.$input)
  683. }
  684. this.$preview = this.$element.find('.fileinput-preview')
  685. var height = this.$preview.css('height')
  686. if (this.$preview.css('display') !== 'inline' && height !== '0px' && height !== 'none') {
  687. this.$preview.css('line-height', height)
  688. }
  689. this.original = {
  690. exists: this.$element.hasClass('fileinput-exists'),
  691. preview: this.$preview.html(),
  692. hiddenVal: this.$hidden.val()
  693. }
  694. this.listen()
  695. }
  696. Fileinput.prototype.listen = function() {
  697. this.$input.on('change.bs.fileinput', $.proxy(this.change, this))
  698. $(this.$input[0].form).on('reset.bs.fileinput', $.proxy(this.reset, this))
  699. this.$element.find('[data-trigger="fileinput"]').on('click.bs.fileinput', $.proxy(this.trigger, this))
  700. this.$element.find('[data-dismiss="fileinput"]').on('click.bs.fileinput', $.proxy(this.clear, this))
  701. },
  702. Fileinput.prototype.change = function(e) {
  703. var files = e.target.files === undefined ? (e.target && e.target.value ? [{ name: e.target.value.replace(/^.+\\/, '')}] : []) : e.target.files
  704. e.stopPropagation()
  705. if (files.length === 0) {
  706. this.clear()
  707. return
  708. }
  709. this.$hidden.val('')
  710. this.$hidden.attr('name', '')
  711. this.$input.attr('name', this.name)
  712. var file = files[0]
  713. if (this.$preview.length > 0 && (typeof file.type !== "undefined" ? file.type.match(/^image\/(gif|png|jpeg)$/) : file.name.match(/\.(gif|png|jpe?g)$/i)) && typeof FileReader !== "undefined") {
  714. var reader = new FileReader()
  715. var preview = this.$preview
  716. var element = this.$element
  717. reader.onload = function(re) {
  718. var $img = $('<img>')
  719. $img[0].src = re.target.result
  720. files[0].result = re.target.result
  721. element.find('.fileinput-filename').text(file.name)
  722. // if parent has max-height, using `(max-)height: 100%` on child doesn't take padding and border into account
  723. if (preview.css('max-height') != 'none') $img.css('max-height', parseInt(preview.css('max-height'), 10) - parseInt(preview.css('padding-top'), 10) - parseInt(preview.css('padding-bottom'), 10) - parseInt(preview.css('border-top'), 10) - parseInt(preview.css('border-bottom'), 10))
  724. preview.html($img)
  725. element.addClass('fileinput-exists').removeClass('fileinput-new')
  726. element.trigger('change.bs.fileinput', files)
  727. }
  728. reader.readAsDataURL(file)
  729. } else {
  730. this.$element.find('.fileinput-filename').text(file.name)
  731. this.$preview.text(file.name)
  732. this.$element.addClass('fileinput-exists').removeClass('fileinput-new')
  733. this.$element.trigger('change.bs.fileinput')
  734. }
  735. },
  736. Fileinput.prototype.clear = function(e) {
  737. if (e) e.preventDefault()
  738. this.$hidden.val('')
  739. this.$hidden.attr('name', this.name)
  740. this.$input.attr('name', '')
  741. //ie8+ doesn't support changing the value of input with type=file so clone instead
  742. if (isIE) {
  743. var inputClone = this.$input.clone(true);
  744. this.$input.after(inputClone);
  745. this.$input.remove();
  746. this.$input = inputClone;
  747. } else {
  748. this.$input.val('')
  749. }
  750. this.$preview.html('')
  751. this.$element.find('.fileinput-filename').text('')
  752. this.$element.addClass('fileinput-new').removeClass('fileinput-exists')
  753. if (e !== undefined) {
  754. this.$input.trigger('change')
  755. this.$element.trigger('clear.bs.fileinput')
  756. }
  757. },
  758. Fileinput.prototype.reset = function() {
  759. this.clear()
  760. this.$hidden.val(this.original.hiddenVal)
  761. this.$preview.html(this.original.preview)
  762. this.$element.find('.fileinput-filename').text('')
  763. if (this.original.exists) this.$element.addClass('fileinput-exists').removeClass('fileinput-new')
  764. else this.$element.addClass('fileinput-new').removeClass('fileinput-exists')
  765. this.$element.trigger('reset.bs.fileinput')
  766. },
  767. Fileinput.prototype.trigger = function(e) {
  768. this.$input.trigger('click')
  769. e.preventDefault()
  770. }
  771. // FILEUPLOAD PLUGIN DEFINITION
  772. // ===========================
  773. var old = $.fn.fileinput
  774. $.fn.fileinput = function (options) {
  775. return this.each(function () {
  776. var $this = $(this),
  777. data = $this.data('bs.fileinput')
  778. if (!data) $this.data('bs.fileinput', (data = new Fileinput(this, options)))
  779. if (typeof options == 'string') data[options]()
  780. })
  781. }
  782. $.fn.fileinput.Constructor = Fileinput
  783. // FILEINPUT NO CONFLICT
  784. // ====================
  785. $.fn.fileinput.noConflict = function () {
  786. $.fn.fileinput = old
  787. return this
  788. }
  789. // FILEUPLOAD DATA-API
  790. // ==================
  791. $(document).on('click.fileinput.data-api', '[data-provides="fileinput"]', function (e) {
  792. var $this = $(this)
  793. if ($this.data('bs.fileinput')) return
  794. $this.fileinput($this.data())
  795. var $target = $(e.target).closest('[data-dismiss="fileinput"],[data-trigger="fileinput"]');
  796. if ($target.length > 0) {
  797. e.preventDefault()
  798. $target.trigger('click.bs.fileinput')
  799. }
  800. })
  801. }(window.jQuery);