topical media & game development
lib-present-jquery-desktop-basic-steps-lib-jquery-ui-core-drag-drop-select-1.5.3.js / js
/*
* jQuery UI 1.5.3
*
* Copyright (c) 2008 Paul Bakaus (ui.jquery.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* http://docs.jquery.com/UI
*/
;(function(.ui = {
plugin: {
add: function(module, option, set) {
var proto = .ui.cssCache[name]) { return .browser.safari)
//tmp.appendTo('body');
//Opera and Safari set width and height to 0px instead of auto
//Safari returns rgba(0,0,0,0) when bgcolor is not set
.ui.cssCache[name];
},
disableSelection: function(el) {
el.attr('unselectable', 'on').css('MozUserSelect', 'none');
},
enableSelection: function(el) {
el.attr('unselectable', 'off').css('MozUserSelect', '');
},
hasScroll: function(e, a) {
var scroll = /top/.test(a||"top") ? 'scrollTop' : 'scrollLeft', has = false;
if (e[scroll] > 0) return true; e[scroll] = 1;
has = e[scroll] > 0 ? true : false; e[scroll] = 0;
return has;
}
};
jQuery core modifications and additions *
var _remove = .fn.remove = function() {
$("*", this).add(this).triggerHandler("remove");
return _remove.apply(this, arguments );
};
// [namespace][plugin].getter || [];
methods = (typeof methods == "string" ? methods.split(/,?\s+/) : methods);
return (.widget = function(name, prototype) {
var namespace = name.split(".")[0];
name = name.split(".")[1];
// create plugin method
.data(this[0], name);
return (instance ? instance[options].apply(instance, args)
: undefined);
}
return this.each(function() {
var instance = .isFunction(instance[options])) {
instance[options].apply(instance, args);
} else if (!isMethodCall) {
[namespace][name](this, options));
}
});
};
// create widget constructor
.extend({}, [namespace][name].defaults, options);
this.element = element
.bind('setData.' + name, function(e, key, value) {
return self.setData(key, value);
})
.bind('getData.' + name, function(e, key) {
return self.getData(key);
})
.bind('remove', function() {
return self.destroy();
});
this.init();
};
// add widget prototype
.extend({}, .widget.prototype = {
init: function() {},
destroy: function() {
this.element.removeData(this.widgetName);
},
getData: function(key) {
return this.options[key];
},
setData: function(key, value) {
this.options[key] = value;
if (key == 'disabled') {
this.element[value ? 'addClass' : 'removeClass'](
this.widgetBaseClass + '-disabled');
}
},
enable: function() {
this.setData('disabled', false);
},
disable: function() {
this.setData('disabled', true);
}
};
Mouse Interaction Plugin *
.ui.mouse = {
mouseInit: function() {
var self = this;
this.element.bind('mousedown.'+this.widgetName, function(e) {
return self.mouseDown(e);
});
// Prevent text selection in IE
if (.browser.msie
&& this.element.attr('unselectable', this._mouseUnselectable));
},
mouseDown: function(e) {
// we may have missed mouseup (out of window)
(this._mouseStarted && this.mouseUp(e));
this._mouseDownEvent = e;
var self = this,
btnIsLeft = (e.which == 1),
elIsCancel = (typeof this.options.cancel == "string" ? $(e.target).parents().add(e.target).filter(this.options.cancel).length : false);
if (!btnIsLeft || elIsCancel || !this.mouseCapture(e)) {
return true;
}
this._mouseDelayMet = !this.options.delay;
if (!this._mouseDelayMet) {
this._mouseDelayTimer = setTimeout(function() {
self._mouseDelayMet = true;
}, this.options.delay);
}
if (this.mouseDistanceMet(e) && this.mouseDelayMet(e)) {
this._mouseStarted = (this.mouseStart(e) !== false);
if (!this._mouseStarted) {
e.preventDefault();
return true;
}
}
// these delegates are required to keep context
this._mouseMoveDelegate = function(e) {
return self.mouseMove(e);
};
this._mouseUpDelegate = function(e) {
return self.mouseUp(e);
};
document
.bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
.bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
return false;
},
mouseMove: function(e) {
// IE mouseup check - mouseup happened when mouse was out of window
if (.ui.mouse.defaults = {
cancel: null,
distance: 1,
delay: 0
};
})(jQuery);
/*
* jQuery UI Draggable
*
* Copyright (c) 2008 Paul Bakaus
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* http://docs.jquery.com/UI/Draggables
*
* Depends:
* ui.core.js
*/
(function(.widget("ui.draggable", .ui.mouse, {
init: function() {
//Initialize needed constants
var o = this.options;
//Position the node
if (o.helper == 'original' && !(/(relative|absolute|fixed)/).test(this.element.css('position')))
this.element.css('position', 'relative');
this.element.addClass('ui-draggable');
(o.disabled && this.element.addClass('ui-draggable-disabled'));
this.mouseInit();
},
mouseStart: function(e) {
var o = this.options;
if (this.helper || o.disabled || $(e.target).is('.ui-resizable-handle')) return false;
var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
$(this.options.handle, this.element).find("*").andSelf().each(function() {
if(this == e.target) handle = true;
});
if (!handle) return false;
if(.ui.ddmanager.current = this;
//Create and append the visible helper
this.helper = .browser.mozilla) po = { top: 0, left: 0 }; //Ugly FF3 fix
this.offset.parent = { //Store its position plus border
top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
};
var p = this.element.position(); //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helpers
this.offset.relative = this.cssPosition == "relative" ? {
top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.offsetParent[0].scrollTop,
left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.offsetParent[0].scrollLeft
} : { top: 0, left: 0 };
this.originalPosition = this.generatePosition(e); //Generate the original position
this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Cache the helper size
if(o.cursorAt) {
if(o.cursorAt.left != undefined) this.offset.click.left = o.cursorAt.left + this.margins.left;
if(o.cursorAt.right != undefined) this.offset.click.left = this.helperProportions.width - o.cursorAt.right + this.margins.left;
if(o.cursorAt.top != undefined) this.offset.click.top = o.cursorAt.top + this.margins.top;
if(o.cursorAt.bottom != undefined) this.offset.click.top = this.helperProportions.height - o.cursorAt.bottom + this.margins.top;
}
/*
* - Position constraining -
* Here we prepare position constraining like grid and containment.
*/
if(o.containment) {
if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
if(o.containment == 'document' || o.containment == 'window') this.containment = [
0 - this.offset.relative.left - this.offset.parent.left,
0 - this.offset.relative.top - this.offset.parent.top,
$(o.containment == 'document' ? document : window).width() - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.element.css("marginRight"),10) || 0),
($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.element.css("marginBottom"),10) || 0)
];
if(!(/^(document|window|parent).ui.ddmanager && !o.dropBehaviour) .ui.ddmanager) .ui.ddmanager && !this.options.dropBehaviour)
var dropped = .ui.ddmanager) .ui.plugin.call(this, n, [e, this.uiHash()]);
if(n == "drag") this.positionAbs = this.convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins
return this.element.triggerHandler(n == "drag" ? n : "drag"+n, [e, this.uiHash()], this.options[n]);
},
destroy: function() {
if(!this.element.data('draggable')) return;
this.element.removeData("draggable").unbind(".draggable").removeClass('ui-draggable');
this.mouseDestroy();
}
}));
.ui.draggable, {
defaults: {
appendTo: "parent",
axis: false,
cancel: ":input",
delay: 0,
distance: 1,
helper: "original"
}
});
.ui.plugin.add("draggable", "zIndex", {
start: function(e, ui) {
var t = $(ui.helper);
if(t.css("zIndex")) ui.options._zIndex = t.css("zIndex");
t.css('zIndex', ui.options.zIndex);
},
stop: function(e, ui) {
if(ui.options._zIndex) $(ui.helper).css('zIndex', ui.options._zIndex);
}
});
.ui.plugin.add("draggable", "iframeFix", {
start: function(e, ui) {
$(ui.options.iframeFix === true ? "iframe" : ui.options.iframeFix).each(function() {
$('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>')
.css({
width: this.offsetWidth+"px", height: this.offsetHeight+"px",
position: "absolute", opacity: "0.001", zIndex: 1000
})
.css(this.offset())
.appendTo("body");
});
},
stop: function(e, ui) {
$("div.DragDropIframeFix").each(function() { this.parentNode.removeChild(this); }); //Remove frame helpers
}
});
.ui.plugin.add("draggable", "snap", {
start: function(e, ui) {
var inst = this.data("draggable");
inst.snapElements = [];
$(ui.options.snap === true ? '.ui-draggable' : ui.options.snap).each(function() {
var o = t.outerWidth(), height: o.top, left: .ui.plugin.add("draggable", "connectToSortable", {
start: function(e,ui) {
var inst = this.data("draggable");
inst.sortables = [];
$(ui.options.connectToSortable).each(function() {
if(.data(this, 'sortable');
inst.sortables.push({
instance: sortable,
shouldRevert: sortable.options.revert
});
sortable.refreshItems(); //Do a one-time refresh at start to refresh the containerCache
sortable.propagate("activate", e, inst);
}
});
},
stop: function(e,ui) {
//If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
var inst = this.data("draggable");
.extend(this.instance.ui(), { sender: inst.element })], this.instance.options["receive"]);
this.instance.options.helper = this.instance.options._helper;
} else {
this.instance.propagate("deactivate", e, inst);
}
});
},
drag: function(e,ui) {
var inst = this.data("draggable"), self = this;
var checkPos = function(o) {
var l = o.left, r = l + o.width,
t = o.top, b = t + o.height;
return (l < (this.positionAbs.left + this.offset.click.left) && (this.positionAbs.left + this.offset.click.left) < r
&& t < (this.positionAbs.top + this.offset.click.top) && (this.positionAbs.top + this.offset.click.top) < b);
};
.ui.plugin.add("draggable", "stack", {
start: function(e,ui) {
var group = ) {
.extend(o, {
accept: o.accept && o.accept.constructor == Function ? o.accept : function(d) {
return d.is(accept);
}
});
//Store the droppable's proportions
this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
// Add the reference and positions to the manager
.ui.ddmanager.droppables;
for ( var i = 0; i < drop.length; i++ )
if ( drop[i] == this )
drop.splice(i, 1);
this.element
.removeClass("ui-droppable ui-droppable-disabled")
.removeData("droppable")
.unbind(".droppable");
},
over: function(e) {
var draggable = .ui.plugin.call(this, 'over', [e, this.ui(draggable)]);
this.element.triggerHandler("dropover", [e, this.ui(draggable)], this.options.over);
}
},
out: function(e) {
var draggable = .ui.plugin.call(this, 'out', [e, this.ui(draggable)]);
this.element.triggerHandler("dropout", [e, this.ui(draggable)], this.options.out);
}
},
drop: function(e,custom) {
var draggable = custom || .data(this, 'droppable');
if(inst.options.greedy && .extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)) {
childrenIntersection = true; return false;
}
});
if(childrenIntersection) return false;
if(this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) {
.ui.ddmanager.current;
.ui.ddmanager.current;
.extend(.ui.intersect = function(draggable, droppable, toleranceMode) {
if (!droppable.offset) return false;
var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height;
var l = droppable.offset.left, r = l + droppable.proportions.width,
t = droppable.offset.top, b = t + droppable.proportions.height;
switch (toleranceMode) {
case 'fit':
return (l < x1 && x2 < r
&& t < y1 && y2 < b);
break;
case 'intersect':
return (l < x1 + (draggable.helperProportions.width / 2) // Right Half
&& x2 - (draggable.helperProportions.width / 2) < r // Left Half
&& t < y1 + (draggable.helperProportions.height / 2) // Bottom Half
&& y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
break;
case 'pointer':
return (l < ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left) && ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left) < r
&& t < ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top) && ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top) < b);
break;
case 'touch':
return (
(y1 >= t && y1 <= b) || // Top edge touching
(y2 >= t && y2 <= b) || // Bottom edge touching
(y1 < t && y2 > b) // Surrounded vertically
) && (
(x1 >= l && x1 <= r) || // Left edge touching
(x2 >= l && x2 <= r) || // Right edge touching
(x1 < l && x2 > r) // Surrounded horizontally
);
break;
default:
return false;
break;
}
};
/*
This manager tracks offsets of draggables and droppables
*/
.ui.ddmanager.droppables;
var type = e ? e.type : null; // workaround for #2317
for (var i = 0; i < m.length; i++) {
if(m[i].options.disabled || (t && !m[i].options.accept.call(m[i].element,(t.currentItem || t.element)))) continue;
m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue
m[i].offset = m[i].element.offset();
m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
if(type == "dragstart" || type == "sortactivate") m[i].activate.call(m[i], e); //Activate the droppable if used directly from draggables
}
},
drop: function(draggable, e) {
var dropped = false;
.ui.ddmanager.droppables, function() {
if(!this.options) return;
if (!this.options.disabled && this.visible && .ui.ddmanager.prepareOffsets(draggable, e);
//Run through all droppables and check their positions based on specific tolerance options
.ui.ddmanager.droppables, function() {
if(this.options.disabled || this.greedyChild || !this.visible) return;
var intersects = .data(parent[0], 'droppable');
parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
}
}
// we just moved into a greedy child
if (parentInstance && c == 'isover') {
parentInstance['isover'] = 0;
parentInstance['isout'] = 1;
parentInstance.out.call(parentInstance, e);
}
this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0;
this[c == "isover" ? "over" : "out"].call(this, e);
// we just moved out of a greedy child
if (parentInstance && c == 'isout') {
parentInstance['isout'] = 0;
parentInstance['isover'] = 1;
parentInstance.over.call(parentInstance, e);
}
});
}
};
/*
* Droppable Extensions
*/
.ui.plugin.add("droppable", "hoverClass", {
over: function(e, ui) {
this.addClass(ui.options.hoverClass);
},
out: function(e, ui) {
this.removeClass(ui.options.hoverClass);
},
drop: function(e, ui) {
this.removeClass(ui.options.hoverClass);
}
});
})(jQuery);
/*
* jQuery UI Selectable
*
* Copyright (c) 2008 Richard D. Worth (rdworth.org)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* http://docs.jquery.com/UI/Selectables
*
* Depends:
* ui.core.js
*/
(function(.widget("ui.selectable", .ui.mouse, {
init: function() {
var self = this;
this.element.addClass("ui-selectable");
this.dragged = false;
// cache selectee children based on filter
var selectees;
this.refresh = function() {
selectees = $(self.options.filter, self.element[0]);
selectees.each(function() {
var this.offset();
element: this.width(),
bottom: pos.top + this.hasClass('ui-selected'),
selecting: this.hasClass('ui-unselecting')
});
});
};
this.refresh();
this.selectees = selectees.addClass("ui-selectee");
this.mouseInit();
this.helper = $(document.createElement('div')).css({border:'1px dotted black'});
},
toggle: function() {
if(this.options.disabled){
this.enable();
} else {
this.disable();
}
},
destroy: function() {
this.element
.removeClass("ui-selectable ui-selectable-disabled")
.removeData("selectable")
.unbind(".selectable");
this.mouseDestroy();
},
mouseStart: function(e) {
var self = this;
this.opos = [e.pageX, e.pageY];
if (this.options.disabled)
return;
var options = this.options;
this.selectees = $(options.filter, this.element[0]);
// selectable START callback
this.element.triggerHandler("selectablestart", [e, {
"selectable": this.element[0],
"options": options
}], options.start);
$('body').append(this.helper);
// position helper (lasso)
this.helper.css({
"z-index": 100,
"position": "absolute",
"left": e.clientX,
"top": e.clientY,
"width": 0,
"height": 0
});
if (options.autoRefresh) {
this.refresh();
}
this.selectees.filter('.ui-selected').each(function() {
var selectee = element.removeClass('ui-selected');
selectee.selected = false;
selectee..data(this, "selectable-item")) isSelectee = true;
});
return this.options.keyboard ? !isSelectee : true;
},
mouseDrag: function(e) {
var self = this;
this.dragged = true;
if (this.options.disabled)
return;
var options = this.options;
var x1 = this.opos[0], y1 = this.opos[1], x2 = e.pageX, y2 = e.pageY;
if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
this.selectees.each(function() {
var selectee = element.removeClass('ui-selected');
selectee.selected = false;
}
if (selectee.unselecting) {
selectee.element.addClass('ui-selecting');
selectee.selecting = true;
// selectable SELECTING callback
self.element.triggerHandler("selectableselecting", [e, {
selectable: self.element[0],
selecting: selectee.element,
options: options
}], options.selecting);
}
} else {
// UNSELECT
if (selectee.selecting) {
if (e.ctrlKey && selectee.startselected) {
selectee.element.addClass('ui-selected');
selectee.selected = true;
} else {
selectee.element.addClass('ui-unselecting');
selectee.unselecting = true;
}
// selectable UNSELECTING callback
self.element.triggerHandler("selectableunselecting", [e, {
selectable: self.element[0],
unselecting: selectee.element,
options: options
}], options.unselecting);
}
}
if (selectee.selected) {
if (!e.ctrlKey && !selectee.startselected) {
selectee.element.addClass('ui-unselecting');
selectee.unselecting = true;
// selectable UNSELECTING callback
self.element.triggerHandler("selectableunselecting", [e, {
selectable: self.element[0],
unselecting: selectee.element,
options: options
}], options.unselecting);
}
}
}
});
return false;
},
mouseStop: function(e) {
var self = this;
this.dragged = false;
var options = this.options;
$('.ui-unselecting', this.element[0]).each(function() {
var selectee = element.removeClass('ui-unselecting');
selectee.unselecting = false;
selectee.startselected = false;
self.element.triggerHandler("selectableunselected", [e, {
selectable: self.element[0],
unselected: selectee.element,
options: options
}], options.unselected);
});
$('.ui-selecting', this.element[0]).each(function() {
var selectee = element.removeClass('ui-selecting').addClass('ui-selected');
selectee.selecting = false;
selectee.selected = true;
selectee.startselected = true;
self.element.triggerHandler("selectableselected", [e, {
selectable: self.element[0],
selected: selectee.element,
options: options
}], options.selected);
});
this.element.triggerHandler("selectablestop", [e, {
selectable: self.element[0],
options: this.options
}], this.options.stop);
this.helper.remove();
return false;
}
}));
.ui.selectable, {
defaults: {
distance: 1,
delay: 0,
cancel: ":input",
appendTo: 'body',
autoRefresh: true,
filter: '*',
tolerance: 'touch'
}
});
})(jQuery);
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.