var clientId = "eb"; var domain = "http://britannica.sharedbook.com/serve/smartbtn/" + clientId + "/"; function SharedBookSmartButton_aw() { // *********** Private members *********** var cookie_name = clientId + "_sbUserId"; // Timer ID var tid = null; // Count how many times setInterval(.) was called to allow max retries var interval_counter = 0; var printableUrl = document.location.href; var doc_url = document.location.href; doc_url = doc_url.split("#")[0]; // For example: http://www.britannica.com/EBchecked/topic/229851/geometry // any_machine_name.britannica.com:port // any_machine_name.britannica.net:port/ var printableUrl = 'http://www.britannica.com/EBchecked/sharedBookTopic/167647/dog'; try { var pattern = "http://\\S*\\.britannica\\.(com|net)(:\\d*)?/\\S*/topic/(\\d*)/([^/]*)\.*$"; var topic_id = doc_url.match(pattern)[3] var topic_name = doc_url.match(pattern)[4] printableUrl = "http://www.britannica.com/EBchecked/sharedBookTopic/" + topic_id + "/" + topic_name; } catch(err){} var userIdFromCookie = null; // ************************************************************************** // Privileged functions (public with access to private methods) // ************************************************************************** this.sharedbookAddArticle = function () { userIdFromCookie = new Date().getTime(); // This code generats "var add_article_success = 'True'". var add_article_url = encodeURI(domain + "add_url_generate_book.djs?user_id=" + userIdFromCookie + "&article_url=" + doc_url + "&scraping_url=" + printableUrl + '&sr=aw'); var add_article_script = document.createElement('script'); add_article_script.src = add_article_url; document.getElementsByTagName('head')[0].appendChild(add_article_script); // Display the blocking div. //document.getElementById("blockingDiv_aw").style.display = ""; centerAndShow('divTopLeft_aw', 'blockingDiv_aw'); tid = setInterval(handleAddURLToClipboard, 1000); function handleAddURLToClipboard() { if(typeof add_article_success != 'undefined' && add_article_success != null) { clearInterval(tid); tid = null; interval_counter = 0; if (add_article_success == "False") { // Reset to allow subsequent requests that will use the same var. add_article_success = null; // Hide the blocking div. document.getElementById("blockingDiv_aw").style.display = "none"; document.getElementById("divTopLeft_aw").style.display = "none"; alert("We're Sorry, but we are currently unable to 'Book' this page. This may be a temporary issue. Please try again later."); } //if (add_article_success == "True") else { var go_to_url = add_article_success + "&linkBack=" + doc_url + '&btnVer=aw'; top.document.location.href = encodeURI(go_to_url); } } else if (interval_counter++ > 120) { clearInterval(tid); interval_counter = 0; // Hide the blocking div. document.getElementById("blockingDiv_aw").style.display = "none"; document.getElementById("divTopLeft_aw").style.display = "none"; alert("We're Sorry, but we are currently unable to 'Book' this page. This may be a temporary issue. Please try again later."); } } }; // ************************************************************************** // Private functions // ************************************************************************** // ************************************************************************** // Functions for positioning the blocking div. // ************************************************************************** function getPageHeightWithScroll(){ if (window.innerHeight && (window.scrollMaxY!=null)) {// Firefox //console.log("FF logic: wih:"+window.innerHeight+" smY:" + window.scrollMaxY); return( window.innerHeight + window.scrollMaxY); } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac //console.log("Explorer Mac"); return(document.body.scrollHeight); } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari //console.log("Mozilla"); return(document.body.offsetHeight+document.body.offsetTop); } } function getPageWidthWithScroll(){ if (window.innerWidth && (window.scrollMaxX!=null)) {// Firefox //console.log('ff'); return( window.innerWidth + window.scrollMaxX); } else if (document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac //console.log('generic'); return(document.body.scrollWidth); } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari //console.log('last resort'); return(document.body.offsetWidth+document.body.offsetLeft); } } function getPageWidth() { if (window.innerWidth) {// Firefox return( window.innerWidth); } else if (document.documentElement.clientWidth!=0){ // strict mode return(document.documentElement.clientWidth); } else { // quirks mode return(document.body.clientWidth); } } function getPageHeight() { if (window.innerHeight) {// Firefox return( window.innerHeight); } else if (document.documentElement.clientHeight!=0){ // strict mode return(document.documentElement.clientHeight); } else { // quirks mode return(document.body.clientHeight); } } function getPageScrollHeight() { if((window.pageYOffset!=null)) { return(window.pageYOffset); } else { var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body; return iebody.scrollTop; } } function getPageScrollWidth() { if((window.pageXOffset!=null)) { return(window.pageXOffset); } else { var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body; return iebody.scrollLeft; } } function centerAndShow(id, parentid) { var pageHeight,pageWidth; elm=document.getElementById(id); parentElm=document.getElementById(parentid); parentElm.style.width=getPageWidthWithScroll()+'px'; // 20 parentElm.style.height=getPageHeightWithScroll()+'px'; // 20 parentElm.style.display = ''; elm.style.display = ''; pageHeight=getPageHeight(); pageWidth=getPageWidth(); elm.style.top= (pageHeight-elm.offsetHeight)/2+getPageScrollHeight()+'px'; elm.style.left= (pageWidth-elm.offsetWidth)/2+getPageScrollWidth()+'px'; var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body; iebody.style.overflow='hidden'; } // ************************************************************************** // END - functions for positioning the blocking div. // ************************************************************************** } // Important: client name turns to directory name, keep it lower case ! var sbSmartBtnObj_aw = new SharedBookSmartButton_aw(); var dws = "" dws += ''; dws += ''; dws += ''; //var blocking_div_html = ''; var blocking_div_html_aw = ' '; //var blocking_div_html = ''; // if (!window.smartBtnGM) { document.write(dws); } else { // FF plugin smartBtnGM.buttonContainerElement.innerHTML += dws; var divTag = document.createElement("div"); divTag.innerHTML = blocking_div_html_aw; document.getElementsByTagName("body")[0].appendChild(divTag); } var bodyElems = document.getElementsByTagName("body"); if (bodyElems && bodyElems[0]) { var bodyTag = bodyElems[0]; function addBlockingDiv_aw() { var divTag_aw = document.createElement("div"); divTag_aw.innerHTML = blocking_div_html_aw; bodyTag.appendChild(divTag_aw); } if (window.addEventListener){ // FF window.addEventListener('load', addBlockingDiv_aw, false); } else if (window.attachEvent){ // IE window.attachEvent('onload', addBlockingDiv_aw); } }