Modified:
trunk/ui/ui.draggable.js
trunk/ui/ui.droppable.js
trunk/ui/ui.sortable.js
Log:
draggable,droppable,sortable: properly implemented cssNamespace option
across plugins (selectable & resizable to go, so those options should stay
undocumented until all plugins are converted. Fixes #3707)
Modified: trunk/ui/ui.draggable.js
==============================================================================
--- trunk/ui/ui.draggable.js (original)
+++ trunk/ui/ui.draggable.js Wed Jan 7 09:43:15 2009
@@ -20,7 +20,7 @@
this.element[0].style.position = 'relative';
(this.options.cssNamespace &&
this.element.addClass(this.options.cssNamespace+"-draggable"));
- (this.options.disabled &&
this.element.addClass('ui-draggable-disabled'));
+ (this.options.disabled &&
this.element.addClass(this.options.cssNamespace+'-draggable-disabled'));
this._mouseInit();
@@ -28,7 +28,7 @@
destroy: function() {
if(!this.element.data('draggable')) return;
-
this.element.removeData("draggable").unbind(".draggable").removeClass('ui-draggable
ui-draggable-dragging ui-draggable-disabled');
+
this.element.removeData("draggable").unbind(".draggable").removeClass(this.options.cssNamespace+'-draggable '+this.options.cssNamespace+'-draggable-dragging '+this.options.cssNamespace+'-draggable-disabled');
this._mouseDestroy();
},
@@ -36,7 +36,7 @@
var o = this.options;
- if (this.helper || o.disabled ||
$(event.target).is('.ui-resizable-handle'))
+ if (this.helper || o.disabled ||
$(event.target).is('.'+this.options.cssNamespace+'-resizable-handle'))
return false;
//Quit if we're not on a valid handle
@@ -111,7 +111,7 @@
if ($.ui.ddmanager && !o.dropBehaviour)
$.ui.ddmanager.prepareOffsets(this, event);
- this.helper.addClass("ui-draggable-dragging");
+ this.helper.addClass(o.cssNamespace+"-draggable-dragging");
this._mouseDrag(event, true); //Execute the drag once - this causes the
helper not to be visible before getting its correct position
return true;
},
@@ -328,7 +328,7 @@
},
_clear: function() {
- this.helper.removeClass("ui-draggable-dragging");
+ this.helper.removeClass(this.options.cssNamespace+"-draggable-dragging");
if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval)
this.helper.remove();
//if($.ui.ddmanager) $.ui.ddmanager.current = null;
this.helper = null;
Modified: trunk/ui/ui.droppable.js
==============================================================================
--- trunk/ui/ui.droppable.js (original)
+++ trunk/ui/ui.droppable.js Wed Jan 7 09:43:15 2009
@@ -42,7 +42,7 @@
drop.splice(i, 1);
this.element
- .removeClass("ui-droppable-disabled")
+
.removeClass(this.options.cssNamespace+"-droppable "+this.options.cssNamespace+"-droppable-disabled")
.removeData("droppable")
.unbind(".droppable");
},
@@ -105,7 +105,7 @@
if (!draggable || (draggable.currentItem || draggable.element)[0] ==
this.element[0]) return false; // Bail if draggable and droppable are same
element
var childrenIntersection = false;
-
this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function()
{
+
this.element.find(":data(droppable)").not("."+draggable.options.cssNamespace+"-draggable-dragging").each(function()
{
var inst = $.data(this, 'droppable');
if(inst.options.greedy && $.ui.intersect(draggable, $.extend(inst, {
offset: inst.element.offset() }), inst.options.tolerance)) {
childrenIntersection = true; return false;
Modified: trunk/ui/ui.sortable.js
==============================================================================
--- trunk/ui/ui.sortable.js (original)
+++ trunk/ui/ui.sortable.js Wed Jan 7 09:43:15 2009
@@ -17,7 +17,7 @@
var o = this.options;
this.containerCache = {};
- this.element.addClass("ui-sortable");
+ (this.options.cssNamespace &&
this.element.addClass(this.options.cssNamespace+"-sortable"));
//Get the items
this.refresh();
@@ -35,7 +35,7 @@
destroy: function() {
this.element
- .removeClass("ui-sortable ui-sortable-disabled")
+
.removeClass(this.options.cssNamespace+"-sortable "+this.options.cssNamespace+"-sortable-disabled")
.removeData("sortable")
.unbind(".sortable");
this._mouseDestroy();
@@ -169,7 +169,7 @@
this.dragging = true;
- this.helper.addClass('ui-sortable-helper');
+ this.helper.addClass(o.cssNamespace+'-sortable-helper');
this._mouseDrag(event); //Execute the drag once - this causes the helper
not to be visible before getting its correct position
return true;
@@ -270,7 +270,7 @@
this._mouseUp();
if(this.options.helper == "original")
-
this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
+
this.currentItem.css(this._storedCSS).removeClass(this.options.cssNamespace+"-sortable-helper");
else
this.currentItem.show();
@@ -422,13 +422,13 @@
for (var j = cur.length - 1; j >= 0; j--){
var inst = $.data(cur[j], 'sortable');
if(inst && inst != this && !inst.options.disabled) {
- queries.push([$.isFunction(inst.options.items) ?
inst.options.items.call(inst.element) : $(inst.options.items,
inst.element).not(".ui-sortable-helper"), inst]);
+ queries.push([$.isFunction(inst.options.items) ?
inst.options.items.call(inst.element) : $(inst.options.items,
inst.element).not("."+inst.options.cssNamespace+"-sortable-helper"), inst]);
}
};
};
}
- queries.push([$.isFunction(this.options.items) ?
this.options.items.call(this.element, null, { options: this.options, item:
this.currentItem }) : $(this.options.items,
this.element).not(".ui-sortable-helper"), this]);
+ queries.push([$.isFunction(this.options.items) ?
this.options.items.call(this.element, null, { options: this.options, item:
this.currentItem }) : $(this.options.items,
this.element).not("."+this.options.cssNamespace+"-sortable-helper"), this]);
for (var i = queries.length - 1; i >= 0; i--){
queries[i][0].each(function() {
@@ -552,8 +552,8 @@
element: function() {
var el = $(document.createElement(self.currentItem[0].nodeName))
- .addClass(className || self.currentItem[0].className+"
ui-sortable-placeholder")
- .removeClass('ui-sortable-helper')[0];
+ .addClass(className ||
self.currentItem[0].className+" "+self.options.cssNamespace+"-sortable-placeholder")
+ .removeClass(self.options.cssNamespace+'-sortable-helper')[0];
if(!className) {
el.style.visibility = "hidden";
@@ -823,12 +823,12 @@
for(var i in this._storedCSS) {
if(this._storedCSS[i] == 'auto' || this._storedCSS[i] == 'static')
this._storedCSS[i] = '';
}
- this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
+
this.currentItem.css(this._storedCSS).removeClass(this.options.cssNamespace+"-sortable-helper");
} else {
this.currentItem.show();
}
- if(this.domPosition.prev !=
this.currentItem.prev().not(".ui-sortable-helper")[0] ||
this.domPosition.parent != this.currentItem.parent()[0])
this._propagate("update", event, null, noPropagation); //Trigger update
callback if the DOM position has changed
+ if(this.domPosition.prev !=
this.currentItem.prev().not("."+this.options.cssNamespace+"-sortable-helper")[0]
|| this.domPosition.parent != this.currentItem.parent()[0])
this._propagate("update", event, null, noPropagation); //Trigger update
callback if the DOM position has changed
if(!$.ui.contains(this.element[0], this.currentItem[0])) { //Node was
moved out of the current element
this._propagate("remove", event, null, noPropagation);
for (var i = this.containers.length - 1; i >= 0; i--){
@@ -896,6 +896,7 @@
accurateIntersection: true,
appendTo: "parent",
cancel: ":input,option",
+ cssNamespace: 'ui',
delay: 0,
distance: 1,
dropOnEmpty: true,
Seems to me there's a difference between being able to change the 'ui-' namespace and being able to tell draggables not to add a class (for performance reasons). In order to support an option to customize the 'ui-' namespace, it seems we would have to do so for all plugins (I don't think we should do it half-way). That would require a lot of changes and a lot of testing. And it would mean that the user would have to create their own css framework+theme from scratch, no?
We have to support change the name of the css namespace or via noClasses to not add classes combined with a addClasses or via cssNamespace (that makes more sense for me).
All components should support this
and themeroller too.
This is useless: $(el).draggable().addClass('my-class')
On Sat, Jan 17, 2009 at 1:44 AM, Eduardo Lundgren <eduardo...@gmail.com> wrote:
We have to support change the name of the css namespace or via noClasses to not add classes combined with a addClasses or via cssNamespace (that makes more sense for me).
Paul and Scott already agreed above that we're not going to support changing the css namespace.
So the only question left (as I understand it) is how to allow the user in this specific case, to specify they don't want classes added to each individual element (of which there may be many) for performance reasons. So Scott suggested three option names
- addClasses
- applyClasses
- useClasses
I assume we would chose one of these, and it would default to true?
All components should support this
All components don't have the performance need that it seems draggable has, to not add classes to each individual draggable element, where they may be hundreds or thousands.
and themeroller too.
ThemeRoller's role is pretty limited in this regard. Its reason for existing is to modify the visual style of jQuery UI CSS Framework classes (ui-widget, ui-state-default, ui-icon, etc.). This is a totally separate set of classes from ui-draggable, ui-draggable-disabled, etc., which we generally call plugin specific classes. Draggable adds no framework classes, and ThemeRoller does not modify styles of plugin specific classes.
This is useless: $(el).draggable().addClass('my-class')
This looks quite useful to me. The plugin itself adds the plugin classes (in the 'ui-' css namespace) unless the user has requested they not be added for performance reasons. If a user wants diffferent additional classes to select or style these elements, that's up to them. They know what these elements are, since they have selected them in order to call .draggable(). No need for the plugin to do what jQuery can do quite simply.
On Sat, Jan 17, 2009 at 11:45 AM, Richard D. Worth <rdw...@gmail.com> wrote:On Sat, Jan 17, 2009 at 1:44 AM, Eduardo Lundgren <eduardo...@gmail.com> wrote:
We have to support change the name of the css namespace or via noClasses to not add classes combined with a addClasses or via cssNamespace (that makes more sense for me).
Paul and Scott already agreed above that we're not going to support changing the css namespace.
So the only question left (as I understand it) is how to allow the user in this specific case, to specify they don't want classes added to each individual element (of which there may be many) for performance reasons. So Scott suggested three option names
- addClasses
- applyClasses
- useClasses
I assume we would chose one of these, and it would default to true?
All components should support this
All components don't have the performance need that it seems draggable has, to not add classes to each individual draggable element, where they may be hundreds or thousands.
Be careful about that Richard - you have to develop a feeling for real world enterprise cases (same goes for Scott). I could agree that probably draggable & droppable are the most often individually initialized components. However, you never know what users build. We should always optimize the initialization first. We will want to make sure that all components scale, this should be top priority.
Richard,
What happen if a client using jQuery UI need to change the css namespace for some reason? If we don't have this option they will have to find and replace the "ui-" for "somethingelse-".
Using an option as cssNamespace, we are able to:
cssNamespace: false - increase the performance
cssNamespace: 'somethingelse-' - change the namespace
cssNamespace: undefined - use the default ui- namespace
In order than a method to addClasses, this method is not simple, imagine if the user want to add the className to another internal element instead of the this.element how come we could do this with this option?
One option could be the user define a css class like this example below, that is resonable for me too:
.ui-element.customized-user-class .title {}
On Sat, Jan 17, 2009 at 1:42 PM, Eduardo Lundgren <eduardo...@gmail.com> wrote:Richard,
What happen if a client using jQuery UI need to change the css namespace for some reason? If we don't have this option they will have to find and replace the "ui-" for "somethingelse-".
We haven't heard of any reasons and we can't think of any.
Using an option as cssNamespace, we are able to:
cssNamespace: false - increase the performance
cssNamespace: 'somethingelse-' - change the namespace
cssNamespace: undefined - use the default ui- namespace
Yes, we all fully understand what it would provide and we don't think it's necessary.
In order than a method to addClasses, this method is not simple, imagine if the user want to add the className to another internal element instead of the this.element how come we could do this with this option?
We don't want to support random customization of classes. Either everything is classed or nothing, and you will only get this option of extremely simple (markup-wise) elements that require very high performance.
One option could be the user define a css class like this example below, that is resonable for me too:
.ui-element.customized-user-class .title {}
You should use CSS the way it is meant to be used by applying a custom class to the outermost element and writing styles appropriately.
$(el).plugin().addClass('myClass');
On Sat, Jan 17, 2009 at 7:51 PM, Scott González <scott.g...@gmail.com> wrote:
On Sat, Jan 17, 2009 at 1:42 PM, Eduardo Lundgren <eduardo...@gmail.com> wrote:
Richard,
What happen if a client using jQuery UI need to change the css namespace for some reason? If we don't have this option they will have to find and replace the "ui-" for "somethingelse-".
We haven't heard of any reasons and we can't think of any.
Seriously Scott, are you kidding me? Every single application or framework with its own conventions may want to do this.
Wichert.
In order than a method to addClasses, this method is not simple, imagine if the user want to add the className to another internal element instead of the this.element how come we could do this with this option?
We don't want to support random customization of classes. Either everything is classed or nothing, and you will only get this option of extremely simple (markup-wise) elements that require very high performance.
Please look at cssNamespace and how it's implemented right now (i.e. in draggables). It switches the "ui-" namespace for all classes that are added (i.e. also ui-draggable-disabled). Easy, and useful.
- Richard