// By Richard Harrison for S8Design.co.uk function ViralLinkManager(target, imgDir, rows, showAdvice, adviceType, styles) { // construction arguments are optional with defaults - if not given or only placeholder // elements (empty string '')* are provided, the following "vl" prefixed values apply // {target} is id(s) of HTML div element to which to write viral linking HTML after composing // it; default is one target per page with id="_vlTarget_"...multiple are allowed, but current // handling presumes same layout for all instances // *NOTE: showAdvice must be true/false // variable, object-global, default, configuration parameters start here - - - - - - - - - // these will be overridden at construction, if corresponding arguments are provided var vlTarget = ['vlTarget']; // HTML target element's (probably a div) id var vlImgDir = 'images/viralLinking/'; // subdirectory from which to get images for links var vlRows = 1; // how many rows of icons for display layout var vlShowAdvice = true; // whether to display advice text var vlAdviceType = 'inline'; // where to show advice, if used...inline or top var vlStyles = 'css/viralLinking.css'; // style-sheet for viral linking var vlAddStyles = false; // assume external style-sheet already included // variable, object-global, default, configuration parameters end here - - - - - - - - - - // utility functions function get(eid) { return document.getElementById(eid); } ; function getBT(tag) { return document.getElementsByTagName(tag); } ; // top type advice strings vary by number of rows of icons as: // 1 row ==> [0], 2 rows ==> [1], 3 rows ==> [2], etc. var vlAdvice = [ ['Social bookmarking and email links...', ' share this page via social sites or email ' ], ['Spread the word...', ' tell others about page ' ], ['Send a link...', ' notify others ' ], ['Share it...', ' send links ' ], ['Share...', ' link this ' ] ] ; // private data to construct anchors for viral linking var vlLinksArray = [ // URL to request parameters to add to (implicit) GET display name display image // ---------------------------------- ------------------------------------------------------------- ---------------- ------------------- ['blogmarks.net/my/new.php', 'mini=1&simple=1&url=_vlUrl_%2F&title=_vlTitle_"', 'blogmarks', 'blogmarks.png' ], ['del.icio.us/post', 'url=_vlUrl_%2F&title=_vlTitle_', 'del.icio.us', 'delicious.png' ], ['digg.com/submit', 'phase=2&url=_vlUrl_%2F&title=_vlTitle_', 'Digg', 'digg.png' ], ['www.facebook.com/sharer.php', 'u=_vlUrl_%2F&t=_vlTitle_', 'Facebook', 'facebook.png' ], ['www.furl.net/storeIt.jsp', 'u=_vlUrl_%2F&t=_vlTitle_', 'Furl', 'furl.png' ], ['www.google.com/bookmarks/mark', 'op=edit&bkmk=_vlUrl_%2F&title=_vlTitle_', 'Google', 'googlebookmark.png' ], ['www.mixx.com/submit', 'page_url=_vlUrl_%2F&title=_vlTitle_', 'Mixx', 'mixx.png' ], ['www.indianpad.com/submit.php', 'url=_vlUrl_%2F', 'IndianPad', 'indianpad.png' ], ['reddit.com/submit', 'url=_vlUrl_%2F&title=_vlTitle_', 'Reddit', 'reddit.png' ], ['www.sphere.com/search', 'q=sphereit:_vlUrl_%2F&title=_vlTitle_', 'SphereIt', 'sphere.png' ], ['sphinn.com/submit.php', 'url=_vlUrl_%2F&title=_vlTitle_', 'Sphinn', 'sphinn.png' ], ['www.spurl.net/spurl.php', 'url=_vlUrl_%2F&title=_vlTitle_', 'Spurl', 'spurl.png' ], ['www.stumbleupon.com/submit', 'url=_vlUrl_%2F&title=_vlTitle_', 'StumbleUpon', 'stumbleupon.png' ], ['technorati.com/faves', 'add=_vlUrl_%2F', 'Technorati', 'technorati.png' ], ['mailto:', 'subject=Check%20this%20site:%20_vlUrl_', 'Email a Friend', 'email.gif' ] ] ; // capture URL info for current page - this is what will be passed in calls to social // bookmarking sites and in e-mails to friends var vlUrl = encodeURI(window.location.toString()); // replace all embedded blanks with plus-signs var vlTitle = encodeURI(getBT('TITLE')[0].innerHTML.toString().replace(/ /g, '+')); function addViralLinking(){ if (vlAddStyles) { // add viral linking styles to page - will not work in Safari, which doesn't support // dynamic additions of new element to head block of HTML by JavaScript/DOM // operations - if you're supporting Safari, an external style-sheet MUST be included // to the HTML directly...further, if you're supporting Safari and including a // style-sheet to the head of the page, don't notify this object, i.e., don't include // a {styles} argument at construction, or the link will appear twice in non-Safari // browsers if (-1 != navigator.userAgent.indexOf('Apple')) { var s = document.createElement('LINK'); s.rel = 'stylesheet'; s.type = 'text/css'; s.media = 'screen'; s.href = vlStyles; var h = getBT('HEAD')[0]; h.appendChild(s); } } // create HTML for viral links var last = vlLinksArray.length; var w = Math.ceil(20*last/vlRows + (('inline' == vlAdviceType && vlShowAdvice)?60:0)) + 'px'; var vl = '
'; // insert to target container{s} in HTML var last = vlTarget.length; for (var i = 0; i < last; i++) { get(vlTarget[i]).innerHTML = vl; } } ; this.getVlTarget = function() {return vlTarget;} ; // construction steps - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // process arguments: target, imgDir, rows, showAdvice, adviceType, styles if ('undefined' != typeof targets && '' != targets) vlTarget = targets; if ('undefined' != typeof imgDir && '' != imgDir) vlImgDir = imgDir; if ('undefined' != typeof rows && '' != rows) vlRows = rows; if ('undefined' != typeof showAdvice) vlShowAdvice = showAdvice; if ('undefined' != typeof adviceType && '' != adviceType) vlAdviceType = adviceType; if ('undefined' != typeof styles && '' != styles) { vlStyles = styles; // name of external style-sheet to add to head of current page vlAddStyles = true; // tell object to add link element to page } addViralLinking(); // write link contents to page } ;