jasny-bootstrap.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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. alert(this.$input.attr('name'));
  680. this.name = this.$input.attr('name') || options.name
  681. this.$hidden = this.$element.find('input[type=hidden][name="' + this.name + '"]')
  682. if (this.$hidden.length === 0) {
  683. this.$hidden = $('<input type="hidden">').insertBefore(this.$input)
  684. }
  685. this.$preview = this.$element.find('.fileinput-preview')
  686. var height = this.$preview.css('height')
  687. if (this.$preview.css('display') !== 'inline' && height !== '0px' && height !== 'none') {
  688. this.$preview.css('line-height', height)
  689. }
  690. this.original = {
  691. exists: this.$element.hasClass('fileinput-exists'),
  692. preview: this.$preview.html(),
  693. hiddenVal: this.$hidden.val()
  694. }
  695. this.listen()
  696. }
  697. Fileinput.prototype.listen = function() {
  698. this.$input.on('change.bs.fileinput', $.proxy(this.change, this))
  699. $(this.$input[0].form).on('reset.bs.fileinput', $.proxy(this.reset, this))
  700. this.$element.find('[data-trigger="fileinput"]').on('click.bs.fileinput', $.proxy(this.trigger, this))
  701. this.$element.find('[data-dismiss="fileinput"]').on('click.bs.fileinput', $.proxy(this.clear, this))
  702. },
  703. Fileinput.prototype.change = function(e) {
  704. var files = e.target.files === undefined ? (e.target && e.target.value ? [{ name: e.target.value.replace(/^.+\\/, '')}] : []) : e.target.files
  705. e.stopPropagation()
  706. if (files.length === 0) {
  707. this.clear()
  708. return
  709. }
  710. this.$hidden.val('')
  711. this.$hidden.attr('name', '')
  712. this.$input.attr('name', this.name)
  713. var file = files[0]
  714. 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") {
  715. var reader = new FileReader()
  716. var preview = this.$preview
  717. var element = this.$element
  718. reader.onload = function(re) {
  719. var $img = $('<img>')
  720. $img[0].src = re.target.result
  721. files[0].result = re.target.result
  722. element.find('.fileinput-filename').text(file.name)
  723. // if parent has max-height, using `(max-)height: 100%` on child doesn't take padding and border into account
  724. 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))
  725. preview.html($img)
  726. element.addClass('fileinput-exists').removeClass('fileinput-new')
  727. element.trigger('change.bs.fileinput', files)
  728. }
  729. reader.readAsDataURL(file)
  730. } else {
  731. this.$element.find('.fileinput-filename').text(file.name)
  732. this.$preview.text(file.name)
  733. this.$element.addClass('fileinput-exists').removeClass('fileinput-new')
  734. this.$element.trigger('change.bs.fileinput')
  735. }
  736. },
  737. Fileinput.prototype.clear = function(e) {
  738. if (e) e.preventDefault()
  739. this.$hidden.val('')
  740. this.$hidden.attr('name', this.name)
  741. this.$input.attr('name', '')
  742. //ie8+ doesn't support changing the value of input with type=file so clone instead
  743. if (isIE) {
  744. var inputClone = this.$input.clone(true);
  745. this.$input.after(inputClone);
  746. this.$input.remove();
  747. this.$input = inputClone;
  748. } else {
  749. this.$input.val('')
  750. }
  751. this.$preview.html('')
  752. this.$element.find('.fileinput-filename').text('')
  753. this.$element.addClass('fileinput-new').removeClass('fileinput-exists')
  754. if (e !== undefined) {
  755. this.$input.trigger('change')
  756. this.$element.trigger('clear.bs.fileinput')
  757. }
  758. },
  759. Fileinput.prototype.reset = function() {
  760. this.clear()
  761. this.$hidden.val(this.original.hiddenVal)
  762. this.$preview.html(this.original.preview)
  763. this.$element.find('.fileinput-filename').text('')
  764. if (this.original.exists) this.$element.addClass('fileinput-exists').removeClass('fileinput-new')
  765. else this.$element.addClass('fileinput-new').removeClass('fileinput-exists')
  766. this.$element.trigger('reset.bs.fileinput')
  767. },
  768. Fileinput.prototype.trigger = function(e) {
  769. this.$input.trigger('click')
  770. e.preventDefault()
  771. }
  772. // FILEUPLOAD PLUGIN DEFINITION
  773. // ===========================
  774. var old = $.fn.fileinput
  775. $.fn.fileinput = function (options) {
  776. return this.each(function () {
  777. var $this = $(this),
  778. data = $this.data('bs.fileinput')
  779. if (!data) $this.data('bs.fileinput', (data = new Fileinput(this, options)))
  780. if (typeof options == 'string') data[options]()
  781. })
  782. }
  783. $.fn.fileinput.Constructor = Fileinput
  784. // FILEINPUT NO CONFLICT
  785. // ====================
  786. $.fn.fileinput.noConflict = function () {
  787. $.fn.fileinput = old
  788. return this
  789. }
  790. // FILEUPLOAD DATA-API
  791. // ==================
  792. $(document).on('click.fileinput.data-api', '[data-provides="fileinput"]', function (e) {
  793. var $this = $(this)
  794. if ($this.data('bs.fileinput')) return
  795. $this.fileinput($this.data())
  796. var $target = $(e.target).closest('[data-dismiss="fileinput"],[data-trigger="fileinput"]');
  797. if ($target.length > 0) {
  798. e.preventDefault()
  799. $target.trigger('click.bs.fileinput')
  800. }
  801. })
  802. }(window.jQuery);