jquery-fileupload-requirejs-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +3 -0
- data/Rakefile +27 -0
- data/app/assets/images/loading.gif +0 -0
- data/app/assets/images/progressbar.gif +0 -0
- data/app/assets/javascripts/jquery-fileupload/basic.js +4 -0
- data/app/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js +111 -0
- data/app/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js +80 -0
- data/app/assets/javascripts/jquery-fileupload/index.js +9 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js +210 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js +782 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload.js +1156 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js +179 -0
- data/app/assets/javascripts/jquery-fileupload/locale.js +29 -0
- data/app/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js +91 -0
- data/app/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js +533 -0
- data/app/assets/javascripts/jquery-fileupload/vendor/load-image.js +121 -0
- data/app/assets/javascripts/jquery-fileupload/vendor/tmpl.js +86 -0
- data/app/assets/stylesheets/jquery.fileupload-ui.scss +84 -0
- data/lib/jquery-fileupload-requirejs-rails.rb +4 -0
- data/lib/jquery-fileupload-requirejs-rails/engine.rb +4 -0
- data/lib/jquery-fileupload-requirejs-rails/version.rb +3 -0
- data/lib/tasks/jquery-fileupload-requirejs-rails_tasks.rake +4 -0
- metadata +170 -0
@@ -0,0 +1,179 @@
|
|
1
|
+
define(['jquery'], function ($) {
|
2
|
+
|
3
|
+
|
4
|
+
/*
|
5
|
+
* jQuery Iframe Transport Plugin 1.6.1
|
6
|
+
* https://github.com/blueimp/jQuery-File-Upload
|
7
|
+
*
|
8
|
+
* Copyright 2011, Sebastian Tschan
|
9
|
+
* https://blueimp.net
|
10
|
+
*
|
11
|
+
* Licensed under the MIT license:
|
12
|
+
* http://www.opensource.org/licenses/MIT
|
13
|
+
*/
|
14
|
+
|
15
|
+
/*jslint unparam: true, nomen: true */
|
16
|
+
/*global define, window, document */
|
17
|
+
|
18
|
+
|
19
|
+
'use strict';
|
20
|
+
|
21
|
+
// Helper variable to create unique names for the transport iframes:
|
22
|
+
var counter = 0;
|
23
|
+
|
24
|
+
// The iframe transport accepts three additional options:
|
25
|
+
// options.fileInput: a jQuery collection of file input fields
|
26
|
+
// options.paramName: the parameter name for the file form data,
|
27
|
+
// overrides the name property of the file input field(s),
|
28
|
+
// can be a string or an array of strings.
|
29
|
+
// options.formData: an array of objects with name and value properties,
|
30
|
+
// equivalent to the return data of .serializeArray(), e.g.:
|
31
|
+
// [{name: 'a', value: 1}, {name: 'b', value: 2}]
|
32
|
+
$.ajaxTransport('iframe', function (options) {
|
33
|
+
if (options.async) {
|
34
|
+
var form,
|
35
|
+
iframe,
|
36
|
+
addParamChar;
|
37
|
+
return {
|
38
|
+
send: function (_, completeCallback) {
|
39
|
+
form = $('<form style="display:none;"></form>');
|
40
|
+
form.attr('accept-charset', options.formAcceptCharset);
|
41
|
+
addParamChar = /\?/.test(options.url) ? '&' : '?';
|
42
|
+
// XDomainRequest only supports GET and POST:
|
43
|
+
if (options.type === 'DELETE') {
|
44
|
+
options.url = options.url + addParamChar + '_method=DELETE';
|
45
|
+
options.type = 'POST';
|
46
|
+
} else if (options.type === 'PUT') {
|
47
|
+
options.url = options.url + addParamChar + '_method=PUT';
|
48
|
+
options.type = 'POST';
|
49
|
+
} else if (options.type === 'PATCH') {
|
50
|
+
options.url = options.url + addParamChar + '_method=PATCH';
|
51
|
+
options.type = 'POST';
|
52
|
+
}
|
53
|
+
// javascript:false as initial iframe src
|
54
|
+
// prevents warning popups on HTTPS in IE6.
|
55
|
+
// IE versions below IE8 cannot set the name property of
|
56
|
+
// elements that have already been added to the DOM,
|
57
|
+
// so we set the name along with the iframe HTML markup:
|
58
|
+
iframe = $(
|
59
|
+
'<iframe src="javascript:false;" name="iframe-transport-' +
|
60
|
+
(counter += 1) + '"></iframe>'
|
61
|
+
).bind('load', function () {
|
62
|
+
var fileInputClones,
|
63
|
+
paramNames = $.isArray(options.paramName) ?
|
64
|
+
options.paramName : [options.paramName];
|
65
|
+
iframe
|
66
|
+
.unbind('load')
|
67
|
+
.bind('load', function () {
|
68
|
+
var response;
|
69
|
+
// Wrap in a try/catch block to catch exceptions thrown
|
70
|
+
// when trying to access cross-domain iframe contents:
|
71
|
+
try {
|
72
|
+
response = iframe.contents();
|
73
|
+
// Google Chrome and Firefox do not throw an
|
74
|
+
// exception when calling iframe.contents() on
|
75
|
+
// cross-domain requests, so we unify the response:
|
76
|
+
if (!response.length || !response[0].firstChild) {
|
77
|
+
throw new Error();
|
78
|
+
}
|
79
|
+
} catch (e) {
|
80
|
+
response = undefined;
|
81
|
+
}
|
82
|
+
// The complete callback returns the
|
83
|
+
// iframe content document as response object:
|
84
|
+
completeCallback(
|
85
|
+
200,
|
86
|
+
'success',
|
87
|
+
{'iframe': response}
|
88
|
+
);
|
89
|
+
// Fix for IE endless progress bar activity bug
|
90
|
+
// (happens on form submits to iframe targets):
|
91
|
+
$('<iframe src="javascript:false;"></iframe>')
|
92
|
+
.appendTo(form);
|
93
|
+
form.remove();
|
94
|
+
});
|
95
|
+
form
|
96
|
+
.prop('target', iframe.prop('name'))
|
97
|
+
.prop('action', options.url)
|
98
|
+
.prop('method', options.type);
|
99
|
+
if (options.formData) {
|
100
|
+
$.each(options.formData, function (index, field) {
|
101
|
+
$('<input type="hidden"/>')
|
102
|
+
.prop('name', field.name)
|
103
|
+
.val(field.value)
|
104
|
+
.appendTo(form);
|
105
|
+
});
|
106
|
+
}
|
107
|
+
if (options.fileInput && options.fileInput.length &&
|
108
|
+
options.type === 'POST') {
|
109
|
+
fileInputClones = options.fileInput.clone();
|
110
|
+
// Insert a clone for each file input field:
|
111
|
+
options.fileInput.after(function (index) {
|
112
|
+
return fileInputClones[index];
|
113
|
+
});
|
114
|
+
if (options.paramName) {
|
115
|
+
options.fileInput.each(function (index) {
|
116
|
+
$(this).prop(
|
117
|
+
'name',
|
118
|
+
paramNames[index] || options.paramName
|
119
|
+
);
|
120
|
+
});
|
121
|
+
}
|
122
|
+
// Appending the file input fields to the hidden form
|
123
|
+
// removes them from their original location:
|
124
|
+
form
|
125
|
+
.append(options.fileInput)
|
126
|
+
.prop('enctype', 'multipart/form-data')
|
127
|
+
// enctype must be set as encoding for IE:
|
128
|
+
.prop('encoding', 'multipart/form-data');
|
129
|
+
}
|
130
|
+
form.submit();
|
131
|
+
// Insert the file input fields at their original location
|
132
|
+
// by replacing the clones with the originals:
|
133
|
+
if (fileInputClones && fileInputClones.length) {
|
134
|
+
options.fileInput.each(function (index, input) {
|
135
|
+
var clone = $(fileInputClones[index]);
|
136
|
+
$(input).prop('name', clone.prop('name'));
|
137
|
+
clone.replaceWith(input);
|
138
|
+
});
|
139
|
+
}
|
140
|
+
});
|
141
|
+
form.append(iframe).appendTo(document.body);
|
142
|
+
},
|
143
|
+
abort: function () {
|
144
|
+
if (iframe) {
|
145
|
+
// javascript:false as iframe src aborts the request
|
146
|
+
// and prevents warning popups on HTTPS in IE6.
|
147
|
+
// concat is used to avoid the "Script URL" JSLint error:
|
148
|
+
iframe
|
149
|
+
.unbind('load')
|
150
|
+
.prop('src', 'javascript'.concat(':false;'));
|
151
|
+
}
|
152
|
+
if (form) {
|
153
|
+
form.remove();
|
154
|
+
}
|
155
|
+
}
|
156
|
+
};
|
157
|
+
}
|
158
|
+
});
|
159
|
+
|
160
|
+
// The iframe transport returns the iframe content document as response.
|
161
|
+
// The following adds converters from iframe to text, json, html, and script:
|
162
|
+
$.ajaxSetup({
|
163
|
+
converters: {
|
164
|
+
'iframe text': function (iframe) {
|
165
|
+
return iframe && $(iframe[0].body).text();
|
166
|
+
},
|
167
|
+
'iframe json': function (iframe) {
|
168
|
+
return iframe && $.parseJSON($(iframe[0].body).text());
|
169
|
+
},
|
170
|
+
'iframe html': function (iframe) {
|
171
|
+
return iframe && $(iframe[0].body).html();
|
172
|
+
},
|
173
|
+
'iframe script': function (iframe) {
|
174
|
+
return iframe && $.globalEval($(iframe[0].body).text());
|
175
|
+
}
|
176
|
+
}
|
177
|
+
});
|
178
|
+
|
179
|
+
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery File Upload Plugin Localization Example 6.5.1
|
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
|
+
/*global window */
|
13
|
+
|
14
|
+
window.locale = {
|
15
|
+
"fileupload": {
|
16
|
+
"errors": {
|
17
|
+
"maxFileSize": "File is too big",
|
18
|
+
"minFileSize": "File is too small",
|
19
|
+
"acceptFileTypes": "Filetype not allowed",
|
20
|
+
"maxNumberOfFiles": "Max number of files exceeded",
|
21
|
+
"uploadedBytes": "Uploaded bytes exceed file size",
|
22
|
+
"emptyResult": "Empty file upload result"
|
23
|
+
},
|
24
|
+
"error": "Error",
|
25
|
+
"start": "Start",
|
26
|
+
"cancel": "Cancel",
|
27
|
+
"destroy": "Delete"
|
28
|
+
}
|
29
|
+
};
|
@@ -0,0 +1,91 @@
|
|
1
|
+
/*
|
2
|
+
* JavaScript Canvas to Blob 2.0.3
|
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) {
|
76
|
+
callback(this.mozGetAsFile('blob', type));
|
77
|
+
};
|
78
|
+
} else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
|
79
|
+
CanvasPrototype.toBlob = function (callback, type) {
|
80
|
+
callback(dataURLtoBlob(this.toDataURL(type)));
|
81
|
+
};
|
82
|
+
}
|
83
|
+
}
|
84
|
+
if (typeof define === 'function' && define.amd) {
|
85
|
+
define(function () {
|
86
|
+
return dataURLtoBlob;
|
87
|
+
});
|
88
|
+
} else {
|
89
|
+
window.dataURLtoBlob = dataURLtoBlob;
|
90
|
+
}
|
91
|
+
}(this));
|
@@ -0,0 +1,533 @@
|
|
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
|
+
}
|
33
|
+
_cleanData(elems);
|
34
|
+
};
|
35
|
+
|
36
|
+
$.widget = function (name, base, prototype) {
|
37
|
+
var fullName, existingConstructor, constructor, basePrototype,
|
38
|
+
// proxiedPrototype allows the provided prototype to remain unmodified
|
39
|
+
// so that it can be used as a mixin for multiple widgets (#8876)
|
40
|
+
proxiedPrototype = {},
|
41
|
+
namespace = name.split(".")[ 0 ];
|
42
|
+
|
43
|
+
name = name.split(".")[ 1 ];
|
44
|
+
fullName = namespace + "-" + name;
|
45
|
+
|
46
|
+
if (!prototype) {
|
47
|
+
prototype = base;
|
48
|
+
base = $.Widget;
|
49
|
+
}
|
50
|
+
|
51
|
+
// create selector for plugin
|
52
|
+
$.expr[ ":" ][ fullName.toLowerCase() ] = function (elem) {
|
53
|
+
return !!$.data(elem, fullName);
|
54
|
+
};
|
55
|
+
|
56
|
+
$[ namespace ] = $[ namespace ] || {};
|
57
|
+
existingConstructor = $[ namespace ][ name ];
|
58
|
+
constructor = $[ namespace ][ name ] = function (options, element) {
|
59
|
+
// allow instantiation without "new" keyword
|
60
|
+
if (!this._createWidget) {
|
61
|
+
return new constructor(options, element);
|
62
|
+
}
|
63
|
+
|
64
|
+
// allow instantiation without initializing for simple inheritance
|
65
|
+
// must use "new" keyword (the code above always passes args)
|
66
|
+
if (arguments.length) {
|
67
|
+
this._createWidget(options, element);
|
68
|
+
}
|
69
|
+
};
|
70
|
+
// extend with the existing constructor to carry over any static properties
|
71
|
+
$.extend(constructor, existingConstructor, {
|
72
|
+
version: prototype.version,
|
73
|
+
// copy the object used to create the prototype in case we need to
|
74
|
+
// redefine the widget later
|
75
|
+
_proto: $.extend({}, prototype),
|
76
|
+
// track widgets that inherit from this widget in case this widget is
|
77
|
+
// redefined after a widget inherits from it
|
78
|
+
_childConstructors: []
|
79
|
+
});
|
80
|
+
|
81
|
+
basePrototype = new base();
|
82
|
+
// we need to make the options hash a property directly on the new instance
|
83
|
+
// otherwise we'll modify the options hash on the prototype that we're
|
84
|
+
// inheriting from
|
85
|
+
basePrototype.options = $.widget.extend({}, basePrototype.options);
|
86
|
+
$.each(prototype, function (prop, value) {
|
87
|
+
if (!$.isFunction(value)) {
|
88
|
+
proxiedPrototype[ prop ] = value;
|
89
|
+
return;
|
90
|
+
}
|
91
|
+
proxiedPrototype[ prop ] = (function () {
|
92
|
+
var _super = function () {
|
93
|
+
return base.prototype[ prop ].apply(this, arguments);
|
94
|
+
},
|
95
|
+
_superApply = function (args) {
|
96
|
+
return base.prototype[ prop ].apply(this, args);
|
97
|
+
};
|
98
|
+
return function () {
|
99
|
+
var __super = this._super,
|
100
|
+
__superApply = this._superApply,
|
101
|
+
returnValue;
|
102
|
+
|
103
|
+
this._super = _super;
|
104
|
+
this._superApply = _superApply;
|
105
|
+
|
106
|
+
returnValue = value.apply(this, arguments);
|
107
|
+
|
108
|
+
this._super = __super;
|
109
|
+
this._superApply = __superApply;
|
110
|
+
|
111
|
+
return returnValue;
|
112
|
+
};
|
113
|
+
})();
|
114
|
+
});
|
115
|
+
constructor.prototype = $.widget.extend(basePrototype, {
|
116
|
+
// TODO: remove support for widgetEventPrefix
|
117
|
+
// always use the name + a colon as the prefix, e.g., draggable:start
|
118
|
+
// don't prefix for widgets that aren't DOM-based
|
119
|
+
widgetEventPrefix: existingConstructor ? basePrototype.widgetEventPrefix : name
|
120
|
+
}, proxiedPrototype, {
|
121
|
+
constructor: constructor,
|
122
|
+
namespace: namespace,
|
123
|
+
widgetName: name,
|
124
|
+
widgetFullName: fullName
|
125
|
+
});
|
126
|
+
|
127
|
+
// If this widget is being redefined then we need to find all widgets that
|
128
|
+
// are inheriting from it and redefine all of them so that they inherit from
|
129
|
+
// the new version of this widget. We're essentially trying to replace one
|
130
|
+
// level in the prototype chain.
|
131
|
+
if (existingConstructor) {
|
132
|
+
$.each(existingConstructor._childConstructors, function (i, child) {
|
133
|
+
var childPrototype = child.prototype;
|
134
|
+
|
135
|
+
// redefine the child widget using the same prototype that was
|
136
|
+
// originally used, but inherit from the new version of the base
|
137
|
+
$.widget(childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto);
|
138
|
+
});
|
139
|
+
// remove the list of existing child constructors from the old constructor
|
140
|
+
// so the old child constructors can be garbage collected
|
141
|
+
delete existingConstructor._childConstructors;
|
142
|
+
} else {
|
143
|
+
base._childConstructors.push(constructor);
|
144
|
+
}
|
145
|
+
|
146
|
+
$.widget.bridge(name, constructor);
|
147
|
+
};
|
148
|
+
|
149
|
+
$.widget.extend = function (target) {
|
150
|
+
var input = slice.call(arguments, 1),
|
151
|
+
inputIndex = 0,
|
152
|
+
inputLength = input.length,
|
153
|
+
key,
|
154
|
+
value;
|
155
|
+
for (; inputIndex < inputLength; inputIndex++) {
|
156
|
+
for (key in input[ inputIndex ]) {
|
157
|
+
value = input[ inputIndex ][ key ];
|
158
|
+
if (input[ inputIndex ].hasOwnProperty(key) && value !== undefined) {
|
159
|
+
// Clone objects
|
160
|
+
if ($.isPlainObject(value)) {
|
161
|
+
target[ key ] = $.isPlainObject(target[ key ]) ?
|
162
|
+
$.widget.extend({}, target[ key ], value) :
|
163
|
+
// Don't extend strings, arrays, etc. with objects
|
164
|
+
$.widget.extend({}, value);
|
165
|
+
// Copy everything else by reference
|
166
|
+
} else {
|
167
|
+
target[ key ] = value;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
return target;
|
173
|
+
};
|
174
|
+
|
175
|
+
$.widget.bridge = function (name, object) {
|
176
|
+
var fullName = object.prototype.widgetFullName || name;
|
177
|
+
$.fn[ name ] = function (options) {
|
178
|
+
var isMethodCall = typeof options === "string",
|
179
|
+
args = slice.call(arguments, 1),
|
180
|
+
returnValue = this;
|
181
|
+
|
182
|
+
// allow multiple hashes to be passed on init
|
183
|
+
options = !isMethodCall && args.length ?
|
184
|
+
$.widget.extend.apply(null, [ options ].concat(args)) :
|
185
|
+
options;
|
186
|
+
|
187
|
+
if (isMethodCall) {
|
188
|
+
this.each(function () {
|
189
|
+
var methodValue,
|
190
|
+
instance = $.data(this, fullName);
|
191
|
+
if (!instance) {
|
192
|
+
return $.error("cannot call methods on " + name + " prior to initialization; " +
|
193
|
+
"attempted to call method '" + options + "'");
|
194
|
+
}
|
195
|
+
if (!$.isFunction(instance[options]) || options.charAt(0) === "_") {
|
196
|
+
return $.error("no such method '" + options + "' for " + name + " widget instance");
|
197
|
+
}
|
198
|
+
methodValue = instance[ options ].apply(instance, args);
|
199
|
+
if (methodValue !== instance && methodValue !== undefined) {
|
200
|
+
returnValue = methodValue && methodValue.jquery ?
|
201
|
+
returnValue.pushStack(methodValue.get()) :
|
202
|
+
methodValue;
|
203
|
+
return false;
|
204
|
+
}
|
205
|
+
});
|
206
|
+
} else {
|
207
|
+
this.each(function () {
|
208
|
+
var instance = $.data(this, fullName);
|
209
|
+
if (instance) {
|
210
|
+
instance.option(options || {})._init();
|
211
|
+
} else {
|
212
|
+
$.data(this, fullName, new object(options, this));
|
213
|
+
}
|
214
|
+
});
|
215
|
+
}
|
216
|
+
|
217
|
+
return returnValue;
|
218
|
+
};
|
219
|
+
};
|
220
|
+
|
221
|
+
$.Widget = function (/* options, element */) {
|
222
|
+
};
|
223
|
+
$.Widget._childConstructors = [];
|
224
|
+
|
225
|
+
$.Widget.prototype = {
|
226
|
+
widgetName: "widget",
|
227
|
+
widgetEventPrefix: "",
|
228
|
+
defaultElement: "<div>",
|
229
|
+
options: {
|
230
|
+
disabled: false,
|
231
|
+
|
232
|
+
// callbacks
|
233
|
+
create: null
|
234
|
+
},
|
235
|
+
_createWidget: function (options, element) {
|
236
|
+
element = $(element || this.defaultElement || this)[ 0 ];
|
237
|
+
this.element = $(element);
|
238
|
+
this.uuid = uuid++;
|
239
|
+
this.eventNamespace = "." + this.widgetName + this.uuid;
|
240
|
+
this.options = $.widget.extend({},
|
241
|
+
this.options,
|
242
|
+
this._getCreateOptions(),
|
243
|
+
options);
|
244
|
+
|
245
|
+
this.bindings = $();
|
246
|
+
this.hoverable = $();
|
247
|
+
this.focusable = $();
|
248
|
+
|
249
|
+
if (element !== this) {
|
250
|
+
$.data(element, this.widgetFullName, this);
|
251
|
+
this._on(true, this.element, {
|
252
|
+
remove: function (event) {
|
253
|
+
if (event.target === element) {
|
254
|
+
this.destroy();
|
255
|
+
}
|
256
|
+
}
|
257
|
+
});
|
258
|
+
this.document = $(element.style ?
|
259
|
+
// element within the document
|
260
|
+
element.ownerDocument :
|
261
|
+
// element is window or document
|
262
|
+
element.document || element);
|
263
|
+
this.window = $(this.document[0].defaultView || this.document[0].parentWindow);
|
264
|
+
}
|
265
|
+
|
266
|
+
this._create();
|
267
|
+
this._trigger("create", null, this._getCreateEventData());
|
268
|
+
this._init();
|
269
|
+
},
|
270
|
+
_getCreateOptions: $.noop,
|
271
|
+
_getCreateEventData: $.noop,
|
272
|
+
_create: $.noop,
|
273
|
+
_init: $.noop,
|
274
|
+
|
275
|
+
destroy: function () {
|
276
|
+
this._destroy();
|
277
|
+
// we can probably remove the unbind calls in 2.0
|
278
|
+
// all event bindings should go through this._on()
|
279
|
+
this.element
|
280
|
+
.unbind(this.eventNamespace)
|
281
|
+
// 1.9 BC for #7810
|
282
|
+
// TODO remove dual storage
|
283
|
+
.removeData(this.widgetName)
|
284
|
+
.removeData(this.widgetFullName)
|
285
|
+
// support: jquery <1.6.3
|
286
|
+
// http://bugs.jquery.com/ticket/9413
|
287
|
+
.removeData($.camelCase(this.widgetFullName));
|
288
|
+
this.widget()
|
289
|
+
.unbind(this.eventNamespace)
|
290
|
+
.removeAttr("aria-disabled")
|
291
|
+
.removeClass(
|
292
|
+
this.widgetFullName + "-disabled " +
|
293
|
+
"ui-state-disabled");
|
294
|
+
|
295
|
+
// clean up events and states
|
296
|
+
this.bindings.unbind(this.eventNamespace);
|
297
|
+
this.hoverable.removeClass("ui-state-hover");
|
298
|
+
this.focusable.removeClass("ui-state-focus");
|
299
|
+
},
|
300
|
+
_destroy: $.noop,
|
301
|
+
|
302
|
+
widget: function () {
|
303
|
+
return this.element;
|
304
|
+
},
|
305
|
+
|
306
|
+
option: function (key, value) {
|
307
|
+
var options = key,
|
308
|
+
parts,
|
309
|
+
curOption,
|
310
|
+
i;
|
311
|
+
|
312
|
+
if (arguments.length === 0) {
|
313
|
+
// don't return a reference to the internal hash
|
314
|
+
return $.widget.extend({}, this.options);
|
315
|
+
}
|
316
|
+
|
317
|
+
if (typeof key === "string") {
|
318
|
+
// handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
|
319
|
+
options = {};
|
320
|
+
parts = key.split(".");
|
321
|
+
key = parts.shift();
|
322
|
+
if (parts.length) {
|
323
|
+
curOption = options[ key ] = $.widget.extend({}, this.options[ key ]);
|
324
|
+
for (i = 0; i < parts.length - 1; i++) {
|
325
|
+
curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
|
326
|
+
curOption = curOption[ parts[ i ] ];
|
327
|
+
}
|
328
|
+
key = parts.pop();
|
329
|
+
if (value === undefined) {
|
330
|
+
return curOption[ key ] === undefined ? null : curOption[ key ];
|
331
|
+
}
|
332
|
+
curOption[ key ] = value;
|
333
|
+
} else {
|
334
|
+
if (value === undefined) {
|
335
|
+
return this.options[ key ] === undefined ? null : this.options[ key ];
|
336
|
+
}
|
337
|
+
options[ key ] = value;
|
338
|
+
}
|
339
|
+
}
|
340
|
+
|
341
|
+
this._setOptions(options);
|
342
|
+
|
343
|
+
return this;
|
344
|
+
},
|
345
|
+
_setOptions: function (options) {
|
346
|
+
var key;
|
347
|
+
|
348
|
+
for (key in options) {
|
349
|
+
this._setOption(key, options[ key ]);
|
350
|
+
}
|
351
|
+
|
352
|
+
return this;
|
353
|
+
},
|
354
|
+
_setOption: function (key, value) {
|
355
|
+
this.options[ key ] = value;
|
356
|
+
|
357
|
+
if (key === "disabled") {
|
358
|
+
this.widget()
|
359
|
+
.toggleClass(this.widgetFullName + "-disabled ui-state-disabled", !!value)
|
360
|
+
.attr("aria-disabled", value);
|
361
|
+
this.hoverable.removeClass("ui-state-hover");
|
362
|
+
this.focusable.removeClass("ui-state-focus");
|
363
|
+
}
|
364
|
+
|
365
|
+
return this;
|
366
|
+
},
|
367
|
+
|
368
|
+
enable: function () {
|
369
|
+
return this._setOption("disabled", false);
|
370
|
+
},
|
371
|
+
disable: function () {
|
372
|
+
return this._setOption("disabled", true);
|
373
|
+
},
|
374
|
+
|
375
|
+
_on: function (suppressDisabledCheck, element, handlers) {
|
376
|
+
var delegateElement,
|
377
|
+
instance = this;
|
378
|
+
|
379
|
+
// no suppressDisabledCheck flag, shuffle arguments
|
380
|
+
if (typeof suppressDisabledCheck !== "boolean") {
|
381
|
+
handlers = element;
|
382
|
+
element = suppressDisabledCheck;
|
383
|
+
suppressDisabledCheck = false;
|
384
|
+
}
|
385
|
+
|
386
|
+
// no element argument, shuffle and use this.element
|
387
|
+
if (!handlers) {
|
388
|
+
handlers = element;
|
389
|
+
element = this.element;
|
390
|
+
delegateElement = this.widget();
|
391
|
+
} else {
|
392
|
+
// accept selectors, DOM elements
|
393
|
+
element = delegateElement = $(element);
|
394
|
+
this.bindings = this.bindings.add(element);
|
395
|
+
}
|
396
|
+
|
397
|
+
$.each(handlers, function (event, handler) {
|
398
|
+
function handlerProxy() {
|
399
|
+
// allow widgets to customize the disabled handling
|
400
|
+
// - disabled as an array instead of boolean
|
401
|
+
// - disabled class as method for disabling individual parts
|
402
|
+
if (!suppressDisabledCheck &&
|
403
|
+
( instance.options.disabled === true ||
|
404
|
+
$(this).hasClass("ui-state-disabled") )) {
|
405
|
+
return;
|
406
|
+
}
|
407
|
+
return ( typeof handler === "string" ? instance[ handler ] : handler )
|
408
|
+
.apply(instance, arguments);
|
409
|
+
}
|
410
|
+
|
411
|
+
// copy the guid so direct unbinding works
|
412
|
+
if (typeof handler !== "string") {
|
413
|
+
handlerProxy.guid = handler.guid =
|
414
|
+
handler.guid || handlerProxy.guid || $.guid++;
|
415
|
+
}
|
416
|
+
|
417
|
+
var match = event.match(/^(\w+)\s*(.*)$/),
|
418
|
+
eventName = match[1] + instance.eventNamespace,
|
419
|
+
selector = match[2];
|
420
|
+
if (selector) {
|
421
|
+
delegateElement.delegate(selector, eventName, handlerProxy);
|
422
|
+
} else {
|
423
|
+
element.bind(eventName, handlerProxy);
|
424
|
+
}
|
425
|
+
});
|
426
|
+
},
|
427
|
+
|
428
|
+
_off: function (element, eventName) {
|
429
|
+
eventName = (eventName || "").split(" ").join(this.eventNamespace + " ") + this.eventNamespace;
|
430
|
+
element.unbind(eventName).undelegate(eventName);
|
431
|
+
},
|
432
|
+
|
433
|
+
_delay: function (handler, delay) {
|
434
|
+
function handlerProxy() {
|
435
|
+
return ( typeof handler === "string" ? instance[ handler ] : handler )
|
436
|
+
.apply(instance, arguments);
|
437
|
+
}
|
438
|
+
|
439
|
+
var instance = this;
|
440
|
+
return setTimeout(handlerProxy, delay || 0);
|
441
|
+
},
|
442
|
+
|
443
|
+
_hoverable: function (element) {
|
444
|
+
this.hoverable = this.hoverable.add(element);
|
445
|
+
this._on(element, {
|
446
|
+
mouseenter: function (event) {
|
447
|
+
$(event.currentTarget).addClass("ui-state-hover");
|
448
|
+
},
|
449
|
+
mouseleave: function (event) {
|
450
|
+
$(event.currentTarget).removeClass("ui-state-hover");
|
451
|
+
}
|
452
|
+
});
|
453
|
+
},
|
454
|
+
|
455
|
+
_focusable: function (element) {
|
456
|
+
this.focusable = this.focusable.add(element);
|
457
|
+
this._on(element, {
|
458
|
+
focusin: function (event) {
|
459
|
+
$(event.currentTarget).addClass("ui-state-focus");
|
460
|
+
},
|
461
|
+
focusout: function (event) {
|
462
|
+
$(event.currentTarget).removeClass("ui-state-focus");
|
463
|
+
}
|
464
|
+
});
|
465
|
+
},
|
466
|
+
|
467
|
+
_trigger: function (type, event, data) {
|
468
|
+
var prop, orig,
|
469
|
+
callback = this.options[ type ];
|
470
|
+
|
471
|
+
data = data || {};
|
472
|
+
event = $.Event(event);
|
473
|
+
event.type = ( type === this.widgetEventPrefix ?
|
474
|
+
type :
|
475
|
+
this.widgetEventPrefix + type ).toLowerCase();
|
476
|
+
// the original event may come from any element
|
477
|
+
// so we need to reset the target on the new event
|
478
|
+
event.target = this.element[ 0 ];
|
479
|
+
|
480
|
+
// copy original event properties over to the new event
|
481
|
+
orig = event.originalEvent;
|
482
|
+
if (orig) {
|
483
|
+
for (prop in orig) {
|
484
|
+
if (!( prop in event )) {
|
485
|
+
event[ prop ] = orig[ prop ];
|
486
|
+
}
|
487
|
+
}
|
488
|
+
}
|
489
|
+
|
490
|
+
this.element.trigger(event, data);
|
491
|
+
return !( $.isFunction(callback) &&
|
492
|
+
callback.apply(this.element[0], [ event ].concat(data)) === false ||
|
493
|
+
event.isDefaultPrevented() );
|
494
|
+
}
|
495
|
+
};
|
496
|
+
|
497
|
+
$.each({ show: "fadeIn", hide: "fadeOut" }, function (method, defaultEffect) {
|
498
|
+
$.Widget.prototype[ "_" + method ] = function (element, options, callback) {
|
499
|
+
if (typeof options === "string") {
|
500
|
+
options = { effect: options };
|
501
|
+
}
|
502
|
+
var hasOptions,
|
503
|
+
effectName = !options ?
|
504
|
+
method :
|
505
|
+
options === true || typeof options === "number" ?
|
506
|
+
defaultEffect :
|
507
|
+
options.effect || defaultEffect;
|
508
|
+
options = options || {};
|
509
|
+
if (typeof options === "number") {
|
510
|
+
options = { duration: options };
|
511
|
+
}
|
512
|
+
hasOptions = !$.isEmptyObject(options);
|
513
|
+
options.complete = callback;
|
514
|
+
if (options.delay) {
|
515
|
+
element.delay(options.delay);
|
516
|
+
}
|
517
|
+
if (hasOptions && $.effects && $.effects.effect[ effectName ]) {
|
518
|
+
element[ method ](options);
|
519
|
+
} else if (effectName !== method && element[ effectName ]) {
|
520
|
+
element[ effectName ](options.duration, options.easing, callback);
|
521
|
+
} else {
|
522
|
+
element.queue(function (next) {
|
523
|
+
$(this)[ method ]();
|
524
|
+
if (callback) {
|
525
|
+
callback.call(element[ 0 ]);
|
526
|
+
}
|
527
|
+
next();
|
528
|
+
});
|
529
|
+
}
|
530
|
+
};
|
531
|
+
});
|
532
|
+
|
533
|
+
}));
|