PageSourceSearch

https://materials-lab.io/static/assets/js/plugins/jasny-bootstrap.min.js

js materials-lab.io collected 2026-10-04 13:26:43 UTC 10,521 bytes, 337 lines download raw bytes

vendor: 10,521 bytes, lines 1-337
1/* ===========================================================
2 * Bootstrap: fileinput.js v4.0.0
3 * http://jasny.github.com/bootstrap/javascript/#fileinput
4 * ===========================================================
5 * Copyright 2012-2014 Arnold Daniels
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License")
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================================================== */
19
20+function ($) { "use strict";
21
22  var isIE = window.navigator.appName == 'Microsoft Internet Explorer'
23
24  // FILEUPLOAD PUBLIC CLASS DEFINITION
25  // =================================
26
27  var Fileinput = function (element, options) {
28    this.$element = $(element)
29
30    this.options = $.extend({}, Fileinput.DEFAULTS, options)
31    this.$input = this.$element.find(':file')
32    if (this.$input.length === 0) return
33
34    this.name = this.$input.attr('name') || options.name
35
36    this.$hidden = this.$element.find('input[type=hidden][name="' + this.name + '"]')
37    if (this.$hidden.length === 0) {
38      this.$hidden = $('<input type="hidden">').insertBefore(this.$input)
39    }
40
41    this.$preview = this.$element.find('.fileinput-preview')
42    var height = this.$preview.css('height')
43    if (this.$preview.css('display') !== 'inline' && height !== '0px' && height !== 'none') {
44      this.$preview.css('line-height', height)
45    }
46
47    this.original = {
48      exists: this.$element.hasClass('fileinput-exists'),
49      preview: this.$preview.html(),
50      hiddenVal: this.$hidden.val()
51    }
52
53    this.listen()
54    this.reset()
55  }
56
57  Fileinput.DEFAULTS = {
58    clearName: true
59  }
60
61  Fileinput.prototype.listen = function() {
62    this.$input.on('change.bs.fileinput', $.proxy(this.change, this))
63    $(this.$input[0].form).on('reset.bs.fileinput', $.proxy(this.reset, this))
64
65    this.$element.find('[data-trigger="fileinput"]').on('click.bs.fileinput', $.proxy(this.trigger, this))
66    this.$element.find('[data-dismiss="fileinput"]').on('click.bs.fileinput', $.proxy(this.clear, this))
67  },
68
69  Fileinput.prototype.verifySizes = function(files) {
70    if (typeof this.options.maxSize === 'undefined') return true
71
72    var max = parseFloat(this.options.maxSize)
73    if (max !== this.options.maxSize) return true
74
75    for (var i = 0; i < files.length; i++) {
76      var size = typeof files[i].size !== 'undefined' ? files[i].size : null
77      if (size === null) continue
78
79      size = size / 1000 / 1000 /* convert from bytes to MB */
80      if (size > max) return false
81    }
82
83    return true
84  }
85
86  Fileinput.prototype.change = function(e) {
87    var files = e.target.files === undefined ? (e.target && e.target.value ? [{ name: e.target.value.replace(/^.+\\/, '')}] : []) : e.target.files
88
89    e.stopPropagation()
90
91    if (files.length === 0) {
92      this.clear()
93      this.$element.trigger('clear.bs.fileinput')
94      return
95    }
96
97    if (!this.verifySizes(files)) {
98      this.$element.trigger('max_size.bs.fileinput')
99
100      this.clear()
101      this.$element.trigger('clear.bs.fileinput')
102      return
103    }
104
105    this.$hidden.val('')
106    this.$hidden.attr('name', '')
107    this.$input.attr('name', this.name)
108
109    var file = files[0]
110
111    if (this.$preview.length > 0 && (typeof file.type !== "undefined" ? file.type.match(/^image\/(gif|png|jpeg|svg\+xml)$/) : file.name.match(/\.(gif|png|jpe?g|svg)$/i)) && typeof FileReader !== "undefined") {
112      var Fileinput = this
113      var reader = new FileReader()
114      var preview = this.$preview
115      var element = this.$element
116
117      reader.onload = function(re) {
118        var $img = $('<img>')
119        $img[0].src = re.target.result
120        files[0].result = re.target.result
121
122        element.find('.fileinput-filename').text(file.name)
123
124        // if parent has max-height, using `(max-)height: 100%` on child doesn't take padding and border into account
125        if (preview.css('max-height') != 'none') {
126          var mh = parseInt(preview.css('max-height'), 10) || 0
127          var pt = parseInt(preview.css('padding-top'), 10) || 0
128          var pb = parseInt(preview.css('padding-bottom'), 10) || 0
129          var bt = parseInt(preview.css('border-top'), 10) || 0
130          var bb = parseInt(preview.css('border-bottom'), 10) || 0
131
132          $img.css('max-height', mh - pt - pb - bt - bb)
133        }
134
135        preview.html($img)
136        if (Fileinput.options.exif) {
137          //Fix image tranformation if this is possible
138          Fileinput.setImageTransform($img, file);
139        }
140        element.addClass('fileinput-exists').removeClass('fileinput-new')
141
142        element.trigger('change.bs.fileinput', files)
143      }
144
145      reader.readAsDataURL(file)
146    } else {
147      var text = file.name
148      var $nameView = this.$element.find('.fileinput-filename')
149
150      if (files.length > 1) {
151        text = $.map(files, function(file) {
152          return file.name;
153        }).join(', ')
154      }
155
156      $nameView.text(text)
157      this.$preview.text(file.name)
158      this.$element.addClass('fileinput-exists').removeClass('fileinput-new')
159      this.$element.trigger('change.bs.fileinput')
160    }
161  },
162
163  Fileinput.prototype.setImageTransform = function($img, file) {
164      var Fileinput = this;
165      var reader = new FileReader();
166      reader.onload = function(me) {
167        var transform = false;
168        var view = new DataView(reader.result);
169        var exif = Fileinput.getImageExif(view);
170        if (exif) {
171            Fileinput.resetOrientation($img, exif);
172        }
173      }
174
175      reader.readAsArrayBuffer(file);
176  }
177
178  Fileinput.prototype.getImageExif = function(view) {
179    if (view.getUint16(0, false) != 0xFFD8) {
180      return -2;
181    }
182    var length = view.byteLength, offset = 2;
183    while (offset < length) {
184      var marker = view.getUint16(offset, false);
185          offset += 2;
186      if (marker == 0xFFE1) {
187        if (view.getUint32(offset += 2, false) != 0x45786966) {
188          return -1;
189        }
190        var little = view.getUint16(offset += 6, false) == 0x4949;
191            offset += view.getUint32(offset + 4, little);
192        var tags = view.getUint16(offset, little);
193            offset += 2;
194        for (var i = 0; i < tags; i++)   {
195          if (view.getUint16(offset + (i * 12), little) == 0x0112) {
196            return view.getUint16(offset + (i * 12) + 8, little);
197          }
198        }
199      }
200      else if ((marker & 0xFF00) != 0xFF00){
201         break;
202      } else {
203        offset += view.getUint16(offset, false);
204      }
205    }
206
207    return -1;
208  }
209
210  Fileinput.prototype.resetOrientation = function($img, transform) {
211  var img = new Image();
212
213  img.onload = function() {
214    var width = img.width,
215        height = img.height,
216        canvas = document.createElement('canvas'),
217        ctx = canvas.getContext("2d");
218
219    // set proper canvas dimensions before transform & export
220    if ([5,6,7,8].indexOf(transform) > -1) {
221      canvas.width = height;
222      canvas.height = width;
223    } else {
224      canvas.width = width;
225      canvas.height = height;
226    }
227
228    // transform context before drawing image
229    switch (transform) {
230      case 2: ctx.transform(-1, 0, 0, 1, width, 0); break;
231      case 3: ctx.transform(-1, 0, 0, -1, width, height ); break;
232      case 4: ctx.transform(1, 0, 0, -1, 0, height ); break;
233      case 5: ctx.transform(0, 1, 1, 0, 0, 0); break;
234      case 6: ctx.transform(0, 1, -1, 0, height , 0); break;
235      case 7: ctx.transform(0, -1, -1, 0, height , width); break;
236      case 8: ctx.transform(0, -1, 1, 0, 0, width); break;
237      default: ctx.transform(1, 0, 0, 1, 0, 0);
238    }
239
240    // draw image
241    ctx.drawImage(img, 0, 0);
242
243    // export base64
244    $img.attr('src', canvas.toDataURL());
245  };
246
247  img.src = $img.attr('src');
248};
249
250  Fileinput.prototype.clear = function(e) {
251    if (e) e.preventDefault()
252
253    this.$hidden.val('')
254    this.$hidden.attr('name', this.name)
255    if (this.options.clearName) this.$input.attr('name', '')
256
257    //ie8+ doesn't support changing the value of input with type=file so clone instead
258    if (isIE) {
259      var inputClone = this.$input.clone(true);
260      this.$input.after(inputClone);
261      this.$input.remove();
262      this.$input = inputClone;
263    } else {
264      this.$input.val('')
265    }
266
267    this.$preview.html('')
268    this.$element.find('.fileinput-filename').text('')
269    this.$element.addClass('fileinput-new').removeClass('fileinput-exists')
270
271    if (e !== undefined) {
272      this.$input.trigger('change')
273      this.$element.trigger('clear.bs.fileinput')
274    }
275  },
276
277  Fileinput.prototype.reset = function() {
278    this.clear()
279
280    this.$hidden.val(this.original.hiddenVal)
281    this.$preview.html(this.original.preview)
282    this.$element.find('.fileinput-filename').text('')
283
284    if (this.original.exists) this.$element.addClass('fileinput-exists').removeClass('fileinput-new')
285     else this.$element.addClass('fileinput-new').removeClass('fileinput-exists')
286
287    this.$element.trigger('reseted.bs.fileinput')
288  },
289
290  Fileinput.prototype.trigger = function(e) {
291    this.$input.trigger('click')
292    e.preventDefault()
293  }
294
295
296  // FILEUPLOAD PLUGIN DEFINITION
297  // ===========================
298
299  var old = $.fn.fileinput
300
301  $.fn.fileinput = function (options) {
302    return this.each(function () {
303      var $this = $(this),
304          data = $this.data('bs.fileinput')
305      if (!data) $this.data('bs.fileinput', (data = new Fileinput(this, options)))
306      if (typeof options == 'string') data[options]()
307    })
308  }
309
310  $.fn.fileinput.Constructor = Fileinput
311
312
313  // FILEINPUT NO CONFLICT
314  // ====================
315
316  $.fn.fileinput.noConflict = function () {
317    $.fn.fileinput = old
318    return this
319  }
320
321
322  // FILEUPLOAD DATA-API
323  // ==================
324
325  $(document).on('click.fileinput.data-api', '[data-provides="fileinput"]', function (e) {
326    var $this = $(this)
327    if ($this.data('bs.fileinput')) return
328    $this.fileinput($this.data())
329
330    var $target = $(e.target).closest('[data-dismiss="fileinput"],[data-trigger="fileinput"]');
331    if ($target.length > 0) {
332      e.preventDefault()
333      $target.trigger('click.bs.fileinput')
334    }
335  })
336
337}(window.jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.