rails-uploader 0.2.8 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +162 -86
  4. data/app/assets/javascripts/uploader/application.js +6 -4
  5. data/app/assets/javascripts/uploader/jquery.uploader.js.coffee +58 -0
  6. data/app/controllers/uploader/attachments_controller.rb +63 -39
  7. data/app/views/uploader/default/_container.html.erb +19 -45
  8. data/app/views/uploader/default/_download.html.erb +4 -5
  9. data/app/views/uploader/default/_upload.html.erb +0 -1
  10. data/config/locales/en.yml +2 -0
  11. data/config/locales/ru.yml +3 -0
  12. data/config/locales/uk.yml +3 -0
  13. data/config/routes.rb +1 -1
  14. data/lib/uploader/asset.rb +63 -84
  15. data/lib/uploader/authorization.rb +52 -0
  16. data/lib/uploader/authorization_adapter.rb +24 -0
  17. data/lib/uploader/chunked_uploads.rb +15 -0
  18. data/lib/uploader/engine.rb +6 -0
  19. data/lib/uploader/file_part.rb +18 -0
  20. data/lib/uploader/fileuploads.rb +42 -65
  21. data/lib/uploader/helpers/field_tag.rb +10 -5
  22. data/lib/uploader/hooks/formtastic.rb +0 -13
  23. data/lib/uploader/upload_request.rb +72 -0
  24. data/lib/uploader/version.rb +1 -1
  25. data/lib/uploader.rb +41 -8
  26. data/spec/dummy/app/models/asset.rb +12 -0
  27. data/spec/dummy/app/models/picture.rb +6 -0
  28. data/spec/dummy/db/test.sqlite3 +0 -0
  29. data/spec/dummy/log/test.log +325 -0
  30. data/spec/dummy/public/uploads/picture/data/1/thumb_rails.png +0 -0
  31. data/spec/dummy/public/uploads/picture/data/3/thumb_rails.png +0 -0
  32. data/spec/fileuploads_spec.rb +4 -4
  33. data/spec/requests/attachments_controller_spec.rb +11 -12
  34. data/vendor/assets/javascripts/uploader/jquery.fileupload-process.js +175 -0
  35. data/vendor/assets/javascripts/uploader/jquery.fileupload-ui.js +164 -261
  36. data/vendor/assets/javascripts/uploader/jquery.fileupload-validate.js +122 -0
  37. data/vendor/assets/javascripts/uploader/jquery.fileupload.js +335 -101
  38. data/vendor/assets/javascripts/uploader/jquery.iframe-transport.js +47 -15
  39. data/vendor/assets/javascripts/uploader/vendor/jquery.ui.widget.js +572 -0
  40. data/vendor/assets/javascripts/uploader/vendor/tmpl.min.js +1 -0
  41. data/vendor/assets/stylesheets/uploader/default.css +26 -19
  42. metadata +12 -9
  43. data/vendor/assets/javascripts/uploader/jquery.fileupload-fp.js +0 -227
  44. data/vendor/assets/javascripts/uploader/jquery.ui.widget.js +0 -530
  45. data/vendor/assets/javascripts/uploader/load-image.min.js +0 -1
  46. data/vendor/assets/javascripts/uploader/locales/en.js +0 -27
  47. data/vendor/assets/javascripts/uploader/locales/ru.js +0 -27
  48. data/vendor/assets/javascripts/uploader/locales/uk.js +0 -27
  49. data/vendor/assets/javascripts/uploader/tmpl.min.js +0 -1
@@ -0,0 +1 @@
1
+ !function(e){"use strict";var n=function(e,t){var r=/[^\w\-\.:]/.test(e)?new Function(n.arg+",tmpl","var _e=tmpl.encode"+n.helper+",_s='"+e.replace(n.regexp,n.func)+"';return _s;"):n.cache[e]=n.cache[e]||n(n.load(e));return t?r(t,n):function(e){return r(e,n)}};n.cache={},n.load=function(e){return document.getElementById(e).innerHTML},n.regexp=/([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g,n.func=function(e,n,t,r,c,u){return n?{"\n":"\\n","\r":"\\r"," ":"\\t"," ":" "}[n]||"\\"+n:t?"="===t?"'+_e("+r+")+'":"'+("+r+"==null?'':"+r+")+'":c?"';":u?"_s+='":void 0},n.encReg=/[<>&"'\x00]/g,n.encMap={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#39;"},n.encode=function(e){return(null==e?"":""+e).replace(n.encReg,function(e){return n.encMap[e]||""})},n.arg="o",n.helper=",print=function(s,e){_s+=e?(s==null?'':s):_e(s);},include=function(s,d){_s+=tmpl(s,d);}","function"==typeof define&&define.amd?define(function(){return n}):"object"==typeof module&&module.exports?module.exports=n:e.tmpl=n}(this);
@@ -1,4 +1,4 @@
1
- .uploader-dnd-area {
1
+ .uploader-dnd-area {
2
2
  border: 1px dashed #ccc;
3
3
  padding: 15px 0px 15px 20px;
4
4
  color: #b1b1b1;
@@ -13,7 +13,7 @@
13
13
  .uploader-dnd-hints {
14
14
  text-align: center;
15
15
  padding: 30px 0;
16
- overflow: hidden;
16
+ overflow: hidden;
17
17
  clear: both;
18
18
  }
19
19
  .uploader-dnd-hints .uploader-button {
@@ -37,11 +37,11 @@
37
37
  .uploader-button {
38
38
  display: inline-block;
39
39
  background: #972da0;
40
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#982da1', endColorstr='#892891');
41
- background: -webkit-linear-gradient(left top, left bottom, #982da1, #892891);
42
- background: -moz-linear-gradient(top, #982da1, #892891);
43
- background: -o-linear-gradient(top, #982da1, #892891);
44
- background: -ms-linear-gradient(top, #982da1, #892891);
40
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#982da1', endColorstr='#892891');
41
+ background: -webkit-linear-gradient(left top, left bottom, #982da1, #892891);
42
+ background: -moz-linear-gradient(top, #982da1, #892891);
43
+ background: -o-linear-gradient(top, #982da1, #892891);
44
+ background: -ms-linear-gradient(top, #982da1, #892891);
45
45
  border: solid 1px #5f1c65;
46
46
  border-radius: 2px;
47
47
  -moz-border-radius: 2px;
@@ -57,22 +57,22 @@
57
57
  }
58
58
  .uploader-button:hover {
59
59
  background: #972da0;
60
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#90179a', endColorstr='#7d2485');
61
- background: -webkit-linear-gradient(left top, left bottom, #90179a, #7d2485);
62
- background: -moz-linear-gradient(top, #90179a, #7d2485);
63
- background: -o-linear-gradient(top, #90179a, #7d2485);
64
- background: -ms-linear-gradient(top, #90179a, #7d2485);
60
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#90179a', endColorstr='#7d2485');
61
+ background: -webkit-linear-gradient(left top, left bottom, #90179a, #7d2485);
62
+ background: -moz-linear-gradient(top, #90179a, #7d2485);
63
+ background: -o-linear-gradient(top, #90179a, #7d2485);
64
+ background: -ms-linear-gradient(top, #90179a, #7d2485);
65
65
  -moz-box-shadow: 0 1px 3px #aaa;
66
66
  -webkit-box-shadow: 0 1px 3px #aaa;
67
67
  box-shadow: 0 1px 3px #aaa;
68
68
  }
69
69
  .uploader-button:active {
70
70
  background: #8e1898;
71
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8e1898', endColorstr='#7f2387');
72
- background: -webkit-linear-gradient(left top, left bottom, #8e1898, #7f2387);
73
- background: -moz-linear-gradient(top, #8e1898, #7f2387);
74
- background: -o-linear-gradient(top, #8e1898, #7f2387);
75
- background: -ms-linear-gradient(top, #8e1898, #7f2387);
71
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8e1898', endColorstr='#7f2387');
72
+ background: -webkit-linear-gradient(left top, left bottom, #8e1898, #7f2387);
73
+ background: -moz-linear-gradient(top, #8e1898, #7f2387);
74
+ background: -o-linear-gradient(top, #8e1898, #7f2387);
75
+ background: -ms-linear-gradient(top, #8e1898, #7f2387);
76
76
  -moz-box-shadow: inset 0 0 4px #5f1c65;
77
77
  -webkit-box-shadow: inset 0 0 4px #5f1c65;
78
78
  box-shadow: inset 0 0 4px #5f1c65;
@@ -144,7 +144,7 @@ input[disabled].uploader-button.gray {
144
144
  -webkit-box-shadow: 0 0 5px #d2d2d2;
145
145
  box-shadow: 0 0 5px #d2d2d2;
146
146
  border: solid 1px #cf63d8;
147
- }
147
+ }
148
148
 
149
149
  .uploader-dnd-area .attach_item a.del_btn {
150
150
  width: 19px;
@@ -174,7 +174,7 @@ input[disabled].uploader-button.gray {
174
174
  float: right;
175
175
  width: 180px;
176
176
  overflow: hidden;
177
- }
177
+ }
178
178
  .uploader-dnd-area .attach_item .fileName {
179
179
  color: #000;
180
180
  font-size: 14px;
@@ -204,3 +204,10 @@ input[disabled].uploader-button.gray {
204
204
  .uploader-dnd-area .attach_item.loading .progressBar {
205
205
  display: block;
206
206
  }
207
+ .uploader-dnd-area .attach_item .thumbnail.preview img {
208
+ width: 50px;
209
+ }
210
+ .uploader-dnd-area .uploader-dnd-hints .uploader-button span {
211
+ margin-top: 6px;
212
+ display: inline-block;
213
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Galeta
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-19 00:00:00.000000000 Z
12
+ date: 2016-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-ui-rails
@@ -78,6 +78,7 @@ files:
78
78
  - README.md
79
79
  - Rakefile
80
80
  - app/assets/javascripts/uploader/application.js
81
+ - app/assets/javascripts/uploader/jquery.uploader.js.coffee
81
82
  - app/assets/stylesheets/uploader/application.css
82
83
  - app/controllers/uploader/attachments_controller.rb
83
84
  - app/views/uploader/default/_container.html.erb
@@ -91,7 +92,11 @@ files:
91
92
  - lib/rails-uploader.rb
92
93
  - lib/uploader.rb
93
94
  - lib/uploader/asset.rb
95
+ - lib/uploader/authorization.rb
96
+ - lib/uploader/authorization_adapter.rb
97
+ - lib/uploader/chunked_uploads.rb
94
98
  - lib/uploader/engine.rb
99
+ - lib/uploader/file_part.rb
95
100
  - lib/uploader/fileuploads.rb
96
101
  - lib/uploader/helpers/field_tag.rb
97
102
  - lib/uploader/helpers/form_builder.rb
@@ -99,6 +104,7 @@ files:
99
104
  - lib/uploader/hooks/active_record.rb
100
105
  - lib/uploader/hooks/formtastic.rb
101
106
  - lib/uploader/hooks/simple_form.rb
107
+ - lib/uploader/upload_request.rb
102
108
  - lib/uploader/version.rb
103
109
  - spec/dummy/README.rdoc
104
110
  - spec/dummy/Rakefile
@@ -171,16 +177,13 @@ files:
171
177
  - vendor/assets/images/uploader/ico_attach.png
172
178
  - vendor/assets/images/uploader/preloader.gif
173
179
  - vendor/assets/images/uploader/progressBarFillBg.png
174
- - vendor/assets/javascripts/uploader/jquery.fileupload-fp.js
180
+ - vendor/assets/javascripts/uploader/jquery.fileupload-process.js
175
181
  - vendor/assets/javascripts/uploader/jquery.fileupload-ui.js
182
+ - vendor/assets/javascripts/uploader/jquery.fileupload-validate.js
176
183
  - vendor/assets/javascripts/uploader/jquery.fileupload.js
177
184
  - vendor/assets/javascripts/uploader/jquery.iframe-transport.js
178
- - vendor/assets/javascripts/uploader/jquery.ui.widget.js
179
- - vendor/assets/javascripts/uploader/load-image.min.js
180
- - vendor/assets/javascripts/uploader/locales/en.js
181
- - vendor/assets/javascripts/uploader/locales/ru.js
182
- - vendor/assets/javascripts/uploader/locales/uk.js
183
- - vendor/assets/javascripts/uploader/tmpl.min.js
185
+ - vendor/assets/javascripts/uploader/vendor/jquery.ui.widget.js
186
+ - vendor/assets/javascripts/uploader/vendor/tmpl.min.js
184
187
  - vendor/assets/stylesheets/uploader/default.css
185
188
  - vendor/assets/stylesheets/uploader/jquery.fileupload-ui.css
186
189
  homepage: https://github.com/superp/rails-uploader
@@ -1,227 +0,0 @@
1
- /*
2
- * jQuery File Upload File Processing Plugin 1.2.3
3
- * https://github.com/blueimp/jQuery-File-Upload
4
- *
5
- * Copyright 2012, Sebastian Tschan
6
- * https://blueimp.net
7
- *
8
- * Licensed under the MIT license:
9
- * http://www.opensource.org/licenses/MIT
10
- */
11
-
12
- /*jslint nomen: true, unparam: true, regexp: true */
13
- /*global define, window, document */
14
-
15
- (function (factory) {
16
- 'use strict';
17
- if (typeof define === 'function' && define.amd) {
18
- // Register as an anonymous AMD module:
19
- define([
20
- 'jquery',
21
- 'load-image',
22
- 'canvas-to-blob',
23
- './jquery.fileupload'
24
- ], factory);
25
- } else {
26
- // Browser globals:
27
- factory(
28
- window.jQuery,
29
- window.loadImage
30
- );
31
- }
32
- }(function ($, loadImage) {
33
- 'use strict';
34
-
35
- // The File Upload FP version extends the fileupload widget
36
- // with file processing functionality:
37
- $.widget('blueimp.fileupload', $.blueimp.fileupload, {
38
-
39
- options: {
40
- // The list of file processing actions:
41
- process: [
42
- /*
43
- {
44
- action: 'load',
45
- fileTypes: /^image\/(gif|jpeg|png)$/,
46
- maxFileSize: 20000000 // 20MB
47
- },
48
- {
49
- action: 'resize',
50
- maxWidth: 1920,
51
- maxHeight: 1200,
52
- minWidth: 800,
53
- minHeight: 600
54
- },
55
- {
56
- action: 'save'
57
- }
58
- */
59
- ],
60
-
61
- // The add callback is invoked as soon as files are added to the
62
- // fileupload widget (via file input selection, drag & drop or add
63
- // API call). See the basic file upload widget for more information:
64
- add: function (e, data) {
65
- if (data.autoUpload || (data.autoUpload !== false &&
66
- ($(this).data('blueimp-fileupload') ||
67
- $(this).data('fileupload')).options.autoUpload)) {
68
- $(this).fileupload('process', data).done(function () {
69
- data.submit();
70
- });
71
- }
72
- }
73
- },
74
-
75
- processActions: {
76
- // Loads the image given via data.files and data.index
77
- // as img element if the browser supports canvas.
78
- // Accepts the options fileTypes (regular expression)
79
- // and maxFileSize (integer) to limit the files to load:
80
- load: function (data, options) {
81
- var that = this,
82
- file = data.files[data.index],
83
- dfd = $.Deferred();
84
- if (window.HTMLCanvasElement &&
85
- window.HTMLCanvasElement.prototype.toBlob &&
86
- ($.type(options.maxFileSize) !== 'number' ||
87
- file.size < options.maxFileSize) &&
88
- (!options.fileTypes ||
89
- options.fileTypes.test(file.type))) {
90
- loadImage(
91
- file,
92
- function (img) {
93
- if (!img.src) {
94
- return dfd.rejectWith(that, [data]);
95
- }
96
- data.img = img;
97
- dfd.resolveWith(that, [data]);
98
- }
99
- );
100
- } else {
101
- dfd.rejectWith(that, [data]);
102
- }
103
- return dfd.promise();
104
- },
105
- // Resizes the image given as data.img and updates
106
- // data.canvas with the resized image as canvas element.
107
- // Accepts the options maxWidth, maxHeight, minWidth and
108
- // minHeight to scale the given image:
109
- resize: function (data, options) {
110
- var img = data.img,
111
- canvas;
112
- options = $.extend({canvas: true}, options);
113
- if (img) {
114
- canvas = loadImage.scale(img, options);
115
- if (canvas.width !== img.width ||
116
- canvas.height !== img.height) {
117
- data.canvas = canvas;
118
- }
119
- }
120
- return data;
121
- },
122
- // Saves the processed image given as data.canvas
123
- // inplace at data.index of data.files:
124
- save: function (data, options) {
125
- // Do nothing if no processing has happened:
126
- if (!data.canvas) {
127
- return data;
128
- }
129
- var that = this,
130
- file = data.files[data.index],
131
- name = file.name,
132
- dfd = $.Deferred(),
133
- callback = function (blob) {
134
- if (!blob.name) {
135
- if (file.type === blob.type) {
136
- blob.name = file.name;
137
- } else if (file.name) {
138
- blob.name = file.name.replace(
139
- /\..+$/,
140
- '.' + blob.type.substr(6)
141
- );
142
- }
143
- }
144
- // Store the created blob at the position
145
- // of the original file in the files list:
146
- data.files[data.index] = blob;
147
- dfd.resolveWith(that, [data]);
148
- };
149
- // Use canvas.mozGetAsFile directly, to retain the filename, as
150
- // Gecko doesn't support the filename option for FormData.append:
151
- if (data.canvas.mozGetAsFile) {
152
- callback(data.canvas.mozGetAsFile(
153
- (/^image\/(jpeg|png)$/.test(file.type) && name) ||
154
- ((name && name.replace(/\..+$/, '')) ||
155
- 'blob') + '.png',
156
- file.type
157
- ));
158
- } else {
159
- data.canvas.toBlob(callback, file.type);
160
- }
161
- return dfd.promise();
162
- }
163
- },
164
-
165
- // Resizes the file at the given index and stores the created blob at
166
- // the original position of the files list, returns a Promise object:
167
- _processFile: function (files, index, options) {
168
- var that = this,
169
- dfd = $.Deferred().resolveWith(that, [{
170
- files: files,
171
- index: index
172
- }]),
173
- chain = dfd.promise();
174
- that._processing += 1;
175
- $.each(options.process, function (i, settings) {
176
- chain = chain.pipe(function (data) {
177
- return that.processActions[settings.action]
178
- .call(this, data, settings);
179
- });
180
- });
181
- chain.always(function () {
182
- that._processing -= 1;
183
- if (that._processing === 0) {
184
- that.element
185
- .removeClass('fileupload-processing');
186
- }
187
- });
188
- if (that._processing === 1) {
189
- that.element.addClass('fileupload-processing');
190
- }
191
- return chain;
192
- },
193
-
194
- // Processes the files given as files property of the data parameter,
195
- // returns a Promise object that allows to bind a done handler, which
196
- // will be invoked after processing all files (inplace) is done:
197
- process: function (data) {
198
- var that = this,
199
- options = $.extend({}, this.options, data);
200
- if (options.process && options.process.length &&
201
- this._isXHRUpload(options)) {
202
- $.each(data.files, function (index, file) {
203
- that._processingQueue = that._processingQueue.pipe(
204
- function () {
205
- var dfd = $.Deferred();
206
- that._processFile(data.files, index, options)
207
- .always(function () {
208
- dfd.resolveWith(that);
209
- });
210
- return dfd.promise();
211
- }
212
- );
213
- });
214
- }
215
- return this._processingQueue;
216
- },
217
-
218
- _create: function () {
219
- this._super();
220
- this._processing = 0;
221
- this._processingQueue = $.Deferred().resolveWith(this)
222
- .promise();
223
- }
224
-
225
- });
226
-
227
- }));
@@ -1,530 +0,0 @@
1
- /*
2
- * jQuery UI Widget 1.10.0+amd
3
- * https://github.com/blueimp/jQuery-File-Upload
4
- *
5
- * Copyright 2013 jQuery Foundation and other contributors
6
- * Released under the MIT license.
7
- * http://jquery.org/license
8
- *
9
- * http://api.jqueryui.com/jQuery.widget/
10
- */
11
-
12
- (function (factory) {
13
- if (typeof define === "function" && define.amd) {
14
- // Register as an anonymous AMD module:
15
- define(["jquery"], factory);
16
- } else {
17
- // Browser globals:
18
- factory(jQuery);
19
- }
20
- }(function( $, undefined ) {
21
-
22
- var uuid = 0,
23
- slice = Array.prototype.slice,
24
- _cleanData = $.cleanData;
25
- $.cleanData = function( elems ) {
26
- for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
27
- try {
28
- $( elem ).triggerHandler( "remove" );
29
- // http://bugs.jquery.com/ticket/8235
30
- } catch( e ) {}
31
- }
32
- _cleanData( elems );
33
- };
34
-
35
- $.widget = function( name, base, prototype ) {
36
- var fullName, existingConstructor, constructor, basePrototype,
37
- // proxiedPrototype allows the provided prototype to remain unmodified
38
- // so that it can be used as a mixin for multiple widgets (#8876)
39
- proxiedPrototype = {},
40
- namespace = name.split( "." )[ 0 ];
41
-
42
- name = name.split( "." )[ 1 ];
43
- fullName = namespace + "-" + name;
44
-
45
- if ( !prototype ) {
46
- prototype = base;
47
- base = $.Widget;
48
- }
49
-
50
- // create selector for plugin
51
- $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
52
- return !!$.data( elem, fullName );
53
- };
54
-
55
- $[ namespace ] = $[ namespace ] || {};
56
- existingConstructor = $[ namespace ][ name ];
57
- constructor = $[ namespace ][ name ] = function( options, element ) {
58
- // allow instantiation without "new" keyword
59
- if ( !this._createWidget ) {
60
- return new constructor( options, element );
61
- }
62
-
63
- // allow instantiation without initializing for simple inheritance
64
- // must use "new" keyword (the code above always passes args)
65
- if ( arguments.length ) {
66
- this._createWidget( options, element );
67
- }
68
- };
69
- // extend with the existing constructor to carry over any static properties
70
- $.extend( constructor, existingConstructor, {
71
- version: prototype.version,
72
- // copy the object used to create the prototype in case we need to
73
- // redefine the widget later
74
- _proto: $.extend( {}, prototype ),
75
- // track widgets that inherit from this widget in case this widget is
76
- // redefined after a widget inherits from it
77
- _childConstructors: []
78
- });
79
-
80
- basePrototype = new base();
81
- // we need to make the options hash a property directly on the new instance
82
- // otherwise we'll modify the options hash on the prototype that we're
83
- // inheriting from
84
- basePrototype.options = $.widget.extend( {}, basePrototype.options );
85
- $.each( prototype, function( prop, value ) {
86
- if ( !$.isFunction( value ) ) {
87
- proxiedPrototype[ prop ] = value;
88
- return;
89
- }
90
- proxiedPrototype[ prop ] = (function() {
91
- var _super = function() {
92
- return base.prototype[ prop ].apply( this, arguments );
93
- },
94
- _superApply = function( args ) {
95
- return base.prototype[ prop ].apply( this, args );
96
- };
97
- return function() {
98
- var __super = this._super,
99
- __superApply = this._superApply,
100
- returnValue;
101
-
102
- this._super = _super;
103
- this._superApply = _superApply;
104
-
105
- returnValue = value.apply( this, arguments );
106
-
107
- this._super = __super;
108
- this._superApply = __superApply;
109
-
110
- return returnValue;
111
- };
112
- })();
113
- });
114
- constructor.prototype = $.widget.extend( basePrototype, {
115
- // TODO: remove support for widgetEventPrefix
116
- // always use the name + a colon as the prefix, e.g., draggable:start
117
- // don't prefix for widgets that aren't DOM-based
118
- widgetEventPrefix: existingConstructor ? basePrototype.widgetEventPrefix : name
119
- }, proxiedPrototype, {
120
- constructor: constructor,
121
- namespace: namespace,
122
- widgetName: name,
123
- widgetFullName: fullName
124
- });
125
-
126
- // If this widget is being redefined then we need to find all widgets that
127
- // are inheriting from it and redefine all of them so that they inherit from
128
- // the new version of this widget. We're essentially trying to replace one
129
- // level in the prototype chain.
130
- if ( existingConstructor ) {
131
- $.each( existingConstructor._childConstructors, function( i, child ) {
132
- var childPrototype = child.prototype;
133
-
134
- // redefine the child widget using the same prototype that was
135
- // originally used, but inherit from the new version of the base
136
- $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
137
- });
138
- // remove the list of existing child constructors from the old constructor
139
- // so the old child constructors can be garbage collected
140
- delete existingConstructor._childConstructors;
141
- } else {
142
- base._childConstructors.push( constructor );
143
- }
144
-
145
- $.widget.bridge( name, constructor );
146
- };
147
-
148
- $.widget.extend = function( target ) {
149
- var input = slice.call( arguments, 1 ),
150
- inputIndex = 0,
151
- inputLength = input.length,
152
- key,
153
- value;
154
- for ( ; inputIndex < inputLength; inputIndex++ ) {
155
- for ( key in input[ inputIndex ] ) {
156
- value = input[ inputIndex ][ key ];
157
- if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
158
- // Clone objects
159
- if ( $.isPlainObject( value ) ) {
160
- target[ key ] = $.isPlainObject( target[ key ] ) ?
161
- $.widget.extend( {}, target[ key ], value ) :
162
- // Don't extend strings, arrays, etc. with objects
163
- $.widget.extend( {}, value );
164
- // Copy everything else by reference
165
- } else {
166
- target[ key ] = value;
167
- }
168
- }
169
- }
170
- }
171
- return target;
172
- };
173
-
174
- $.widget.bridge = function( name, object ) {
175
- var fullName = object.prototype.widgetFullName || name;
176
- $.fn[ name ] = function( options ) {
177
- var isMethodCall = typeof options === "string",
178
- args = slice.call( arguments, 1 ),
179
- returnValue = this;
180
-
181
- // allow multiple hashes to be passed on init
182
- options = !isMethodCall && args.length ?
183
- $.widget.extend.apply( null, [ options ].concat(args) ) :
184
- options;
185
-
186
- if ( isMethodCall ) {
187
- this.each(function() {
188
- var methodValue,
189
- instance = $.data( this, fullName );
190
- if ( !instance ) {
191
- return $.error( "cannot call methods on " + name + " prior to initialization; " +
192
- "attempted to call method '" + options + "'" );
193
- }
194
- if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
195
- return $.error( "no such method '" + options + "' for " + name + " widget instance" );
196
- }
197
- methodValue = instance[ options ].apply( instance, args );
198
- if ( methodValue !== instance && methodValue !== undefined ) {
199
- returnValue = methodValue && methodValue.jquery ?
200
- returnValue.pushStack( methodValue.get() ) :
201
- methodValue;
202
- return false;
203
- }
204
- });
205
- } else {
206
- this.each(function() {
207
- var instance = $.data( this, fullName );
208
- if ( instance ) {
209
- instance.option( options || {} )._init();
210
- } else {
211
- $.data( this, fullName, new object( options, this ) );
212
- }
213
- });
214
- }
215
-
216
- return returnValue;
217
- };
218
- };
219
-
220
- $.Widget = function( /* options, element */ ) {};
221
- $.Widget._childConstructors = [];
222
-
223
- $.Widget.prototype = {
224
- widgetName: "widget",
225
- widgetEventPrefix: "",
226
- defaultElement: "<div>",
227
- options: {
228
- disabled: false,
229
-
230
- // callbacks
231
- create: null
232
- },
233
- _createWidget: function( options, element ) {
234
- element = $( element || this.defaultElement || this )[ 0 ];
235
- this.element = $( element );
236
- this.uuid = uuid++;
237
- this.eventNamespace = "." + this.widgetName + this.uuid;
238
- this.options = $.widget.extend( {},
239
- this.options,
240
- this._getCreateOptions(),
241
- options );
242
-
243
- this.bindings = $();
244
- this.hoverable = $();
245
- this.focusable = $();
246
-
247
- if ( element !== this ) {
248
- $.data( element, this.widgetFullName, this );
249
- this._on( true, this.element, {
250
- remove: function( event ) {
251
- if ( event.target === element ) {
252
- this.destroy();
253
- }
254
- }
255
- });
256
- this.document = $( element.style ?
257
- // element within the document
258
- element.ownerDocument :
259
- // element is window or document
260
- element.document || element );
261
- this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
262
- }
263
-
264
- this._create();
265
- this._trigger( "create", null, this._getCreateEventData() );
266
- this._init();
267
- },
268
- _getCreateOptions: $.noop,
269
- _getCreateEventData: $.noop,
270
- _create: $.noop,
271
- _init: $.noop,
272
-
273
- destroy: function() {
274
- this._destroy();
275
- // we can probably remove the unbind calls in 2.0
276
- // all event bindings should go through this._on()
277
- this.element
278
- .unbind( this.eventNamespace )
279
- // 1.9 BC for #7810
280
- // TODO remove dual storage
281
- .removeData( this.widgetName )
282
- .removeData( this.widgetFullName )
283
- // support: jquery <1.6.3
284
- // http://bugs.jquery.com/ticket/9413
285
- .removeData( $.camelCase( this.widgetFullName ) );
286
- this.widget()
287
- .unbind( this.eventNamespace )
288
- .removeAttr( "aria-disabled" )
289
- .removeClass(
290
- this.widgetFullName + "-disabled " +
291
- "ui-state-disabled" );
292
-
293
- // clean up events and states
294
- this.bindings.unbind( this.eventNamespace );
295
- this.hoverable.removeClass( "ui-state-hover" );
296
- this.focusable.removeClass( "ui-state-focus" );
297
- },
298
- _destroy: $.noop,
299
-
300
- widget: function() {
301
- return this.element;
302
- },
303
-
304
- option: function( key, value ) {
305
- var options = key,
306
- parts,
307
- curOption,
308
- i;
309
-
310
- if ( arguments.length === 0 ) {
311
- // don't return a reference to the internal hash
312
- return $.widget.extend( {}, this.options );
313
- }
314
-
315
- if ( typeof key === "string" ) {
316
- // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
317
- options = {};
318
- parts = key.split( "." );
319
- key = parts.shift();
320
- if ( parts.length ) {
321
- curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
322
- for ( i = 0; i < parts.length - 1; i++ ) {
323
- curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
324
- curOption = curOption[ parts[ i ] ];
325
- }
326
- key = parts.pop();
327
- if ( value === undefined ) {
328
- return curOption[ key ] === undefined ? null : curOption[ key ];
329
- }
330
- curOption[ key ] = value;
331
- } else {
332
- if ( value === undefined ) {
333
- return this.options[ key ] === undefined ? null : this.options[ key ];
334
- }
335
- options[ key ] = value;
336
- }
337
- }
338
-
339
- this._setOptions( options );
340
-
341
- return this;
342
- },
343
- _setOptions: function( options ) {
344
- var key;
345
-
346
- for ( key in options ) {
347
- this._setOption( key, options[ key ] );
348
- }
349
-
350
- return this;
351
- },
352
- _setOption: function( key, value ) {
353
- this.options[ key ] = value;
354
-
355
- if ( key === "disabled" ) {
356
- this.widget()
357
- .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
358
- .attr( "aria-disabled", value );
359
- this.hoverable.removeClass( "ui-state-hover" );
360
- this.focusable.removeClass( "ui-state-focus" );
361
- }
362
-
363
- return this;
364
- },
365
-
366
- enable: function() {
367
- return this._setOption( "disabled", false );
368
- },
369
- disable: function() {
370
- return this._setOption( "disabled", true );
371
- },
372
-
373
- _on: function( suppressDisabledCheck, element, handlers ) {
374
- var delegateElement,
375
- instance = this;
376
-
377
- // no suppressDisabledCheck flag, shuffle arguments
378
- if ( typeof suppressDisabledCheck !== "boolean" ) {
379
- handlers = element;
380
- element = suppressDisabledCheck;
381
- suppressDisabledCheck = false;
382
- }
383
-
384
- // no element argument, shuffle and use this.element
385
- if ( !handlers ) {
386
- handlers = element;
387
- element = this.element;
388
- delegateElement = this.widget();
389
- } else {
390
- // accept selectors, DOM elements
391
- element = delegateElement = $( element );
392
- this.bindings = this.bindings.add( element );
393
- }
394
-
395
- $.each( handlers, function( event, handler ) {
396
- function handlerProxy() {
397
- // allow widgets to customize the disabled handling
398
- // - disabled as an array instead of boolean
399
- // - disabled class as method for disabling individual parts
400
- if ( !suppressDisabledCheck &&
401
- ( instance.options.disabled === true ||
402
- $( this ).hasClass( "ui-state-disabled" ) ) ) {
403
- return;
404
- }
405
- return ( typeof handler === "string" ? instance[ handler ] : handler )
406
- .apply( instance, arguments );
407
- }
408
-
409
- // copy the guid so direct unbinding works
410
- if ( typeof handler !== "string" ) {
411
- handlerProxy.guid = handler.guid =
412
- handler.guid || handlerProxy.guid || $.guid++;
413
- }
414
-
415
- var match = event.match( /^(\w+)\s*(.*)$/ ),
416
- eventName = match[1] + instance.eventNamespace,
417
- selector = match[2];
418
- if ( selector ) {
419
- delegateElement.delegate( selector, eventName, handlerProxy );
420
- } else {
421
- element.bind( eventName, handlerProxy );
422
- }
423
- });
424
- },
425
-
426
- _off: function( element, eventName ) {
427
- eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
428
- element.unbind( eventName ).undelegate( eventName );
429
- },
430
-
431
- _delay: function( handler, delay ) {
432
- function handlerProxy() {
433
- return ( typeof handler === "string" ? instance[ handler ] : handler )
434
- .apply( instance, arguments );
435
- }
436
- var instance = this;
437
- return setTimeout( handlerProxy, delay || 0 );
438
- },
439
-
440
- _hoverable: function( element ) {
441
- this.hoverable = this.hoverable.add( element );
442
- this._on( element, {
443
- mouseenter: function( event ) {
444
- $( event.currentTarget ).addClass( "ui-state-hover" );
445
- },
446
- mouseleave: function( event ) {
447
- $( event.currentTarget ).removeClass( "ui-state-hover" );
448
- }
449
- });
450
- },
451
-
452
- _focusable: function( element ) {
453
- this.focusable = this.focusable.add( element );
454
- this._on( element, {
455
- focusin: function( event ) {
456
- $( event.currentTarget ).addClass( "ui-state-focus" );
457
- },
458
- focusout: function( event ) {
459
- $( event.currentTarget ).removeClass( "ui-state-focus" );
460
- }
461
- });
462
- },
463
-
464
- _trigger: function( type, event, data ) {
465
- var prop, orig,
466
- callback = this.options[ type ];
467
-
468
- data = data || {};
469
- event = $.Event( event );
470
- event.type = ( type === this.widgetEventPrefix ?
471
- type :
472
- this.widgetEventPrefix + type ).toLowerCase();
473
- // the original event may come from any element
474
- // so we need to reset the target on the new event
475
- event.target = this.element[ 0 ];
476
-
477
- // copy original event properties over to the new event
478
- orig = event.originalEvent;
479
- if ( orig ) {
480
- for ( prop in orig ) {
481
- if ( !( prop in event ) ) {
482
- event[ prop ] = orig[ prop ];
483
- }
484
- }
485
- }
486
-
487
- this.element.trigger( event, data );
488
- return !( $.isFunction( callback ) &&
489
- callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
490
- event.isDefaultPrevented() );
491
- }
492
- };
493
-
494
- $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
495
- $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
496
- if ( typeof options === "string" ) {
497
- options = { effect: options };
498
- }
499
- var hasOptions,
500
- effectName = !options ?
501
- method :
502
- options === true || typeof options === "number" ?
503
- defaultEffect :
504
- options.effect || defaultEffect;
505
- options = options || {};
506
- if ( typeof options === "number" ) {
507
- options = { duration: options };
508
- }
509
- hasOptions = !$.isEmptyObject( options );
510
- options.complete = callback;
511
- if ( options.delay ) {
512
- element.delay( options.delay );
513
- }
514
- if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
515
- element[ method ]( options );
516
- } else if ( effectName !== method && element[ effectName ] ) {
517
- element[ effectName ]( options.duration, options.easing, callback );
518
- } else {
519
- element.queue(function( next ) {
520
- $( this )[ method ]();
521
- if ( callback ) {
522
- callback.call( element[ 0 ] );
523
- }
524
- next();
525
- });
526
- }
527
- };
528
- });
529
-
530
- }));