jquery-file-upload-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +55 -0
  4. data/Rakefile +32 -0
  5. data/app/views/jquery_file_upload/basic_plus_ui/_download.html.erb +43 -0
  6. data/app/views/jquery_file_upload/basic_plus_ui/_form.html.haml +35 -0
  7. data/app/views/jquery_file_upload/basic_plus_ui/_upload.html.erb +32 -0
  8. data/config/locales/jquery_file_upload.cs.yml +16 -0
  9. data/config/locales/jquery_file_upload.en.yml +16 -0
  10. data/lib/jquery-file-upload-rails.rb +1 -0
  11. data/lib/jquery_file_upload/rails.rb +6 -0
  12. data/lib/jquery_file_upload/rails/version.rb +5 -0
  13. data/test/dummy/README.rdoc +28 -0
  14. data/test/dummy/app/assets/javascripts/application.js +13 -0
  15. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  16. data/test/dummy/app/controllers/application_controller.rb +5 -0
  17. data/test/dummy/app/helpers/application_helper.rb +2 -0
  18. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  19. data/test/dummy/bin/bundle +3 -0
  20. data/test/dummy/bin/rails +4 -0
  21. data/test/dummy/bin/rake +4 -0
  22. data/test/dummy/config.ru +4 -0
  23. data/test/dummy/config/application.rb +22 -0
  24. data/test/dummy/config/boot.rb +5 -0
  25. data/test/dummy/config/database.yml +25 -0
  26. data/test/dummy/config/environment.rb +5 -0
  27. data/test/dummy/config/environments/development.rb +29 -0
  28. data/test/dummy/config/environments/production.rb +80 -0
  29. data/test/dummy/config/environments/test.rb +36 -0
  30. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  31. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  32. data/test/dummy/config/initializers/inflections.rb +16 -0
  33. data/test/dummy/config/initializers/mime_types.rb +5 -0
  34. data/test/dummy/config/initializers/secret_token.rb +12 -0
  35. data/test/dummy/config/initializers/session_store.rb +3 -0
  36. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  37. data/test/dummy/config/locales/en.yml +23 -0
  38. data/test/dummy/config/routes.rb +56 -0
  39. data/test/dummy/db/test.sqlite3 +0 -0
  40. data/test/jquery_file_upload_rails_test.rb +7 -0
  41. data/test/test_helper.rb +15 -0
  42. data/vendor/assets/images/jquery-file-upload/loading.gif +0 -0
  43. data/vendor/assets/images/jquery-file-upload/progressbar.gif +0 -0
  44. data/vendor/assets/javascripts/jquery-file-upload/app.js +101 -0
  45. data/vendor/assets/javascripts/jquery-file-upload/basic-plus-ui-no-widget.js.coffee +35 -0
  46. data/vendor/assets/javascripts/jquery-file-upload/basic-plus-ui.js.coffee +38 -0
  47. data/vendor/assets/javascripts/jquery-file-upload/cors/jquery.postmessage-transport.js +118 -0
  48. data/vendor/assets/javascripts/jquery-file-upload/cors/jquery.xdr-transport.js +87 -0
  49. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-angular.js +428 -0
  50. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-audio.js +106 -0
  51. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-image.js +295 -0
  52. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-jquery-ui.js +144 -0
  53. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-process.js +172 -0
  54. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-ui.js +699 -0
  55. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-validate.js +120 -0
  56. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-video.js +106 -0
  57. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload.js +1416 -0
  58. data/vendor/assets/javascripts/jquery-file-upload/jquery.iframe-transport.js +210 -0
  59. data/vendor/assets/javascripts/jquery-file-upload/main.js.coffee +4 -0
  60. data/vendor/assets/javascripts/jquery-file-upload/vendor/canvas-to-blob/canvas-to-blob.js +95 -0
  61. data/vendor/assets/javascripts/jquery-file-upload/vendor/canvas-to-blob/canvas-to-blob.min.js +1 -0
  62. data/vendor/assets/javascripts/jquery-file-upload/vendor/jquery.ui.widget.js +530 -0
  63. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/demo.js +138 -0
  64. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-exif-map.js +384 -0
  65. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-exif.js +299 -0
  66. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-ios.js +181 -0
  67. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-meta.js +137 -0
  68. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-orientation.js +159 -0
  69. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image.js +276 -0
  70. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image.min.js +1 -0
  71. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/vendor/jquery.Jcrop.js +1694 -0
  72. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/compile.js +84 -0
  73. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/demo.js +48 -0
  74. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/runtime.js +47 -0
  75. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/tmpl.js +87 -0
  76. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/tmpl.min.js +1 -0
  77. data/vendor/assets/stylesheets/jquery-file-upload/demo-ie8.css +21 -0
  78. data/vendor/assets/stylesheets/jquery-file-upload/demo.css +67 -0
  79. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-noscript.css +22 -0
  80. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-ui-noscript.css +17 -0
  81. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-ui.css.scss +57 -0
  82. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload.css +36 -0
  83. data/vendor/assets/stylesheets/jquery-file-upload/style.css +15 -0
  84. metadata +196 -0
@@ -0,0 +1,210 @@
1
+ /*
2
+ * jQuery Iframe Transport Plugin 1.8.1
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2011, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /*jslint unparam: true, nomen: 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(['jquery'], factory);
20
+ } else {
21
+ // Browser globals:
22
+ factory(window.jQuery);
23
+ }
24
+ }(function ($) {
25
+ 'use strict';
26
+
27
+ // Helper variable to create unique names for the transport iframes:
28
+ var counter = 0;
29
+
30
+ // The iframe transport accepts four additional options:
31
+ // options.fileInput: a jQuery collection of file input fields
32
+ // options.paramName: the parameter name for the file form data,
33
+ // overrides the name property of the file input field(s),
34
+ // can be a string or an array of strings.
35
+ // options.formData: an array of objects with name and value properties,
36
+ // equivalent to the return data of .serializeArray(), e.g.:
37
+ // [{name: 'a', value: 1}, {name: 'b', value: 2}]
38
+ // options.initialIframeSrc: the URL of the initial iframe src,
39
+ // by default set to "javascript:false;"
40
+ $.ajaxTransport('iframe', function (options) {
41
+ if (options.async) {
42
+ // javascript:false as initial iframe src
43
+ // prevents warning popups on HTTPS in IE6:
44
+ /*jshint scripturl: true */
45
+ var initialIframeSrc = options.initialIframeSrc || 'javascript:false;',
46
+ /*jshint scripturl: false */
47
+ form,
48
+ iframe,
49
+ addParamChar;
50
+ return {
51
+ send: function (_, completeCallback) {
52
+ form = $('<form style="display:none;"></form>');
53
+ form.attr('accept-charset', options.formAcceptCharset);
54
+ addParamChar = /\?/.test(options.url) ? '&' : '?';
55
+ // XDomainRequest only supports GET and POST:
56
+ if (options.type === 'DELETE') {
57
+ options.url = options.url + addParamChar + '_method=DELETE';
58
+ options.type = 'POST';
59
+ } else if (options.type === 'PUT') {
60
+ options.url = options.url + addParamChar + '_method=PUT';
61
+ options.type = 'POST';
62
+ } else if (options.type === 'PATCH') {
63
+ options.url = options.url + addParamChar + '_method=PATCH';
64
+ options.type = 'POST';
65
+ }
66
+ // IE versions below IE8 cannot set the name property of
67
+ // elements that have already been added to the DOM,
68
+ // so we set the name along with the iframe HTML markup:
69
+ counter += 1;
70
+ iframe = $(
71
+ '<iframe src="' + initialIframeSrc +
72
+ '" name="iframe-transport-' + counter + '"></iframe>'
73
+ ).bind('load', function () {
74
+ var fileInputClones,
75
+ paramNames = $.isArray(options.paramName) ?
76
+ options.paramName : [options.paramName];
77
+ iframe
78
+ .unbind('load')
79
+ .bind('load', function () {
80
+ var response;
81
+ // Wrap in a try/catch block to catch exceptions thrown
82
+ // when trying to access cross-domain iframe contents:
83
+ try {
84
+ response = iframe.contents();
85
+ // Google Chrome and Firefox do not throw an
86
+ // exception when calling iframe.contents() on
87
+ // cross-domain requests, so we unify the response:
88
+ if (!response.length || !response[0].firstChild) {
89
+ throw new Error();
90
+ }
91
+ } catch (e) {
92
+ response = undefined;
93
+ }
94
+ // The complete callback returns the
95
+ // iframe content document as response object:
96
+ completeCallback(
97
+ 200,
98
+ 'success',
99
+ {'iframe': response}
100
+ );
101
+ // Fix for IE endless progress bar activity bug
102
+ // (happens on form submits to iframe targets):
103
+ $('<iframe src="' + initialIframeSrc + '"></iframe>')
104
+ .appendTo(form);
105
+ window.setTimeout(function () {
106
+ // Removing the form in a setTimeout call
107
+ // allows Chrome's developer tools to display
108
+ // the response result
109
+ form.remove();
110
+ }, 0);
111
+ });
112
+ form
113
+ .prop('target', iframe.prop('name'))
114
+ .prop('action', options.url)
115
+ .prop('method', options.type);
116
+ if (options.formData) {
117
+ $.each(options.formData, function (index, field) {
118
+ $('<input type="hidden"/>')
119
+ .prop('name', field.name)
120
+ .val(field.value)
121
+ .appendTo(form);
122
+ });
123
+ }
124
+ if (options.fileInput && options.fileInput.length &&
125
+ options.type === 'POST') {
126
+ fileInputClones = options.fileInput.clone();
127
+ // Insert a clone for each file input field:
128
+ options.fileInput.after(function (index) {
129
+ return fileInputClones[index];
130
+ });
131
+ if (options.paramName) {
132
+ options.fileInput.each(function (index) {
133
+ $(this).prop(
134
+ 'name',
135
+ paramNames[index] || options.paramName
136
+ );
137
+ });
138
+ }
139
+ // Appending the file input fields to the hidden form
140
+ // removes them from their original location:
141
+ form
142
+ .append(options.fileInput)
143
+ .prop('enctype', 'multipart/form-data')
144
+ // enctype must be set as encoding for IE:
145
+ .prop('encoding', 'multipart/form-data');
146
+ }
147
+ form.submit();
148
+ // Insert the file input fields at their original location
149
+ // by replacing the clones with the originals:
150
+ if (fileInputClones && fileInputClones.length) {
151
+ options.fileInput.each(function (index, input) {
152
+ var clone = $(fileInputClones[index]);
153
+ $(input).prop('name', clone.prop('name'));
154
+ clone.replaceWith(input);
155
+ });
156
+ }
157
+ });
158
+ form.append(iframe).appendTo(document.body);
159
+ },
160
+ abort: function () {
161
+ if (iframe) {
162
+ // javascript:false as iframe src aborts the request
163
+ // and prevents warning popups on HTTPS in IE6.
164
+ // concat is used to avoid the "Script URL" JSLint error:
165
+ iframe
166
+ .unbind('load')
167
+ .prop('src', initialIframeSrc);
168
+ }
169
+ if (form) {
170
+ form.remove();
171
+ }
172
+ }
173
+ };
174
+ }
175
+ });
176
+
177
+ // The iframe transport returns the iframe content document as response.
178
+ // The following adds converters from iframe to text, json, html, xml
179
+ // and script.
180
+ // Please note that the Content-Type for JSON responses has to be text/plain
181
+ // or text/html, if the browser doesn't include application/json in the
182
+ // Accept header, else IE will show a download dialog.
183
+ // The Content-Type for XML responses on the other hand has to be always
184
+ // application/xml or text/xml, so IE properly parses the XML response.
185
+ // See also
186
+ // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation
187
+ $.ajaxSetup({
188
+ converters: {
189
+ 'iframe text': function (iframe) {
190
+ return iframe && $(iframe[0].body).text();
191
+ },
192
+ 'iframe json': function (iframe) {
193
+ return iframe && $.parseJSON($(iframe[0].body).text());
194
+ },
195
+ 'iframe html': function (iframe) {
196
+ return iframe && $(iframe[0].body).html();
197
+ },
198
+ 'iframe xml': function (iframe) {
199
+ var xmlDoc = iframe && iframe[0];
200
+ return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc :
201
+ $.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) ||
202
+ $(xmlDoc.body).html());
203
+ },
204
+ 'iframe script': function (iframe) {
205
+ return iframe && $.globalEval($(iframe[0].body).text());
206
+ }
207
+ }
208
+ });
209
+
210
+ }));
@@ -0,0 +1,4 @@
1
+ # jQuery File Upload Plugin Custom configuration
2
+ # Enabling jQuery File Upload
3
+
4
+ $(".fileupload").fileupload()
@@ -0,0 +1,95 @@
1
+ /*
2
+ * JavaScript Canvas to Blob 2.0.5
3
+ * https://github.com/blueimp/JavaScript-Canvas-to-Blob
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
+ * Based on stackoverflow user Stoive's code snippet:
12
+ * http://stackoverflow.com/q/4998908
13
+ */
14
+
15
+ /*jslint nomen: true, regexp: true */
16
+ /*global window, atob, Blob, ArrayBuffer, Uint8Array, define */
17
+
18
+ (function (window) {
19
+ 'use strict';
20
+ var CanvasPrototype = window.HTMLCanvasElement &&
21
+ window.HTMLCanvasElement.prototype,
22
+ hasBlobConstructor = window.Blob && (function () {
23
+ try {
24
+ return Boolean(new Blob());
25
+ } catch (e) {
26
+ return false;
27
+ }
28
+ }()),
29
+ hasArrayBufferViewSupport = hasBlobConstructor && window.Uint8Array &&
30
+ (function () {
31
+ try {
32
+ return new Blob([new Uint8Array(100)]).size === 100;
33
+ } catch (e) {
34
+ return false;
35
+ }
36
+ }()),
37
+ BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder ||
38
+ window.MozBlobBuilder || window.MSBlobBuilder,
39
+ dataURLtoBlob = (hasBlobConstructor || BlobBuilder) && window.atob &&
40
+ window.ArrayBuffer && window.Uint8Array && function (dataURI) {
41
+ var byteString,
42
+ arrayBuffer,
43
+ intArray,
44
+ i,
45
+ mimeString,
46
+ bb;
47
+ if (dataURI.split(',')[0].indexOf('base64') >= 0) {
48
+ // Convert base64 to raw binary data held in a string:
49
+ byteString = atob(dataURI.split(',')[1]);
50
+ } else {
51
+ // Convert base64/URLEncoded data component to raw binary data:
52
+ byteString = decodeURIComponent(dataURI.split(',')[1]);
53
+ }
54
+ // Write the bytes of the string to an ArrayBuffer:
55
+ arrayBuffer = new ArrayBuffer(byteString.length);
56
+ intArray = new Uint8Array(arrayBuffer);
57
+ for (i = 0; i < byteString.length; i += 1) {
58
+ intArray[i] = byteString.charCodeAt(i);
59
+ }
60
+ // Separate out the mime component:
61
+ mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
62
+ // Write the ArrayBuffer (or ArrayBufferView) to a blob:
63
+ if (hasBlobConstructor) {
64
+ return new Blob(
65
+ [hasArrayBufferViewSupport ? intArray : arrayBuffer],
66
+ {type: mimeString}
67
+ );
68
+ }
69
+ bb = new BlobBuilder();
70
+ bb.append(arrayBuffer);
71
+ return bb.getBlob(mimeString);
72
+ };
73
+ if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) {
74
+ if (CanvasPrototype.mozGetAsFile) {
75
+ CanvasPrototype.toBlob = function (callback, type, quality) {
76
+ if (quality && CanvasPrototype.toDataURL && dataURLtoBlob) {
77
+ callback(dataURLtoBlob(this.toDataURL(type, quality)));
78
+ } else {
79
+ callback(this.mozGetAsFile('blob', type));
80
+ }
81
+ };
82
+ } else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
83
+ CanvasPrototype.toBlob = function (callback, type, quality) {
84
+ callback(dataURLtoBlob(this.toDataURL(type, quality)));
85
+ };
86
+ }
87
+ }
88
+ if (typeof define === 'function' && define.amd) {
89
+ define(function () {
90
+ return dataURLtoBlob;
91
+ });
92
+ } else {
93
+ window.dataURLtoBlob = dataURLtoBlob;
94
+ }
95
+ }(this));
@@ -0,0 +1 @@
1
+ !function(a){"use strict";var b=a.HTMLCanvasElement&&a.HTMLCanvasElement.prototype,c=a.Blob&&function(){try{return Boolean(new Blob)}catch(a){return!1}}(),d=c&&a.Uint8Array&&function(){try{return 100===new Blob([new Uint8Array(100)]).size}catch(a){return!1}}(),e=a.BlobBuilder||a.WebKitBlobBuilder||a.MozBlobBuilder||a.MSBlobBuilder,f=(c||e)&&a.atob&&a.ArrayBuffer&&a.Uint8Array&&function(a){var b,f,g,h,i,j;for(b=a.split(",")[0].indexOf("base64")>=0?atob(a.split(",")[1]):decodeURIComponent(a.split(",")[1]),f=new ArrayBuffer(b.length),g=new Uint8Array(f),h=0;h<b.length;h+=1)g[h]=b.charCodeAt(h);return i=a.split(",")[0].split(":")[1].split(";")[0],c?new Blob([d?g:f],{type:i}):(j=new e,j.append(f),j.getBlob(i))};a.HTMLCanvasElement&&!b.toBlob&&(b.mozGetAsFile?b.toBlob=function(a,c,d){d&&b.toDataURL&&f?a(f(this.toDataURL(c,d))):a(this.mozGetAsFile("blob",c))}:b.toDataURL&&f&&(b.toBlob=function(a,b,c){a(f(this.toDataURL(b,c)))})),"function"==typeof define&&define.amd?define(function(){return f}):a.dataURLtoBlob=f}(this);
@@ -0,0 +1,530 @@
1
+ /*
2
+ * jQuery UI Widget 1.10.3+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
+ }));