home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 April / PCWorld_2008-04_cd.bin / v cisle / ozo / zotero-1.0.3.xpi / chrome / zotero.jar / content / zotero / bibliography.js < prev    next >
Encoding:
JavaScript  |  2008-01-13  |  5.2 KB  |  164 lines

  1. /*
  2.     ***** BEGIN LICENSE BLOCK *****
  3.     
  4.     Copyright (c) 2006  Center for History and New Media
  5.                         George Mason University, Fairfax, Virginia, USA
  6.                         http://chnm.gmu.edu
  7.     
  8.     Licensed under the Educational Community License, Version 1.0 (the "License");
  9.     you may not use this file except in compliance with the License.
  10.     You may obtain a copy of the License at
  11.     
  12.     http://www.opensource.org/licenses/ecl1.php
  13.     
  14.     Unless required by applicable law or agreed to in writing, software
  15.     distributed under the License is distributed on an "AS IS" BASIS,
  16.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.     See the License for the specific language governing permissions and
  18.     limitations under the License.
  19.     
  20.     ***** END LICENSE BLOCK *****
  21. */
  22.  
  23. //////////////////////////////////////////////////////////////////////////////
  24. //
  25. // Zotero_File_Interface_Bibliography
  26. //
  27. //////////////////////////////////////////////////////////////////////////////
  28.  
  29. // Class to provide options for bibliography
  30.  
  31. var Zotero_File_Interface_Bibliography = new function() {
  32.     var _io, _saveStyle;
  33.     
  34.     this.init = init;
  35.     this.styleChanged = styleChanged;
  36.     this.acceptSelection = acceptSelection;
  37.     
  38.     /*
  39.      * Initialize some variables and prepare event listeners for when chrome is done
  40.      * loading
  41.      */
  42.     function init() {
  43.         // Set font size from pref
  44.         // Affects bibliography.xul and integrationDocPrefs.xul
  45.         var sbc = document.getElementById('zotero-bibliography-container');
  46.         Zotero.setFontSize(sbc);
  47.         
  48.         _io = window.arguments[0];
  49.         if(_io.wrappedJSObject){
  50.             _io = _io.wrappedJSObject;
  51.         }
  52.         
  53.         var listbox = document.getElementById("style-listbox");
  54.         var styles = Zotero.Cite.getStyles();
  55.         
  56.         // if no style is set, get the last style used
  57.         if(!_io.style) {
  58.             _io.style = Zotero.Prefs.get("export.lastStyle");
  59.             _saveStyle = true;
  60.         }
  61.         
  62.         // add styles to list
  63.         var index = 0;
  64.         for (var i in styles) {
  65.             var itemNode = document.createElement("listitem");
  66.             itemNode.setAttribute("value", i);
  67.             itemNode.setAttribute("label", styles[i]);
  68.             listbox.appendChild(itemNode);
  69.             
  70.             if(i == _io.style) {
  71.                 var selectIndex = index;
  72.             }
  73.             index++;
  74.         }
  75.         
  76.         if (selectIndex < 1) {
  77.             selectIndex = 0;
  78.         }
  79.         
  80.         // Can't select below-the-fold listitems inline in Firefox 2, because that would be too easy
  81.         setTimeout(function () {
  82.             listbox.ensureIndexIsVisible(selectIndex);
  83.             listbox.selectedIndex = selectIndex;
  84.         }, 1);
  85.         
  86.         // ONLY FOR bibliography.xul: export options
  87.         if(document.getElementById("save-as-rtf")) {
  88.             // restore saved bibliographic settings
  89.             document.getElementById(Zotero.Prefs.get("export.bibliographySettings")).setAttribute("selected", "true");
  90.             
  91.             // disable clipboard on the Mac, because it can't support formatted
  92.             // output
  93.             if(Zotero.isMac) {
  94.                 document.getElementById("mac-clipboard-warning").hidden = false;
  95.             }
  96.         }
  97.         
  98.         // ONLY FOR integrationDocPrefs.xul: update status of displayAs, set
  99.         // bookmarks text
  100.         if(document.getElementById("displayAs")) {
  101.             if(_io.useEndnotes && _io.useEndnotes == 1) document.getElementById("displayAs").selectedIndex = 1;
  102.             styleChanged(selectIndex);
  103.             
  104.             if(_io.useBookmarks && _io.useBookmarks == 1) document.getElementById("formatUsing").selectedIndex = 1;            
  105.             if(_io.openOffice) {
  106.                 var formatOption = "referenceMarks";
  107.             } else {
  108.                 var formatOption = "fields";
  109.             }
  110.             document.getElementById("fields").label = Zotero.getString("integration."+formatOption+".label");
  111.             document.getElementById("fields-caption").textContent = Zotero.getString("integration."+formatOption+".caption");
  112.             
  113.             // add border on Windows
  114.             if(Zotero.isWin) {
  115.                 document.getElementById("doc-prefs-dialog").style.border = "1px solid black";
  116.             }
  117.         }
  118.         window.sizeToContent();
  119.         window.centerWindowOnScreen();
  120.     }
  121.     
  122.     /*
  123.      * ONLY FOR integrationDocPrefs.xul: called when style is changed
  124.      */
  125.     function styleChanged(index) {
  126.         // When called from init(), selectedItem isn't yet set
  127.         if (index != undefined) {
  128.             var selectedItem = document.getElementById("style-listbox").getItemAtIndex(index);
  129.         }
  130.         else {
  131.             var selectedItem = document.getElementById("style-listbox").selectedItem;
  132.         }
  133.         
  134.         var selectedStyle = selectedItem.getAttribute('value');
  135.         
  136.         // update status of displayAs box based
  137.         
  138.         var styleClass = Zotero.Cite.getStyleClass(selectedStyle);
  139.         document.getElementById("displayAs").disabled = styleClass != "note";
  140.     }
  141.  
  142.     function acceptSelection() {
  143.         // collect code
  144.         _io.style = document.getElementById("style-listbox").selectedItem.value;
  145.         if(document.getElementById("output-radio")) {
  146.             // collect settings
  147.             _io.output = document.getElementById("output-radio").selectedItem.id;
  148.             // save settings
  149.             Zotero.Prefs.set("export.bibliographySettings", _io.output);
  150.         }
  151.         
  152.         // ONLY FOR integrationDocPrefs.xul: collect displayAs
  153.         if(document.getElementById("displayAs")) {
  154.             _io.useEndnotes = document.getElementById("displayAs").selectedIndex;
  155.             _io.useBookmarks = document.getElementById("formatUsing").selectedIndex;
  156.         }
  157.         
  158.         // save style (this happens only for "Export Bibliography," or Word
  159.         // integration when no bibliography style was previously selected)
  160.         if(_saveStyle) {
  161.             Zotero.Prefs.set("export.lastStyle", _io.style);
  162.         }
  163.     }
  164. }