Code
<%= sortable_element 'image-list',
:constraint => false,
:url => { :action => 'sort', :issue_id => params[:issue_id] }
-%><script type="text/javascript">
//<![CDATA[
Event.onDOMReady(function(){FirstLast.go("image-list")});
Ajax.Responders.register({
onComplete: function(){FirstLast.go("image-list");}
});
//]]>
</script>var FirstLast = {
go: function(el) {
el = $(el);
// Whitespace nodes need to be cleaned to get the intended effect
var children = Element.cleanWhitespace(el).childNodes;
// Return if there are not any children
if (0 == children.length) return
if (1 == children.length) {
// Cheap shortcut if there is only 1 child node
children[0].addClassName(this._firstChildClassName);
children[0].addClassName(this._lastChildClassName);
} else {
for (var i = 0; i < children.length; i++) {
switch (i) {
// First child
case 0:
children[i].addClassName(this._firstChildClassName);
children[i].removeClassName(this._lastChildClassName);
break;
// Last child
case children.length - 1:
children[i].removeClassName(this._firstChildClassName);
children[i].addClassName(this._lastChildClassName);
break;
// Every child other than the first or last
default:
children[i].removeClassName(this._firstChildClassName);
children[i].removeClassName(this._lastChildClassName);
break; // I know it is unnecessary
}
}
}
},
// Pseudo Private methods and attributes
_firstChildClassName: "first",
_lastChildClassName: "last"
};
:constraint => false,
:url => { :action => 'sort', :issue_id => params[:issue_id] }
-%><script type="text/javascript">
//<![CDATA[
Event.onDOMReady(function(){FirstLast.go("image-list")});
Ajax.Responders.register({
onComplete: function(){FirstLast.go("image-list");}
});
//]]>
</script>var FirstLast = {
go: function(el) {
el = $(el);
// Whitespace nodes need to be cleaned to get the intended effect
var children = Element.cleanWhitespace(el).childNodes;
// Return if there are not any children
if (0 == children.length) return
if (1 == children.length) {
// Cheap shortcut if there is only 1 child node
children[0].addClassName(this._firstChildClassName);
children[0].addClassName(this._lastChildClassName);
} else {
for (var i = 0; i < children.length; i++) {
switch (i) {
// First child
case 0:
children[i].addClassName(this._firstChildClassName);
children[i].removeClassName(this._lastChildClassName);
break;
// Last child
case children.length - 1:
children[i].removeClassName(this._firstChildClassName);
children[i].addClassName(this._lastChildClassName);
break;
// Every child other than the first or last
default:
children[i].removeClassName(this._firstChildClassName);
children[i].removeClassName(this._lastChildClassName);
break; // I know it is unnecessary
}
}
}
},
// Pseudo Private methods and attributes
_firstChildClassName: "first",
_lastChildClassName: "last"
};
