Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
Index: app/views/admin/page/edit.rhtml =================================================================== --- app/views/admin/page/edit.rhtml (revision 562) +++ app/views/admin/page/edit.rhtml (working copy) @@ -28,7 +28,7 @@ return false; } tabControl.tabs.each(function(pair){ - if (tabControl.tabs[pair.key].caption == name) { + if (tabControl.tabs.get(pair.key).caption == name) { result = false; alert('Part name must be unique.'); throw $break; Index: public/javascripts/string.js =================================================================== --- public/javascripts/string.js (revision 562) +++ public/javascripts/string.js (working copy) @@ -1,5 +1,4 @@ Object.extend(String.prototype, { - upcase: function() { return this.toUpperCase(); }, @@ -8,10 +7,6 @@ return this.toLowerCase(); }, - strip: function() { - return this.replace(/^\s+/, '').replace(/\s+$/, ''); - }, - toInteger: function() { return parseInt(this); }, @@ -19,5 +14,4 @@ toSlug: function() { return this.strip().downcase().replace(/[^-a-z0-9~\s\.:;+=_]/g, '').replace(/[\s\.:;=+]+/g, '-'); } - -}); \ No newline at end of file +}); Index: public/javascripts/tabcontrol.js =================================================================== --- public/javascripts/tabcontrol.js (revision 562) +++ public/javascripts/tabcontrol.js (working copy) @@ -1,9 +1,4 @@ -var TabControl = Class.create(); - -TabControl.controls = $H(); -TabControl.BadTabError = new Error('TabControl: Invalid tab.'); - -TabControl.prototype = { +TabControl = Class.create({ /* Initializes a tab control. The variable +element_id+ must be the id of an HTML element containing one element with it's class name set to 'tabs' and another element with it's @@ -13,7 +8,7 @@ TabControl.controls[element_id] = this; this.control_id = element_id; this.element = $(element_id); - this.tab_container = document.getElementsByClassName('tabs', this.element).first(); + this.tab_container = this.element.down('.tabs'); this.tabs = $H(); }, @@ -24,17 +19,16 @@ itself. When a tab is initially added the page element is hidden. */ addTab: function(tab_id, caption, page) { - new Insertion.Bottom( - this.tab_container, - '<a class="tab" href="javascript:TabControl.controls[\'' - + this.control_id - + '\'].select(\'' + tab_id + '\');">' + caption + '</a>' + this.tab_container.insert( + '<a class="tab" href="javascript:TabControl.controls[\'#{id}\'].select(\'#{tab_id}\');">#{caption}</a>'.interpolate({ + id: this.control_id, tab_id: tab_id, caption: caption + }) ); var tab = this.tab_container.lastChild; tab.tab_id = tab_id; tab.caption = caption; tab.page = $(page); - this.tabs[tab_id] = tab; + this.tabs.set(tab_id, tab); this._setNotHere(tab); return tab; }, @@ -47,11 +41,8 @@ var id = t.tab_id; Element.remove(t.page); Element.remove(t); - new_tabs = $H(); - this.tabs.each(function(pair) { - if (pair.key != id) new_tabs[pair.key] = pair.value; - }); - this.tabs = new_tabs; + this.tabs.unset(id); + if (this.selected.tab_id == id) { var first = this.firstTab(); if (typeof first != 'undefined') this.select(first.tab_id); @@ -73,22 +64,21 @@ } else { this._setNotHere(pair.key); } - }.bind(this)); - false; + }, this); }, /* Returns the first tab element that was added using #addTab(). */ firstTab: function() { - return this.tabs[this.tabs.keys().first()]; + return this.tabs.get(this.tabs.keys().first()); }, /* Returns the the last tab element that was added using #addTab(). */ lastTab: function() { - return this.tabs[this.tabs.keys().last()]; + return this.tabs.get(this.tabs.keys().last()); }, /* @@ -127,7 +117,7 @@ */ _tabify: function(something) { if (typeof something == 'string') { - var object = this.tabs[something]; + var object = this.tabs.get(something); } else { var object = something; } @@ -137,4 +127,7 @@ throw TabControl.BadTabError; } } -}; \ No newline at end of file +}); + +TabControl.controls = $H(); +TabControl.BadTabError = new Error('TabControl: Invalid tab.'); Index: public/javascripts/tag_reference_search.js =================================================================== --- public/javascripts/tag_reference_search.js (revision 562) +++ public/javascripts/tag_reference_search.js (working copy) @@ -1,5 +1,5 @@ function hasWordInElement(word, element) { - if(element.nodeType == Node.TEXT_NODE) { + if (element.nodeType == Node.TEXT_NODE) { return element.nodeValue.match(word) != null; } else { return $A(element.childNodes).any(function (child) { @@ -11,18 +11,13 @@ var searchingOn = "" function observeTagSearch(element, value) { - if(value.length < 3 && searchingOn != "") { + if (value.length < 3 && searchingOn != "") { searchingOn = ""; - divs = $$("div.tag-description"); - $A(divs).each(function(div){ Element.show(div); }); - } else if(value.length >= 3 && searchingOn != value) { + $$("div.tag-description").invoke('show'); + } else if (value.length >= 3 && searchingOn != value) { searchingOn = value - divs = $$("div.tag-description"); - $A(divs).each(function (div){ - if(hasWordInElement(value, div)) - Element.show(div); - else - Element.hide(div); + $$("div.tag-description").each(function(div) { + div[hasWordInElement(value, div) ? 'show' : 'hide'](); }); } -} \ No newline at end of file +} Index: public/javascripts/sitemap.js =================================================================== --- public/javascripts/sitemap.js (revision 562) +++ public/javascripts/sitemap.js (working copy) @@ -1,23 +1,17 @@ -var SiteMap = Class.create(); -SiteMap.prototype = Object.extend({}, RuledTable.prototype); // Inherit from RuledTable - -Object.extend(SiteMap.prototype, { - - ruledTableInitialize: RuledTable.prototype.initialize, - - initialize: function(id, expanded) { - this.ruledTableInitialize(id); +var SiteMap = Class.create(RuledTable, { + initialize: function($super, id, expanded) { + $super(id); this.expandedRows = expanded }, onRowSetup: function(row) { - Event.observe(row, 'click', this.onMouseClickRow.bindAsEventListener(this), false); + Event.observe(row, 'click', this.onMouseClickRow.bindAsEventListener(this)); }, onMouseClickRow: function(event) { - var element = Event.element(event); + var element = event.element(); if (this.isExpander(element)) { - var row = Event.findElement(event, 'tr'); + var row = event.findElement('tr'); if (this.hasChildren(row)) { this.toggleBranch(row, element); } @@ -25,19 +19,19 @@ }, hasChildren: function(row) { - return ! /\bno-children\b/.test(row.className); + return !row.hasClassName('no-children'); }, isExpander: function(element) { - return (element.tagName.strip().downcase() == 'img') && /\bexpander\b/i.test(element.className); + return element.match('img.expander'); }, isExpanded: function(row) { - return /\bchildren-visible\b/i.test(row.className); + return row.hasClassName('children-visible'); }, isRow: function(element) { - return element.tagName && (element.tagName.strip().downcase() == 'tr'); + return element.tagName && element.match('tr'); }, extractLevel: function(row) { @@ -51,12 +45,7 @@ }, getExpanderImageForRow: function(row) { - var images = $A(row.getElementsByTagName('img', row)); - var expanders = []; - images.each(function(image){ - expanders.push(image); - }.bind(this)); - return expanders.first(); + return row.down('img'); }, saveExpandedCookie: function() { @@ -65,40 +54,35 @@ hideBranch: function(row, img) { var level = this.extractLevel(row); - var sibling = row.nextSibling; - while(sibling != null) { + var sibling = row.next(); + while (sibling != null) { if (this.isRow(sibling)) { if (this.extractLevel(sibling) <= level) break; - Element.hide(sibling); + sibling.hide(); } - sibling = sibling.nextSibling; + sibling = sibling.next(); } var pageId = this.extractPageId(row); - var newExpanded = []; - for(i = 0; i < this.expandedRows.length; i++) - if(this.expandedRows[i] != pageId) - newExpanded.push(this.expandedRows[i]); - this.expandedRows = newExpanded; + this.expandedRows = this.expandedRows.reject(function(row) { return row == pageId }); this.saveExpandedCookie(); - if (img == null) - img = this.getExpanderImageForRow(row); + if (img == null) img = this.getExpanderImageForRow(row); img.src = img.src.replace(/collapse/, 'expand'); - Element.removeClassName(row, 'children-visible'); - Element.addClassName(row, 'children-hidden'); + row.removeClassName('children-visible'); + row.addClassName('children-hidden'); }, showBranchInternal: function(row, img) { var level = this.extractLevel(row); - var sibling = row.nextSibling; + var sibling = row.next(); var children = false; var childOwningSiblings = []; - while(sibling != null) { + while (sibling != null) { if (this.isRow(sibling)) { var siblingLevel = this.extractLevel(sibling); if (siblingLevel <= level) break; if (siblingLevel == level + 1) { - Element.show(sibling); - if(sibling.className.match(/children-visible/)) { + sibling.show(); + if(sibling.hasClassName('children-visible')) { childOwningSiblings.push(sibling); } else { this.hideBranch(sibling); @@ -106,18 +90,16 @@ } children = true; } - sibling = sibling.nextSibling; + sibling = sibling.next(); } - if (!children) - this.getBranch(row); - if (img == null) - img = this.getExpanderImageForRow(row); + if (!children) this.getBranch(row); + if (img == null) img = this.getExpanderImageForRow(row); img.src = img.src.replace(/expand/, 'collapse'); - for(i=0; i < childOwningSiblings.length; i++) { - this.showBranch(childOwningSiblings[i], null); - } - Element.removeClassName(row, 'children-hidden'); - Element.addClassName(row, 'children-visible'); + childOwningSiblings.each(function(sib) { + this.showBranch(sib, null); + }, this); + row.removeClassName('children-hidden'); + row.addClassName('children-visible'); }, showBranch: function(row, img) { @@ -134,13 +116,13 @@ '../admin/ui/pages/children/' + id + '/' + level, { asynchronous: true, - insertion: Insertion.After, + insertion: "after", onLoading: function(request) { - Element.show('busy-' + id); + $('busy-' + id).show(); this.updating = true; }.bind(this), onComplete: function(request) { - var sibling = row.nextSibling; + var sibling = row.next(); while (sibling != null) { if (this.isRow(sibling)) { var siblingLevel = this.extractLevel(sibling); @@ -150,14 +132,14 @@ sibling = sibling.nextSibling; } this.updating = false; - Effect.Fade('busy-' + id); + $('busy-' + id).fade(); }.bind(this) } ); }, toggleBranch: function(row, img) { - if (! this.updating) { + if (!this.updating) { if (this.isExpanded(row)) { this.hideBranch(row, img); } else { @@ -165,5 +147,4 @@ } } } - }); Index: public/javascripts/ruledtable.js =================================================================== --- public/javascripts/ruledtable.js (revision 562) +++ public/javascripts/ruledtable.js (working copy) @@ -1,28 +1,19 @@ -var RuledTable = Class.create(); -RuledTable.prototype = { - +var RuledTable = Class.create({ initialize: function(element_id) { - var table = $(element_id); - var rows = table.getElementsByTagName('tr'); - for (var i = 0; i < rows.length; i++) { - this.setupRow(rows[i]); - } + var table = $(element_id).select('tr').each(this.setupRow, this) }, onMouseOverRow: function(event) { - // Element.addClassName(this, 'highlight'); - this.className = this.className.replace(/\s*\bhighlight\b|$/, ' highlight'); // faster than the above + this.addClassName('highlight'); }, onMouseOutRow: function(event) { - // Element.removeClassName(this, 'highlight'); - this.className = this.className.replace(/\s*\bhighlight\b\s*/, ' '); // faster than the above + this.removeClassName('highlight'); }, setupRow: function(row) { - Event.observe(row, 'mouseover', this.onMouseOverRow.bindAsEventListener(row)); - Event.observe(row, 'mouseout', this.onMouseOutRow.bindAsEventListener(row)); + row.observe('mouseover', this.onMouseOverRow); + row.observe('mouseout', this.onMouseOutRow); if (this.onRowSetup) this.onRowSetup(row); } - -}; \ No newline at end of file +});
This paste will be private.
From the Design Piracy series on my blog: