This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Truncate a string to the closest word | |
String.prototype.truncateToWord = function(len) { | |
return (len = Number(len)) >= 0 ? | |
this.match(new RegExp('^([\\s\\S]{0,' + len + '})(:?\\s|$)'))[1] : | |
undefined; | |
}; | |
// Examples | |
// The "v" marks the first character out of bounds. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prototype object that works a lot like jQuery: | |
var NodeList = Class.create(Enumerable); | |
Object.extend(NodeList.prototype, { | |
initialize: function(selector) { | |
this.elements = $$(selector); | |
}, | |
_each: function(iterator) { | |
this.elements.each(iterator); | |
return this; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prototype object that works a lot like jQuery: | |
var NodeList = Class.create(Enumerable); | |
Object.extend(NodeList.prototype, { | |
initialize: function(selector) { | |
this.elements = $$(selector); | |
}, | |
_each: function(iterator) { | |
this.elements.each(iterator); | |
return this; | |
} |
NewerOlder