|
1 | 1 | (function( $ ){
|
2 |
| - |
| 2 | + |
3 | 3 | "use strict";
|
4 |
| - |
| 4 | + |
5 | 5 | var Uploader = function(el, options) {
|
6 | 6 | this.$el = $(el);
|
7 | 7 | this.options = $.extend({}, $.fn.uploader.defaults, options);
|
8 | 8 | };
|
9 |
| - |
| 9 | + |
10 | 10 | Uploader.prototype = {
|
11 |
| - |
| 11 | + |
12 | 12 | constructor: Uploader,
|
13 |
| - |
| 13 | + |
14 | 14 | applyTheme: function() {
|
15 | 15 | if (!this.$overlay) {
|
16 | 16 | this.$el.width(0).height(0).css({
|
|
19 | 19 | 'margin': 0,
|
20 | 20 | 'padding': 0
|
21 | 21 | });
|
22 |
| - |
| 22 | + |
23 | 23 | this.$overlay = $('<div class="input-prepend"/>').insertAfter(this.$el);
|
24 | 24 |
|
25 | 25 | this.$button = $('<button class="btn"></button>').appendTo(this.$overlay);
|
|
30 | 30 | //this.$overlay.append('<button class="btn"><i class="icon-upload"></i></button>');
|
31 | 31 | this.$input = $('<input type="text"/>').appendTo(this.$overlay);
|
32 | 32 | this.$input.val(this.options.inputText);
|
33 |
| - |
| 33 | + |
34 | 34 | this.$overlay.on('click', $.proxy(this._on_click, this));
|
35 | 35 | this.$el.on('change', $.proxy(this._on_change, this));
|
36 |
| - |
| 36 | + |
37 | 37 | this.$el.trigger('themed');
|
38 | 38 | }
|
39 | 39 | this.$overlay.offset(this.$el.offset());
|
40 | 40 | },
|
41 |
| - |
| 41 | + |
42 | 42 | _on_click: function(e) {
|
| 43 | + e.preventDefault(); |
43 | 44 | this.$el.click();
|
44 | 45 | },
|
45 |
| - |
| 46 | + |
46 | 47 | _on_change: function(e) {
|
47 | 48 | var filename = this.$el.val().replace(/^(.*)(\\|\/)/g, '');
|
48 | 49 | this.$overlay.find('input').val(filename);
|
49 | 50 | }
|
50 |
| - |
| 51 | + |
51 | 52 | };
|
52 |
| - |
| 53 | + |
53 | 54 | $.fn.uploader = function(option) {
|
54 | 55 | return this.each(function(){
|
55 | 56 | var $this = $(this)
|
|
59 | 60 | data.applyTheme();
|
60 | 61 | });
|
61 | 62 | };
|
62 |
| - |
| 63 | + |
63 | 64 | $.fn.uploader.defaults = {
|
64 | 65 | inputText: 'Choose a file...',
|
65 | 66 | buttonText: '',
|
66 | 67 | icon: 'file'
|
67 | 68 | };
|
68 |
| - |
| 69 | + |
69 | 70 | $.fn.uploader.Constructor = Uploader;
|
70 |
| - |
| 71 | + |
71 | 72 | $(function() {
|
72 | 73 | $(':file').each(function(i, el) {
|
73 | 74 | var $this = $(this), options = {};
|
|
0 commit comments