(function() { function openFrame() { var baseUrl = 'https://www.readability.com', frameUrl = baseUrl + '/static/embed/embed.html', frameStyles = null, frameHtml = null, frameContainerStyles = null, frameContainerHtml = null, rdbWrapper = document.getElementById('rdbWrapper'); if(rdbWrapper) { var queryStrings = [], textColor = rdbWrapper.getAttribute('data-text-color'), bgColor = rdbWrapper.getAttribute('data-bg-color'); // Todo: Turn this into a loop of all data- attributes if this gets any bigger if (textColor) { queryStrings.push('textColor=' + encodeURIComponent(textColor)); } if (bgColor) { queryStrings.push('bgColor=' + encodeURIComponent(bgColor)); } if(queryStrings.length > 0) { frameUrl += '?' + queryStrings.join('&'); } } frameStyles = [ "width: 175px", "height: 35px", "overflow: hidden", "border-width: 0", "white-space: nowrap" ].join(';'); // As string for IE7 Bug where it won't work as an object. The JS only gets executed if innerHTML is used for some reason. frameHtml = [ '' ].join(' '); frameContainerStyles = [ "height: 35px", "padding: 0", "margin: 0", "backgroundColor: rgba(255,255,255,0.95)", "zIndex: 2147483647" ].join(';'); frameContainerHtml = [ '
', frameHtml, '
' ].join(' '); if(rdbWrapper) { rdbWrapper.innerHTML = frameContainerHtml; } else { document.write(frameContainerHtml); } } function inject_script(url) { var h = document.createElement('script'); h.setAttribute('type','text/javascript'); h.setAttribute('charset','UTF-8'); h.setAttribute('src', url); document.documentElement.appendChild(h); } // Cross browser addEventListener from http://snipplr.com/view.php?codeview&id=3116 function listen(evnt, elem, func) { if (elem.addEventListener) { // W3C DOM return elem.addEventListener(evnt,func,false); } else if (elem.attachEvent) { // IE DOM return elem.attachEvent("on"+evnt, func); } else { return false; } } listen("message", window, receiveMessage); function receiveMessage(event) { var baseUrl = 'https://www.readability.com'; if (event.origin === baseUrl) { if (event.data == 'read') { inject_script(baseUrl + '/bookmarklet/read.js'); } else if (event.data == 'queue') { inject_script(baseUrl + '/bookmarklet/save.js'); } else if (event.data.indexOf('set_token') === 0) { window.readabilityToken = event.data.replace('set_token=', ''); } } } var hasToken = document.cookie.indexOf('readabilityToken=') !== -1; if(hasToken) { window.readabilityToken = document.cookie.match(/readabilityToken=([^;]+)/)[1]; } else { window.readabilityToken = null; } openFrame(); })();