PluginProbe
Wp-Insert / 1.7
Wp-Insert v1.7
trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.3.0 1.3.1 1.3.3 1.4 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 2.0 All 63 releases
wp-insert / js / jquery / ui.core.js

ui.core.js in Wp-Insert 1.7, at js/jquery/ui.core.js

296 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*
2 * jQuery UI @VERSION
3 *
4 * Copyright (c) 2008 Paul Bakaus (ui.jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
7 *
8 * http://docs.jquery.com/UI
9 */
10 ;(function($) {
11
12 $.ui = {
13 plugin: {
14 add: function(module, option, set) {
15 var proto = $.ui[module].prototype;
16 for(var i in set) {
17 proto.plugins[i] = proto.plugins[i] || [];
18 proto.plugins[i].push([option, set[i]]);
19 }
20 },
21 call: function(instance, name, args) {
22 var set = instance.plugins[name];
23 if(!set) { return; }
24
25 for (var i = 0; i < set.length; i++) {
26 if (instance.options[set[i][0]]) {
27 set[i][1].apply(instance.element, args);
28 }
29 }
30 }
31 },
32 cssCache: {},
33 css: function(name) {
34 if ($.ui.cssCache[name]) { return $.ui.cssCache[name]; }
35 var tmp = $('<div class="ui-gen">').addClass(name).css({position:'absolute', top:'-5000px', left:'-5000px', display:'block'}).appendTo('body');
36
37 //if (!$.browser.safari)
38 //tmp.appendTo('body');
39
40 //Opera and Safari set width and height to 0px instead of auto
41 //Safari returns rgba(0,0,0,0) when bgcolor is not set
42 $.ui.cssCache[name] = !!(
43 (!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) ||
44 !(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor')))
45 );
46 try { $('body').get(0).removeChild(tmp.get(0)); } catch(e){}
47 return $.ui.cssCache[name];
48 },
49 disableSelection: function(e) {
50 e.unselectable = "on";
51 e.onselectstart = function() { return false; };
52 if (e.style) { e.style.MozUserSelect = "none"; }
53 },
54 enableSelection: function(e) {
55 e.unselectable = "off";
56 e.onselectstart = function() { return true; };
57 if (e.style) { e.style.MozUserSelect = ""; }
58 },
59 hasScroll: function(e, a) {
60 var scroll = /top/.test(a||"top") ? 'scrollTop' : 'scrollLeft', has = false;
61 if (e[scroll] > 0) return true; e[scroll] = 1;
62 has = e[scroll] > 0 ? true : false; e[scroll] = 0;
63 return has;
64 }
65 };
66
67
68 /** jQuery core modifications and additions **/
69
70 var _remove = $.fn.remove;
71 $.fn.remove = function() {
72 $("*", this).add(this).trigger("remove");
73 return _remove.apply(this, arguments );
74 };
75
76 // $.widget is a factory to create jQuery plugins
77 // taking some boilerplate code out of the plugin code
78 // created by Scott González and Jörn Zaefferer
79 function getter(namespace, plugin, method) {
80 var methods = $[namespace][plugin].getter || [];
81 methods = (typeof methods == "string" ? methods.split(/,?\s+/) : methods);
82 return ($.inArray(method, methods) != -1);
83 }
84
85 $.widget = function(name, prototype) {
86 var namespace = name.split(".")[0];
87 name = name.split(".")[1];
88
89 // create plugin method
90 $.fn[name] = function(options) {
91 var isMethodCall = (typeof options == 'string'),
92 args = Array.prototype.slice.call(arguments, 1);
93
94 if (isMethodCall && getter(namespace, name, options)) {
95 var instance = $.data(this[0], name);
96 return (instance ? instance[options].apply(instance, args)
97 : undefined);
98 }
99
100 return this.each(function() {
101 var instance = $.data(this, name);
102 if (isMethodCall && instance && $.isFunction(instance[options])) {
103 instance[options].apply(instance, args);
104 } else if (!isMethodCall) {
105 $.data(this, name, new $[namespace][name](this, options));
106 }
107 });
108 };
109
110 // create widget constructor
111 $[namespace][name] = function(element, options) {
112 var self = this;
113
114 this.widgetName = name;
115 this.widgetBaseClass = namespace + '-' + name;
116
117 this.options = $.extend({}, $.widget.defaults, $[namespace][name].defaults, options);
118 this.element = $(element)
119 .bind('setData.' + name, function(e, key, value) {
120 return self.setData(key, value);
121 })
122 .bind('getData.' + name, function(e, key) {
123 return self.getData(key);
124 })
125 .bind('remove', function() {
126 return self.destroy();
127 });
128 this.init();
129 };
130
131 // add widget prototype
132 $[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
133 };
134
135 $.widget.prototype = {
136 init: function() {},
137 destroy: function() {
138 this.element.removeData(this.widgetName);
139 },
140
141 getData: function(key) {
142 return this.options[key];
143 },
144 setData: function(key, value) {
145 this.options[key] = value;
146
147 if (key == 'disabled') {
148 this.element[value ? 'addClass' : 'removeClass'](
149 this.widgetBaseClass + '-disabled');
150 }
151 },
152
153 enable: function() {
154 this.setData('disabled', false);
155 },
156 disable: function() {
157 this.setData('disabled', true);
158 }
159 };
160
161 $.widget.defaults = {
162 disabled: false
163 };
164
165
166 /** Mouse Interaction Plugin **/
167
168 $.ui.mouse = {
169 mouseInit: function() {
170 var self = this;
171
172 this.element.bind('mousedown.'+this.widgetName, function(e) {
173 return self.mouseDown(e);
174 });
175
176 // Prevent text selection in IE
177 if ($.browser.msie) {
178 this._mouseUnselectable = this.element.attr('unselectable');
179 this.element.attr('unselectable', 'on');
180 }
181
182 this.started = false;
183 },
184
185 // TODO: make sure destroying one instance of mouse doesn't mess with
186 // other instances of mouse
187 mouseDestroy: function() {
188 this.element.unbind('.'+this.widgetName);
189
190 // Restore text selection in IE
191 ($.browser.msie
192 && this.element.attr('unselectable', this._mouseUnselectable));
193 },
194
195 mouseDown: function(e) {
196 // we may have missed mouseup (out of window)
197 (this._mouseStarted && this.mouseUp(e));
198
199 this._mouseDownEvent = e;
200
201 var self = this,
202 btnIsLeft = (e.which == 1),
203 elIsCancel = (typeof this.options.cancel == "string" ? $(e.target).is(this.options.cancel) : false);
204 if (!btnIsLeft || elIsCancel || !this.mouseCapture(e)) {
205 return true;
206 }
207
208 this._mouseDelayMet = !this.options.delay;
209 if (!this._mouseDelayMet) {
210 this._mouseDelayTimer = setTimeout(function() {
211 self._mouseDelayMet = true;
212 }, this.options.delay);
213 }
214
215 if (this.mouseDistanceMet(e) && this.mouseDelayMet(e)) {
216 this._mouseStarted = (this.mouseStart(e) !== false);
217 if (!this._mouseStarted) {
218 e.preventDefault();
219 return true;
220 }
221 }
222
223 // these delegates are required to keep context
224 this._mouseMoveDelegate = function(e) {
225 return self.mouseMove(e);
226 };
227 this._mouseUpDelegate = function(e) {
228 return self.mouseUp(e);
229 };
230 $(document)
231 .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
232 .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
233
234 return false;
235 },
236
237 mouseMove: function(e) {
238 // IE mouseup check - mouseup happened when mouse was out of window
239 if ($.browser.msie && !e.button) {
240 return this.mouseUp(e);
241 }
242
243 if (this._mouseStarted) {
244 this.mouseDrag(e);
245 return false;
246 }
247
248 if (this.mouseDistanceMet(e) && this.mouseDelayMet(e)) {
249 this._mouseStarted =
250 (this.mouseStart(this._mouseDownEvent, e) !== false);
251 (this._mouseStarted ? this.mouseDrag(e) : this.mouseUp(e));
252 }
253
254 return !this._mouseStarted;
255 },
256
257 mouseUp: function(e) {
258 $(document)
259 .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
260 .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
261
262 if (this._mouseStarted) {
263 this._mouseStarted = false;
264 this.mouseStop(e);
265 }
266
267 return false;
268 },
269
270 mouseDistanceMet: function(e) {
271 return (Math.max(
272 Math.abs(this._mouseDownEvent.pageX - e.pageX),
273 Math.abs(this._mouseDownEvent.pageY - e.pageY)
274 ) >= this.options.distance
275 );
276 },
277
278 mouseDelayMet: function(e) {
279 return this._mouseDelayMet;
280 },
281
282 // These are placeholder methods, to be overriden by extending plugin
283 mouseStart: function(e) {},
284 mouseDrag: function(e) {},
285 mouseStop: function(e) {},
286 mouseCapture: function(e) { return true; }
287 };
288
289 $.ui.mouse.defaults = {
290 cancel: null,
291 distance: 1,
292 delay: 0
293 };
294
295 })(jQuery);
296