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.
8
* http://docs.jquery.com/UI
12
/** jQuery core modifications and additions **/
14
var _remove = $.fn.remove;
15
$.fn.remove = function() {
16
$("*", this).add(this).triggerHandler("remove");
17
return _remove.apply(this, arguments );
20
function isVisible(element) {
21
function checkStyles(element) {
22
var style = element.style;
23
return (style.display != 'none' && style.visibility != 'hidden');
26
var visible = checkStyles(element);
28
(visible && $.each($.dir(element, 'parentNode'), function() {
29
return (visible = checkStyles(this));
35
$.extend($.expr[':'], {
36
data: function(a, i, m) {
37
return $.data(a, m[3]);
40
// TODO: add support for object, area
41
tabbable: function(a, i, m) {
42
var nodeName = a.nodeName.toLowerCase();
48
( // filter node types that participate in the tab order
51
('a' == nodeName && a.href) ||
53
// enabled form element
54
(/input|select|textarea|button/.test(nodeName) &&
55
'hidden' != a.type && !a.disabled)
93
// $.widget is a factory to create jQuery plugins
94
// taking some boilerplate code out of the plugin code
95
// created by Scott González and Jörn Zaefferer
96
function getter(namespace, plugin, method, args) {
97
function getMethods(type) {
98
var methods = $[namespace][plugin][type] || [];
99
return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
102
var methods = getMethods('getter');
103
if (args.length == 1 && typeof args[0] == 'string') {
104
methods = methods.concat(getMethods('getterSetter'));
106
return ($.inArray(method, methods) != -1);
109
$.widget = function(name, prototype) {
110
var namespace = name.split(".")[0];
111
name = name.split(".")[1];
113
// create plugin method
114
$.fn[name] = function(options) {
115
var isMethodCall = (typeof options == 'string'),
116
args = Array.prototype.slice.call(arguments, 1);
118
// prevent calls to internal methods
119
if (isMethodCall && options.substring(0, 1) == '_') {
123
// handle getter methods
124
if (isMethodCall && getter(namespace, name, options, args)) {
125
var instance = $.data(this[0], name);
126
return (instance ? instance[options].apply(instance, args)
130
// handle initialization and non-getter methods
131
return this.each(function() {
132
var instance = $.data(this, name);
135
(!instance && !isMethodCall &&
136
$.data(this, name, new $[namespace][name](this, options)));
139
(instance && isMethodCall && $.isFunction(instance[options]) &&
140
instance[options].apply(instance, args));
144
// create widget constructor
145
$[namespace][name] = function(element, options) {
148
this.widgetName = name;
149
this.widgetEventPrefix = $[namespace][name].eventPrefix || name;
150
this.widgetBaseClass = namespace + '-' + name;
152
this.options = $.extend({},
154
$[namespace][name].defaults,
155
$.metadata && $.metadata.get(element)[name],
158
this.element = $(element)
159
.bind('setData.' + name, function(e, key, value) {
160
return self._setData(key, value);
162
.bind('getData.' + name, function(e, key) {
163
return self._getData(key);
165
.bind('remove', function() {
166
return self.destroy();
172
// add widget prototype
173
$[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
175
// TODO: merge getter and getterSetter properties from widget prototype
176
// and plugin prototype
177
$[namespace][name].getterSetter = 'option';
180
$.widget.prototype = {
181
_init: function() {},
182
destroy: function() {
183
this.element.removeData(this.widgetName);
186
option: function(key, value) {
190
if (typeof key == "string") {
191
if (value === undefined) {
192
return this._getData(key);
195
options[key] = value;
198
$.each(options, function(key, value) {
199
self._setData(key, value);
202
_getData: function(key) {
203
return this.options[key];
205
_setData: function(key, value) {
206
this.options[key] = value;
208
if (key == 'disabled') {
209
this.element[value ? 'addClass' : 'removeClass'](
210
this.widgetBaseClass + '-disabled');
215
this._setData('disabled', false);
217
disable: function() {
218
this._setData('disabled', true);
221
_trigger: function(type, e, data) {
222
var eventName = (type == this.widgetEventPrefix
223
? type : this.widgetEventPrefix + type);
224
e = e || $.event.fix({ type: eventName, target: this.element[0] });
225
return this.element.triggerHandler(eventName, [e, data], this.options[type]);
229
$.widget.defaults = {
234
/** jQuery UI core **/
238
add: function(module, option, set) {
239
var proto = $.ui[module].prototype;
241
proto.plugins[i] = proto.plugins[i] || [];
242
proto.plugins[i].push([option, set[i]]);
245
call: function(instance, name, args) {
246
var set = instance.plugins[name];
249
for (var i = 0; i < set.length; i++) {
250
if (instance.options[set[i][0]]) {
251
set[i][1].apply(instance.element, args);
257
css: function(name) {
258
if ($.ui.cssCache[name]) { return $.ui.cssCache[name]; }
259
var tmp = $('<div class="ui-gen">').addClass(name).css({position:'absolute', top:'-5000px', left:'-5000px', display:'block'}).appendTo('body');
261
//if (!$.browser.safari)
262
//tmp.appendTo('body');
264
//Opera and Safari set width and height to 0px instead of auto
265
//Safari returns rgba(0,0,0,0) when bgcolor is not set
266
$.ui.cssCache[name] = !!(
267
(!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) ||
268
!(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor')))
270
try { $('body').get(0).removeChild(tmp.get(0)); } catch(e){}
271
return $.ui.cssCache[name];
273
disableSelection: function(el) {
275
.attr('unselectable', 'on')
276
.css('MozUserSelect', 'none')
277
.bind('selectstart.ui', function() { return false; });
279
enableSelection: function(el) {
281
.attr('unselectable', 'off')
282
.css('MozUserSelect', '')
283
.unbind('selectstart.ui');
285
hasScroll: function(e, a) {
287
//If overflow is hidden, the element might have extra content, but the user wants to hide it
288
if ($(e).css('overflow') == 'hidden') { return false; }
290
var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop',
293
if (e[scroll] > 0) { return true; }
295
// TODO: determine which cases actually cause this to happen
296
// if the element doesn't have the scroll set, see if it's possible to
299
has = (e[scroll] > 0);
306
/** Mouse Interaction Plugin **/
309
_mouseInit: function() {
312
this.element.bind('mousedown.'+this.widgetName, function(e) {
313
return self._mouseDown(e);
316
// Prevent text selection in IE
317
if ($.browser.msie) {
318
this._mouseUnselectable = this.element.attr('unselectable');
319
this.element.attr('unselectable', 'on');
322
this.started = false;
325
// TODO: make sure destroying one instance of mouse doesn't mess with
326
// other instances of mouse
327
_mouseDestroy: function() {
328
this.element.unbind('.'+this.widgetName);
330
// Restore text selection in IE
332
&& this.element.attr('unselectable', this._mouseUnselectable));
335
_mouseDown: function(e) {
336
// we may have missed mouseup (out of window)
337
(this._mouseStarted && this._mouseUp(e));
339
this._mouseDownEvent = e;
342
btnIsLeft = (e.which == 1),
343
elIsCancel = (typeof this.options.cancel == "string" ? $(e.target).parents().add(e.target).filter(this.options.cancel).length : false);
344
if (!btnIsLeft || elIsCancel || !this._mouseCapture(e)) {
348
this.mouseDelayMet = !this.options.delay;
349
if (!this.mouseDelayMet) {
350
this._mouseDelayTimer = setTimeout(function() {
351
self.mouseDelayMet = true;
352
}, this.options.delay);
355
if (this._mouseDistanceMet(e) && this._mouseDelayMet(e)) {
356
this._mouseStarted = (this._mouseStart(e) !== false);
357
if (!this._mouseStarted) {
363
// these delegates are required to keep context
364
this._mouseMoveDelegate = function(e) {
365
return self._mouseMove(e);
367
this._mouseUpDelegate = function(e) {
368
return self._mouseUp(e);
371
.bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
372
.bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
377
_mouseMove: function(e) {
378
// IE mouseup check - mouseup happened when mouse was out of window
379
if ($.browser.msie && !e.button) {
380
return this._mouseUp(e);
383
if (this._mouseStarted) {
388
if (this._mouseDistanceMet(e) && this._mouseDelayMet(e)) {
390
(this._mouseStart(this._mouseDownEvent, e) !== false);
391
(this._mouseStarted ? this._mouseDrag(e) : this._mouseUp(e));
394
return !this._mouseStarted;
397
_mouseUp: function(e) {
399
.unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
400
.unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
402
if (this._mouseStarted) {
403
this._mouseStarted = false;
410
_mouseDistanceMet: function(e) {
412
Math.abs(this._mouseDownEvent.pageX - e.pageX),
413
Math.abs(this._mouseDownEvent.pageY - e.pageY)
414
) >= this.options.distance
418
_mouseDelayMet: function(e) {
419
return this.mouseDelayMet;
422
// These are placeholder methods, to be overriden by extending plugin
423
_mouseStart: function(e) {},
424
_mouseDrag: function(e) {},
425
_mouseStop: function(e) {},
426
_mouseCapture: function(e) { return true; }
429
$.ui.mouse.defaults = {