summaryrefslogtreecommitdiff
path: root/js/readability-start.js
blob: ae90443a1c43ab22bc0890914777cff0255c31c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var style = "style-newspaper";
var size = "size-large";
var margin = "margin-wide";

var baseHref = window.location.toString().match(/.*\//);


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);
	
	function applyChange(s,y) {
		var example = document.getElementById("example");
		var article = document.getElementById("articleContent");
		
		switch(s){
			case "style":
				style = y;
				break
			case "size":
				size = y;
				break
			case "margin":
				margin = y;
				break
		}
		example.className = style;
		article.className = margin + " " + size;
		$("#bookmarkletLink").attr("href", linkStringStart + "readStyle='" + style + "';readSize='" + size + "';readMargin='" + margin + linkStringEnd);
	}
	
	$("#settings input").bind("click", function(){
		applyChange(this.name, this.value);
	});
	$("#settings input").bind("click", function(){
		applyChange(this.name, this.value);
	});
	$("#bookmarkletLink").bind("click", function(){
		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 {
			alert("To start using Readability, drag this link to your browser's bookmarks toolbar.");
		}
		return false;
	});

});