Update Title
updateTitle: function(title) { document.title = title; }
TextSnippets > winton > utility
2717 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
Winton Welsh http://stu.dicio.us
updateTitle: function(title) { document.title = title; }
putCenter: function(item) { item = $(item); var xy = item.getDimensions(); var win = this.windowDimensions(); var scrol = this.scrollOffset(); item.style.left = (win[0] / 2) + scrol[0] - (xy.width / 2) + "px"; item.style.top = (win[1] / 2) + scrol[1] - (xy.height / 2) + "px"; }, fullScreen: function(item) { item = $(item); var win = this.windowDimensions(); var scrol = this.scrollOffset(); item.style.height = scrol[1] + win[1] + "px"; }, windowDimensions: function() { var x, y; if (self.innerHeight) { // all except Explorer x = self.innerWidth; y = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode x = document.documentElement.clientWidth; y = document.documentElement.clientHeight; } else if (document.body) { // other Explorers x = document.body.clientWidth; y = document.body.clientHeight; } if (!x) x = 0; if (!y) y = 0; arrayWindowSize = new Array(x,y); return arrayWindowSize; }, scrollOffset: function() { var x, y; if (self.pageYOffset) { // all except Explorer x = self.pageXOffset; y = self.pageYOffset; } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict x = document.documentElement.scrollLeft; y = document.documentElement.scrollTop; } else if (document.body) { // all other Explorers x = document.body.scrollLeft; y = document.body.scrollTop; } if (!x) x = 0; if (!y) y = 0; arrayScrollOffset = new Array(x,y); return arrayScrollOffset; }
execEvent: function(el, type) { Event.observers.each(function(item,index) { if (item[0] == el && item[1] == type) { item[2](); throw $break; } }); }
getHTML: function(node) { var div = document.createElement('DIV'); div.appendChild(node.cloneNode(true)); return div.innerHTML; }
insertArray: function(array, afterIndex, item) { var first = array.slice(0, afterIndex + 1); var second = array.slice(afterIndex + 1); first.push(item); return first.concat(second); }
getRule: function(selector) { var mysheet = document.styleSheets[0]; var myrules = mysheet.cssRules ? mysheet.cssRules : mysheet.rules; for (i = 0; i < myrules.length; i++) if (myrules[i].selectorText.toLowerCase() == selector) return myrules[i]; return; }
childOfID: function(element, id, isClass) { element = $(element); do { if (isClass && element.hasClassName(id)) return element; if (!isClass && element.id == id) return element; } while (element = $(element.parentNode)); return false; }
catchEnter: function(e) { if (e.keyCode == 13) { Event.stop(e); return true; } else return false; }, catchEsc: function(e) { if (e.keyCode == 27) { Event.stop(e); return true; } else return false; }