// link_indicator.js // == written by Takuya Otani === // == Copyright (C) 2006 SimpleBoxes/SerendipityNZ Ltd. == /* Copyright (C) 2006 Takuya Otani/SimpleBoxes - http://serennz.cool.ne.jp/sb/ Copyright (C) 2006 SerendipityNZ - http://serennz.cool.ne.jp/snz/ This script is licensed under the Creative Commons Attribution 2.5 License http://creativecommons.org/licenses/by/2.5/ basically, do anything you want, just leave my name and link. */ // === utilities === function addEvent(object, type, handler) { if (object.addEventListener) { object.addEventListener(type, handler, false); } else if (object.attachEvent) { object.attachEvent(['on',type].join(''),handler); } else { object[['on',type].join('')] = handler; } } function getEvent(evt) { return (evt) ? evt : ((window.event) ? window.event : null); } function WindowSize() { // window size object this.w = 0; this.h = 0; return this.update(); } WindowSize.prototype.update = function() { var d = document; this.w = (window.innerWidth) ? window.innerWidth : (d.documentElement && d.documentElement.clientWidth) ? d.documentElement.clientWidth : d.body.clientWidth; this.h = (window.innerHeight) ? window.innerHeight : (d.documentElement && d.documentElement.clientHeight) ? d.documentElement.clientHeight : d.body.clientHeight; return this; }; function PageSize() { // page size object this.win = new WindowSize(); this.w = 0; this.h = 0; return this.update(); } PageSize.prototype.update = function() { var d = document; this.w = (window.innerWidth && window.scrollMaxX) ? window.innerWidth + window.scrollMaxX : (d.body.scrollWidth > d.body.offsetWidth) ? d.body.scrollWidth : d.body.offsetWidt; this.h = (window.innerHeight && window.scrollMaxY) ? window.innerHeight + window.scrollMaxY : (d.body.scrollHeight > d.body.offsetHeight) ? d.body.scrollHeight : d.body.offsetHeight; this.win.update(); if (this.w < this.win.w) this.w = this.win.w; if (this.h < this.win.h) this.h = this.win.h; return this; }; function PagePos() { // page position object this.x = 0; this.y = 0; return this.update(); } PagePos.prototype.update = function() { var d = document; this.x = (window.pageXOffset) ? window.pageXOffset : (d.documentElement && d.documentElement.scrollLeft) ? d.documentElement.scrollLeft : (d.body) ? d.body.scrollLeft : 0; this.y = (window.pageYOffset) ? window.pageYOffset : (d.documentElement && d.documentElement.scrollTop) ? d.documentElement.scrollTop : (d.body) ? d.body.scrollTop : 0; return this; }; function UserAgent() { // user agent information var ua = navigator.userAgent; this.isWinIE = this.isMacIE = false; this.isGecko = ua.match(/Gecko\//); this.isSafari = ua.match(/AppleWebKit/); this.isOpera = window.opera; if (document.all && !this.isGecko && !this.isSafari && !this.isOpera) { this.isWinIE = ua.match(/Win/); this.isMacIE = ua.match(/Mac/); this.isNewIE = (ua.match(/MSIE 5\.5/) || ua.match(/MSIE 6\.0/)); } this.isCompat = true; // true means quirks mode. if (document.compatMode) this.isCompat = (document.compatMode != 'CSS1Compat') return this; } // === indicator === function LinkIndicator(option) { var self = this; self.borderWidth = (option.borderWidth) ? option.borderWidth : '1px'; self._img = null; self._box = null; self._pos = new PagePos(); self._ua = new UserAgent(); self._page = new PageSize(); self._base = self._init_path(window.location); return self._init(option); } LinkIndicator.prototype = { _init : function(option) { var self = this; var d = document; if (!d.getElementsByTagName) return; var links = d.getElementsByTagName("a"); for (var i=0;i