1/********************************
2OSBib:
3A collection of PHP classes to create and manage bibliographic formatting for OS bibliography software
4using the OSBib standard.
5
6Released through http://bibliophile.sourceforge.net under the GPL licence.
7Do whatever you like with this -- some credit to the author(s) would be appreciated.
8
9If you make improvements, please consider contacting the administrators at bibliophile.sourceforge.net
10so that your improvements can be added to the release package.
11
12Adapted from WIKINDX: http://wikindx.sourceforge.net
13
14Mark Grimshaw 2005
15http://bibliophile.sourceforge.net
16
17	$Header: /cvsroot/bibliophile/OSBib/create/common.js,v 1.3 2005/06/29 20:22:05 sirfragalot Exp $
18********************************/
19
20function init(){ // init() is called in body.tpl
21 initPreviewLinks();
22}
23
24/**
25* Create the preview link for bibliographic style editing, hiding the link for non-javascript-enabled browsers.
26*
27* @author	Jess Collicott
28* @editor	Mark Tsikanovski and Mark Grimshaw
29* @version	2
30*/
31function initPreviewLinks(){ // collect any links for style template preview, add onclick events and make them visible
32 var previewLinkKeyString = 'action=previewStyle'; // use this string to detect Preview links
33 var previewLinkKeyRegEx = new RegExp(previewLinkKeyString,'i');
34 var links = document.getElementsByTagName('body').item(0).getElementsByTagName('a'); // get collection of all links
35 var linksLength = links.length; // cache
36
37// As of 3.1, style previewing is not working in IE so turn it off all together.
38var agt = navigator.userAgent.toLowerCase();
39  var is_ie = ((agt.indexOf("msie") != -1));
40  if (is_ie)
41  {
42	for (i=0;i<linksLength;i++)
43	{
44		if (typeof(links[i].href) != 'undefined' && links[i].href.search(previewLinkKeyRegEx) != -1)
45		{
46			links[i].className = 'linkHidden';
47		}
48	}
49	return;
50  }
51
52 for (i=0;i<linksLength;i++){
53  if (typeof(links[i].href) != 'undefined' && links[i].href.search(previewLinkKeyRegEx) != -1){
54    if (links[i].className == 'imgLink linkHidden') {
55	  links[i].className = 'imgLink linkCite';
56	}
57	else {
58      links[i].className = 'link linkCite';
59	}
60  }
61 }
62}
63
64/**
65* pop-up window for style previews
66*
67* @Author Mark Grimshaw with a lot of help from Christian Boulanger
68*/
69function openPopUpStylePreview(url, height, width, templateName)
70{
71	var fieldArray = new Array ("style_titleCapitalization", "style_primaryCreatorFirstStyle",
72			"style_primaryCreatorOtherStyle", "style_primaryCreatorInitials",
73			"style_primaryCreatorFirstName", "style_otherCreatorFirstStyle",
74			"style_otherCreatorOtherStyle", "style_otherCreatorInitials", "style_dayFormat",
75			"style_otherCreatorFirstName", "style_primaryCreatorList", "style_otherCreatorList",
76			"style_primaryCreatorListAbbreviationItalic", "style_otherCreatorListAbbreviationItalic",
77			"style_monthFormat", "style_editionFormat", "style_primaryCreatorListMore",
78			"style_primaryCreatorListLimit", "style_dateFormat",
79			"style_primaryCreatorListAbbreviation", "style_otherCreatorListMore",
80			"style_runningTimeFormat", "style_primaryCreatorRepeatString", "style_primaryCreatorRepeat",
81			"style_otherCreatorListLimit", "style_otherCreatorListAbbreviation", "style_pageFormat",
82			"style_editorSwitch", "style_editorSwitchIfYes", "style_primaryCreatorUppercase",
83			"style_otherCreatorUppercase", "style_primaryCreatorSepFirstBetween",
84			"style_primaryCreatorSepNextBetween", "style_primaryCreatorSepNextLast",
85			"style_otherCreatorSepFirstBetween", "style_otherCreatorSepNextBetween",
86			"style_otherCreatorSepNextLast", "style_primaryTwoCreatorsSep", "style_otherTwoCreatorsSep",
87			"style_userMonth_1", "style_userMonth_2", "style_userMonth_3", "style_userMonth_4",
88			"style_userMonth_5", "style_userMonth_6", "style_userMonth_7", "style_userMonth_8",
89			"style_userMonth_9", "style_userMonth_10", "style_userMonth_11", "style_userMonth_12",
90			"style_dateRangeDelimit1", "style_dateRangeDelimit2", "style_dateRangeSameMonth"
91		);
92	var styleArray = new Array ();
93	for (index = 0; index < fieldArray.length; index++)
94	{
95		var currFormField = document.forms[0][fieldArray[index]];
96		if ((currFormField.type == "checkbox") && currFormField.checked)
97			styleArray[fieldArray[index]] = "on"; // checkbox
98		else if (currFormField.type != "checkbox")
99			styleArray[fieldArray[index]] = currFormField.value; // input and textarea
100    }
101    var a_php = "";
102    var total = 0;
103    for (var key in styleArray)
104    {
105        ++ total;
106        a_php = a_php + "s:" +
107                String(key).length + ":\"" + String(key) + "\";s:" +
108                String(styleArray[key]).length + ":\"" + String(styleArray[key]) + "\";";
109    }
110    a_php = "a:" + total + ":{" + a_php + "}";
111    url = url + "&style=" + escape(a_php);
112	var templateString = document.forms[0][templateName].value;
113	url = url +"&templateName=" + escape(templateName) + "&templateString=" + escape(templateString);
114	var popUp = window.open(url,'popUp','height='+height,'width='+width,'status,scrollbars,resizable,dependent');
115}
116/* ===== common JavaScript functions ===== */
117
118// placeholder
119