Commit 8a1575e9 authored by bpandey's avatar bpandey

added jquery


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@93748 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 839716d8
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* jQuery UI @VERSION
*
* 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($) {
/** jQuery core modifications and additions **/
var _remove = $.fn.remove;
$.fn.remove = function() {
$("*", this).add(this).triggerHandler("remove");
return _remove.apply(this, arguments );
};
function isVisible(element) {
function checkStyles(element) {
var style = element.style;
return (style.display != 'none' && style.visibility != 'hidden');
}
var visible = checkStyles(element);
(visible && $.each($.dir(element, 'parentNode'), function() {
return (visible = checkStyles(this));
}));
return visible;
}
$.extend($.expr[':'], {
data: function(a, i, m) {
return $.data(a, m[3]);
},
// TODO: add support for object, area
tabbable: function(a, i, m) {
var nodeName = a.nodeName.toLowerCase();
return (
// in tab order
a.tabIndex >= 0 &&
( // filter node types that participate in the tab order
// anchor tag
('a' == nodeName && a.href) ||
// enabled form element
(/input|select|textarea|button/.test(nodeName) &&
'hidden' != a.type && !a.disabled)
) &&
// visible on page
isVisible(a)
);
}
});
$.keyCode = {
BACKSPACE: 8,
CAPS_LOCK: 20,
COMMA: 188,
CONTROL: 17,
DELETE: 46,
DOWN: 40,
END: 35,
ENTER: 13,
ESCAPE: 27,
HOME: 36,
INSERT: 45,
LEFT: 37,
NUMPAD_ADD: 107,
NUMPAD_DECIMAL: 110,
NUMPAD_DIVIDE: 111,
NUMPAD_ENTER: 108,
NUMPAD_MULTIPLY: 106,
NUMPAD_SUBTRACT: 109,
PAGE_DOWN: 34,
PAGE_UP: 33,
PERIOD: 190,
RIGHT: 39,
SHIFT: 16,
SPACE: 32,
TAB: 9,
UP: 38
};
// $.widget is a factory to create jQuery plugins
// taking some boilerplate code out of the plugin code
// created by Scott González and Jörn Zaefferer
function getter(namespace, plugin, method, args) {
function getMethods(type) {
var methods = $[namespace][plugin][type] || [];
return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
}
var methods = getMethods('getter');
if (args.length == 1 && typeof args[0] == 'string') {
methods = methods.concat(getMethods('getterSetter'));
}
return ($.inArray(method, methods) != -1);
}
$.widget = function(name, prototype) {
var namespace = name.split(".")[0];
name = name.split(".")[1];
// create plugin method
$.fn[name] = function(options) {
var isMethodCall = (typeof options == 'string'),
args = Array.prototype.slice.call(arguments, 1);
// prevent calls to internal methods
if (isMethodCall && options.substring(0, 1) == '_') {
return this;
}
// handle getter methods
if (isMethodCall && getter(namespace, name, options, args)) {
var instance = $.data(this[0], name);
return (instance ? instance[options].apply(instance, args)
: undefined);
}
// handle initialization and non-getter methods
return this.each(function() {
var instance = $.data(this, name);
// constructor
(!instance && !isMethodCall &&
$.data(this, name, new $[namespace][name](this, options)));
// method call
(instance && isMethodCall && $.isFunction(instance[options]) &&
instance[options].apply(instance, args));
});
};
// create widget constructor
$[namespace][name] = function(element, options) {
var self = this;
this.widgetName = name;
this.widgetEventPrefix = $[namespace][name].eventPrefix || name;
this.widgetBaseClass = namespace + '-' + name;
this.options = $.extend({},
$.widget.defaults,
$[namespace][name].defaults,
$.metadata && $.metadata.get(element)[name],
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
$[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
// TODO: merge getter and getterSetter properties from widget prototype
// and plugin prototype
$[namespace][name].getterSetter = 'option';
};
$.widget.prototype = {
_init: function() {},
destroy: function() {
this.element.removeData(this.widgetName);
},
option: function(key, value) {
var options = key,
self = this;
if (typeof key == "string") {
if (value === undefined) {
return this._getData(key);
}
options = {};
options[key] = value;
}
$.each(options, function(key, value) {
self._setData(key, value);
});
},
_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);
},
_trigger: function(type, e, data) {
var eventName = (type == this.widgetEventPrefix
? type : this.widgetEventPrefix + type);
e = e || $.event.fix({ type: eventName, target: this.element[0] });
return this.element.triggerHandler(eventName, [e, data], this.options[type]);
}
};
$.widget.defaults = {
disabled: false
};
/** jQuery UI core **/
$.ui = {
plugin: {
add: function(module, option, set) {
var proto = $.ui[module].prototype;
for(var i in set) {
proto.plugins[i] = proto.plugins[i] || [];
proto.plugins[i].push([option, set[i]]);
}
},
call: function(instance, name, args) {
var set = instance.plugins[name];
if(!set) { return; }
for (var i = 0; i < set.length; i++) {
if (instance.options[set[i][0]]) {
set[i][1].apply(instance.element, args);
}
}
}
},
cssCache: {},
css: function(name) {
if ($.ui.cssCache[name]) { return $.ui.cssCache[name]; }
var tmp = $('<div class="ui-gen">').addClass(name).css({position:'absolute', top:'-5000px', left:'-5000px', display:'block'}).appendTo('body');
//if (!$.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] = !!(
(!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) ||
!(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor')))
);
try { $('body').get(0).removeChild(tmp.get(0)); } catch(e){}
return $.ui.cssCache[name];
},
disableSelection: function(el) {
return $(el)
.attr('unselectable', 'on')
.css('MozUserSelect', 'none')
.bind('selectstart.ui', function() { return false; });
},
enableSelection: function(el) {
return $(el)
.attr('unselectable', 'off')
.css('MozUserSelect', '')
.unbind('selectstart.ui');
},
hasScroll: function(e, a) {
//If overflow is hidden, the element might have extra content, but the user wants to hide it
if ($(e).css('overflow') == 'hidden') { return false; }
var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop',
has = false;
if (e[scroll] > 0) { return true; }
// TODO: determine which cases actually cause this to happen
// if the element doesn't have the scroll set, see if it's possible to
// set the scroll
e[scroll] = 1;
has = (e[scroll] > 0);
e[scroll] = 0;
return has;
}
};
/** 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._mouseUnselectable = this.element.attr('unselectable');
this.element.attr('unselectable', 'on');
}
this.started = false;
},
// TODO: make sure destroying one instance of mouse doesn't mess with
// other instances of mouse
_mouseDestroy: function() {
this.element.unbind('.'+this.widgetName);
// Restore text selection in IE
($.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 ($.browser.msie && !e.button) {
return this._mouseUp(e);
}
if (this._mouseStarted) {
this._mouseDrag(e);
return false;
}
if (this._mouseDistanceMet(e) && this._mouseDelayMet(e)) {
this._mouseStarted =
(this._mouseStart(this._mouseDownEvent, e) !== false);
(this._mouseStarted ? this._mouseDrag(e) : this._mouseUp(e));
}
return !this._mouseStarted;
},
_mouseUp: function(e) {
$(document)
.unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
.unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
if (this._mouseStarted) {
this._mouseStarted = false;
this._mouseStop(e);
}
return false;
},
_mouseDistanceMet: function(e) {
return (Math.max(
Math.abs(this._mouseDownEvent.pageX - e.pageX),
Math.abs(this._mouseDownEvent.pageY - e.pageY)
) >= this.options.distance
);
},
_mouseDelayMet: function(e) {
return this.mouseDelayMet;
},
// These are placeholder methods, to be overriden by extending plugin
_mouseStart: function(e) {},
_mouseDrag: function(e) {},
_mouseStop: function(e) {},
_mouseCapture: function(e) { return true; }
};
$.ui.mouse.defaults = {
cancel: null,
distance: 1,
delay: 0
};
})(jQuery);
;(function($) {
/*
* ui.dropdownchecklist
*
* Copyright (c) 2008 Adrian Tosca
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
*/
// The dropdown check list jQuery plugin transforms a regular select html element into a dropdown check list.
$.widget("ui.dropdownchecklist", {
// Creates the drop container that keeps the items and appends it to the document
_appendDropContainer: function() {
var wrapper = $("<div/>");
// the container is wrapped in a div
wrapper.addClass("ui-dropdownchecklist-dropcontainer-wrapper");
// initially hidden
wrapper.css({
position: 'absolute',
left: "-3300",
top: "-3300px",
width: '3000px',
height: '3000px'
});
var container = $("<div/>"); // the actual container
container.addClass("ui-dropdownchecklist-dropcontainer")
.css("overflow-y", "auto");
wrapper.append(container);
$(document.body).append(wrapper);
// flag that tells if the drop container is shown or not
wrapper.drop = false;
return wrapper;
},
// Creates the control that will replace the source select and appends it to the document
// The control resembles a regular select with single selection
_appendControl: function() {
var self = this, options = this.options, sourceSelect = this.sourceSelect;
// the controls is wrapped in a span with inline-block display
var wrapper = $("<span/>");
wrapper.addClass("ui-dropdownchecklist-wrapper");
wrapper.css({
display: "inline-block",
cursor: "default"
});
// the actual control, can be styled to set the border and drop right image
var control = $("<span/>");
control.addClass("ui-dropdownchecklist");
control.css({
display: "inline-block"
});
wrapper.append(control);
// the text container keeps the control text that is build from the selected (checked) items
var textContainer = $("<span/>");
textContainer.addClass("ui-dropdownchecklist-text")
textContainer.css({
display: "inline-block",
overflow: "hidden"
});
control.append(textContainer);
// add the hover styles to the control
wrapper.hover(function() {
if (!self.disabled) {
control.toggleClass("ui-dropdownchecklist-hover")
}
}, function() {
if (!self.disabled) {
control.toggleClass("ui-dropdownchecklist-hover")
}
});
// clicking on the control toggles the drop container
wrapper.click(function(event) {
if (!self.disabled) {
event.stopPropagation();
self._toggleDropContainer();
}
})
wrapper.insertAfter(sourceSelect);
// prevent wrapping
textContainer.css("height", control.height());
return wrapper;
},
// Creates a drop item that coresponds to an option element in the source select
_createDropItem: function(index, value, text, checked, indent) {
var self = this;
// the item contains a div that contains a checkbox input and a span for text
// the div
var item = $("<div/>");
item.addClass("ui-dropdownchecklist-item");
item.css({whiteSpace: "nowrap"});
// the checkbox
var checkedString = checked ? ' checked="checked"' : '';
var checkBox = $('<input type="checkbox"' + checkedString + '/>')
.attr("index", index)
.val(value);
item.append(checkBox);
// the text
var label = $("<span/>");
label.addClass("ui-dropdownchecklist-text")
.css({
cursor: "default",
width: "100%"
})
.text(text);
if (indent) {
item.addClass("ui-dropdownchecklist-indent");
}
item.append(label);
// firefox or jquery bug prevents chaning style when hover out when over a scrollbar, disable for now
if (!$.browser.mozilla) {
item.hover(function() {
item.toggleClass("ui-dropdownchecklist-item-hover")
}, function() {
item.toggleClass("ui-dropdownchecklist-item-hover")
});
}
// clicking on the checkbox synchronizes the source select
checkBox.click(function(event) {
event.stopPropagation();
self._syncSelected($(this));
});
// check/uncheck the item on clicks on the entire item div
var checkItem = function(event) {
event.stopPropagation();
var checked = checkBox.attr("checked");
checkBox.attr("checked", !checked)
self._syncSelected(checkBox);
}
label.click(checkItem);
item.click(checkItem);
return item;
},
_createGroupItem: function(text) {
var self = this;
var group = $("<div />")
group.addClass("ui-dropdownchecklist-group");
group.css({whiteSpace: "nowrap"});
var label = $("<span/>");
label.addClass("ui-dropdownchecklist-text")
.css({
cursor: "default",
width: "100%"
})
.text(text);
group.append(label);
return group;
},
// Creates the drop items and appends them to the drop container
// Also calculates the size needed by the drop container and returns it
_appendItems: function() {
var self = this, sourceSelect = this.sourceSelect, controlWrapper = this.controlWrapper, dropWrapper = this.dropWrapper;
var dropContainerDiv = dropWrapper.find(".ui-dropdownchecklist-dropcontainer");
dropContainerDiv.css({ float: "left" }); // to allow getting the actual width of the container
sourceSelect.children("optgroup").each(function(index) { // when the select has groups
var optgroup = $(this);
var text = optgroup.attr("label");
var group = self._createGroupItem(text);
dropContainerDiv.append(group);
self._appendOptions(optgroup, dropContainerDiv, true);
});
self._appendOptions(sourceSelect, dropContainerDiv, false); // when no groups
var divWidth = dropContainerDiv.outerWidth();
var divHeight = dropContainerDiv.outerHeight();
dropContainerDiv.css({ float: "" }); // set it back
return { width: divWidth, height: divHeight };
},
_appendOptions : function(parent, container, indent) {
var self = this;
parent.children("option").each(function(index) {
var option = $(this);
var text = option.text();
var value = option.val();
var selected = option.attr("selected");
var item = self._createDropItem(index, value, text, selected, indent);
container.append(item);
})
},
// Synchronizes the items checked and the source select
// When firstItemChecksAll option is active also synchronizes the checked items
// senderCheckbox parameters is the checkbox input that generated the synchronization
_syncSelected: function(senderCheckbox) {
var self = this, options = this.options, sourceSelect = this.sourceSelect, controlWrapper = this.controlWrapper, dropWrapper = this.dropWrapper;
var allCheckboxes = dropWrapper.find("input");
if (options.firstItemChecksAll) {
// if firstItemChecksAll is true, check all checkboxes if the first one is checked
if (senderCheckbox.attr("index") == 0) {
allCheckboxes.attr("checked", senderCheckbox.attr("checked"));
} else {
// check the first checkbox if all the other checkboxes are checked
var allChecked;
allChecked = true;
allCheckboxes.each(function(index) {
if (index > 0) {
var checked = $(this).attr("checked");
if (!checked) allChecked = false;
}
});
var firstCheckbox = allCheckboxes.filter(":first");
firstCheckbox.attr("checked", false);
if (allChecked) {
firstCheckbox.attr("checked", true);
}
}
}
// do the actual synch with the source select
var selectOptions = sourceSelect.get(0).options;
allCheckboxes.each(function(index) {
$(selectOptions[index]).attr("selected", $(this).attr("checked"));
});
// update the text shown in the control
self._updateControlText();
},
// Updates the text shown in the control depending on the checked (selected) items
_updateControlText: function() {
var self = this, sourceSelect = this.sourceSelect, options = this.options, controlWrapper = this.controlWrapper, dropWrapper = this.dropWrapper;
var firstSelect = sourceSelect.children("option:first");
var allSelected = null != firstSelect && firstSelect.attr("selected");
var selectOptions = sourceSelect.children("option");
var text = self._formatText(selectOptions, options.firstItemChecksAll, allSelected);
var controlLabel = controlWrapper.find(".ui-dropdownchecklist-text");
controlLabel.text(text);
controlLabel.attr("title", text);
},
// Formats the text that is shown in the control
_formatText: function(selectOptions, firstItemChecksAll, allSelected) {
var text;
if (firstItemChecksAll && allSelected) {
// just set the text from the first item
text = selectOptions.filter(":first").text();
} else {
// concatenate the text from the checked items
text = "";
selectOptions.each(function() {
if ($(this).attr("selected")) {
text += $(this).text() + ", ";
}
});
if (text.length > 0) {
text = text.substring(0, text.length - 2);
}
}
return text;
},
// Shows and hides the drop container
_toggleDropContainer: function() {
var self = this, dropWrapper = this.dropWrapper, controlWrapper = this.controlWrapper;
// hides the last shown drop container
var hide = function() {
var instance = $.ui.dropdownchecklist.drop;
if (null != instance) {
instance.dropWrapper.css({
top: "-3300px",
left: "-3300px"
});
instance.controlWrapper.find(".ui-dropdownchecklist").toggleClass("ui-dropdownchecklist-active");
instance.dropWrapper.drop = false;
$.ui.dropdownchecklist.drop = null;
$(document).unbind("click", hide);
}
}
// shows the given drop container instance
var show = function(instance) {
if (null != $.ui.dropdownchecklist.drop) {
hide();
}
instance.dropWrapper.css({
top: instance.controlWrapper.offset().top + instance.controlWrapper.outerHeight() + "px",
left: instance.controlWrapper.offset().left + "px"
})
instance.controlWrapper.find(".ui-dropdownchecklist").toggleClass("ui-dropdownchecklist-active");
instance.dropWrapper.drop = true;
$.ui.dropdownchecklist.drop = instance;
$(document).bind("click", hide);
}
if (dropWrapper.drop) {
hide(self);
} else {
show(self);
}
},
// Set the size of the control and of the drop container
_setSize: function(dropCalculatedSize) {
var options = this.options, dropWrapper = this.dropWrapper, controlWrapper = this.controlWrapper;
var controlWidth;
// use the width from options if set, otherwise set the same width as the drop container
if (options.width) {
controlWidth = parseInt(options.width);
} else {
controlWidth = dropCalculatedSize.width;
var minWidth = options.minWidth;
// if the width is to small (usually when there are no items) set a minimum width
if (controlWidth < minWidth) {
controlWidth = minWidth;
}
}
controlWrapper.find(".ui-dropdownchecklist-text").css({
width: controlWidth + "px"
});
// for the drop container get the actual (outer) width of the control.
// this can be different than the set one depening on paddings, borders etc set on the control
var controlOuterWidth = controlWrapper.outerWidth();
// the drop container height can be set from options
var dropHeight = options.maxDropHeight ? parseInt(options.maxDropHeight) : dropCalculatedSize.height;
// ensure the drop container is not less than the control width (would be ugly)
var dropWidth = dropCalculatedSize.width < controlOuterWidth ? controlOuterWidth : dropCalculatedSize.width;
$(dropWrapper).css({
width: dropWidth + "px",
height: dropHeight + "px"
});
dropWrapper.find(".ui-dropdownchecklist-dropcontainer").css({
height: dropHeight + "px"
});
},
// Initializes the plugin
_init: function() {
var self = this, options = this.options;
// sourceSelect is the select on which the plugin is applied
var sourceSelect = self.element;
self.initialDisplay = sourceSelect.css("display");
sourceSelect.css("display", "none");
self.initialMultiple = sourceSelect.attr("multiple");
sourceSelect.attr("multiple", "multiple");
self.sourceSelect = sourceSelect;
// create the drop container where the items are shown
var dropWrapper = self._appendDropContainer();
self.dropWrapper = dropWrapper;
// append the items from the source select element
var dropCalculatedSize = self._appendItems();
// append the control that resembles a single selection select
var controlWrapper = self._appendControl();
self.controlWrapper = controlWrapper;
// updates the text shown in the control
self._updateControlText(controlWrapper, dropWrapper, sourceSelect);
// set the sizes of control and drop container
self._setSize(dropCalculatedSize);
},
enable: function() {
this.controlWrapper.find(".ui-dropdownchecklist").removeClass("ui-dropdownchecklist-disabled");
this.disabled = false;
},
disable: function() {
this.controlWrapper.find(".ui-dropdownchecklist").addClass("ui-dropdownchecklist-disabled");
this.disabled = true;
},
destroy: function() {
this.sourceSelect.css("display", this.initialDisplay);
this.sourceSelect.attr("multiple", this.initialMultiple);
this.controlWrapper.unbind().remove();
this.dropWrapper.remove();
}
});
$.extend($.ui.dropdownchecklist, {
defaults: {
width: null,
maxDropHeight: null,
firstItemChecksAll: false,
minWidth: 50
}
});
})(jQuery);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment