From 9b1ba47d51651884f2125eed64f553a23bb103ea Mon Sep 17 00:00:00 2001 From: JJfutbol Date: Wed, 8 Jul 2009 00:58:37 +0000 Subject: - updated readability start with new bookmarklet code, added comments - small tweaks to readability algorithm git-svn-id: http://arc90labs-readability.googlecode.com/svn/trunk@59 d4e419ec-0920-11de-bbfd-a7c1bc4c261e --- js/readability-start.js | 70 +++++++++++++++++++++++++++++++------------------ js/readability.js | 2 +- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/js/readability-start.js b/js/readability-start.js index ae90443..4263ab2 100755 --- a/js/readability-start.js +++ b/js/readability-start.js @@ -1,52 +1,70 @@ -var style = "style-newspaper"; -var size = "size-large"; -var margin = "margin-wide"; +var defaultMargin = "margin-wide"; +var defaultSize = "size-large"; +var defaultStyle = "style-newspaper"; var baseHref = window.location.toString().match(/.*\//); +var linkStart = "javascript:(function(){"; +var linkEnd = "var elements=document.getElementsByTagName('HEAD');var headElement;if(elements.length>=1){headElement=elements[0];}else{headElement=document.createElement('HEAD');document.documentElement.appendChild(headElement);}_readability_script=document.createElement('SCRIPT');_readability_script.type='text/javascript';_readability_script.src='" + basehref + "js/readability.js?x='+(Math.random());headElement.insertBefore(_readability_script,headElement.firstChild);_readability_css=document.createElement('LINK');_readability_css.rel='stylesheet';_readability_css.href='" + basehref + "css/readability.css';_readability_css.type='text/css';headElement.insertBefore(_readability_css,headElement.firstChild);_readability_print_css=document.createElement('LINK');_readability_print_css.rel='stylesheet';_readability_print_css.href='" + basehref + "css/readability-print.css';_readability_print_css.media='print';_readability_print_css.type='text/css';headElement.insertBefore(_readability_print_css,headElement.firstChild);})();"; -var linkStringStart = "javascript:(function(){"; -var linkStringEnd = "';_readability_script=document.createElement('SCRIPT');_readability_script.type='text/javascript';_readability_script.src='" + baseHref + "js/readability.js?x='+(Math.random());document.getElementsByTagName('head')[0].appendChild(_readability_script);_readability_css=document.createElement('LINK');_readability_css.rel='stylesheet';_readability_css.href='" + baseHref + "css/readability.css';_readability_css.type='text/css';_readability_css.media='screen';document.getElementsByTagName('head')[0].appendChild(_readability_css);_readability_print_css=document.createElement('LINK');_readability_print_css.rel='stylesheet';_readability_print_css.href='" + baseHref + "css/readability-print.css';_readability_print_css.media='print';_readability_print_css.type='text/css';document.getElementsByTagName('head')[0].appendChild(_readability_print_css);})();"; - -$(document).ready(function() { - - $("#bookmarkletLink").attr("href", linkStringStart + "readStyle='" + style + "';readSize='" + size + "';readMargin='" + margin + linkStringEnd); +$(document).ready(function() +{ + // load example with defaults + applyChange("margin", defaultMargin); + applyChange("size", defaultSize); + applyChange("style", defaultStyle); - function applyChange(s,y) { + // helper that takes the user input and customizes the bookmarklet source + function applyChange(property, value) + { var example = document.getElementById("example"); var article = document.getElementById("articleContent"); + var size, style, margin; - switch(s){ - case "style": - style = y; - break - case "size": - size = y; - break + // determine the property that is being changed + switch (property) + { case "margin": - margin = y; - break + margin = value; + break; + + case "size": + size = value; + break; + + case "style": + style = value; + break; } + + // update the presentation of the example content example.className = style; article.className = margin + " " + size; - $("#bookmarkletLink").attr("href", linkStringStart + "readStyle='" + style + "';readSize='" + size + "';readMargin='" + margin + linkStringEnd); + + // update the bookmarklet source + $("#bookmarkletLink").attr("href", linkStart + "readStyle='" + style + "';readSize='" + size + "';readMargin='" + margin + "';" + linkEnd); } $("#settings input").bind("click", function(){ applyChange(this.name, this.value); }); + $("#settings input").bind("click", function(){ applyChange(this.name, this.value); }); + + // the user needs to drag the bookmarklet link to their bookmarks bar, but + // if they don't notify them what to do (unique case for IE) $("#bookmarkletLink").bind("click", function(){ - if($.browser.msie){ + if ($.browser.msie) + { alert("To start using Readability, right-click and select 'Add To Favorites...' to save this link to your browser's bookmarks toolbar."); - } - else { + } + else + { alert("To start using Readability, drag this link to your browser's bookmarks toolbar."); } + return false; }); - -}); - +}); \ No newline at end of file diff --git a/js/readability.js b/js/readability.js index 6b53a15..5619c38 100755 --- a/js/readability.js +++ b/js/readability.js @@ -508,7 +508,7 @@ function removeNonContentElement(element, tagName) { // the number of non-paragraph elements is more than actual // paragraphs or other ominous signs (:) and elements - if (img > p || li >= p || a >= p || p == 0 || embed > 0) + if (img > p || li > p || a > p || p == 0 || embed > 0) { descendant.parentNode.removeChild(descendant); } -- cgit v1.2.3