Changeset 13427


Ignore:
Timestamp:
2006-12-06T10:51:59+13:00 (17 years ago)
Author:
shaoqun
Message:

added javascript and new macros for printing a document page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/macros/document.dm

    r13370 r13427  
    1313_phindclassifier_ {}
    1414_collageclassifier_ {}
     15
    1516# custom header for individual document
    1617_documentheader_ {}
    1718
     19#custom css links for individual document
     20_csslink_{
     21   <link rel="stylesheet" href="_cssfilelink_" type="text/css"
     22    charset="UTF-8"   _linktagend_
     23  <link rel="alternate stylesheet" href="_httpimg_/preview-document.css" type="text/css"
     24    title="Preview Document" charset="UTF-8" media="screen"  _linktagend_
     25   <link rel="stylesheet" href="_httpimg_/print-document.css" type="text/css"
     26    charset="UTF-8" media="print"  _linktagend_
     27}
    1828
    1929#######################################################################
     
    241251_imagedetach_ {<div class="button"><span class="button"><a href="_httpcurrentdocument_&amp;x=1" target="\_blank" title="_texticondetach_">_textDETACH_</a></span></div>}
    242252
     253_imageprint_{<div class="button"><span class="button"><a href="javascript:print_preview()">_textPRINT_</a></span></div>}
     254
     255
    243256_imagehighlight_ {_docbutton_(_httpcurrentdocument_&amp;hl=1&amp;gc=_cgiarggc_&amp;gt=_cgiarggt_,_textHIGHLIGHT_,_texticonhighlight_)}
    244257
     
    255268_imagecont_ {_docbutton_(_httpcurrentdocument_&amp;gt=2,_textCONTINUE_,_texticoncont_)}
    256269
     270
     271#######################################################################
     272# print preview script
     273#######################################################################
     274
     275
     276_pagescriptextra_{
     277
     278 var style_display_old;
     279 var show = true;
     280
     281 function has_toc(){
     282     var div_nodes = document.getElementsByTagName("div");   
     283     for (var i=0;i < div_nodes.length ; i++ )\{
     284          var div_node = div_nodes[i];
     285          if (div_node.className =="toc" && div_node.childNodes.length > 1)
     286             \{
     287                 return true;
     288             \}
     289      \}
     290   
     291    return false;
     292 \}
     293
     294 function hide_toc()\{
     295     var div_nodes = document.getElementsByTagName("div");   
     296     for (var i=0;i < div_nodes.length ; i++ )\{
     297          var div_node = div_nodes[i];
     298          if (div_node.className =="toc")
     299             \{
     300               style_display_old = div_node.style.display;
     301               div_node.style.display = "none";
     302             \};
     303      \} 
     304
     305 \} 
     306
     307 
     308 function show_toc()\{
     309 
     310     var div_nodes = document.getElementsByTagName("div");   
     311     for (var i=0;i < div_nodes.length ; i++ )\{
     312          var div_node = div_nodes[i];
     313          if (div_node.className =="toc")
     314             \{
     315               div_node.style.display = style_display_old;
     316           
     317             \};
     318      \}
     319
     320 \} 
     321
     322 
     323  function switch_toc()\{
     324     var toc_link =  document.getElementById("toc_link");
     325       while (toc_link.hasChildNodes()) \{
     326          toc_link.removeChild(toc_link.firstChild);
     327    \} 
     328    if (show)\{
     329        toc_link.appendChild(document.createTextNode('Show the table of content'));
     330        show = false;
     331        hide_toc();
     332    \}
     333  else\{
     334       toc_link.appendChild(document.createTextNode('Hide the table of content'));
     335      show = true;
     336      show_toc();
     337    \}
     338
     339  \}
     340   
     341  function print_preview() \{
     342   // Switch the stylesheet
     343    setActiveStyleSheet("Preview Document");
     344    add_print_message();
     345  \}
     346
     347  function add_print_message()\{
     348     if (document.getElementById)\{
     349        var print_message = document.createElement('ul');
     350        print_message.id = 'print-message';
     351            print_message.className = "printmessage"; 
     352       
     353         var cancel_print_link = document.createElement('li');
     354         cancel_print_link.className = "cancelprint"
     355         cancel_print_link.onclick = function()\{ cancel_print(); return false;\};
     356         cancel_print_link.appendChild(document.createTextNode('Return to the original page'));
     357          print_message.appendChild(cancel_print_link); 
     358
     359         
     360           var print_link = document.createElement('li');
     361           print_link.onclick = function()\{ window.print(); return false;\};
     362           print_link.appendChild(document.createTextNode('Print this page'));
     363           print_message.appendChild(print_link);
     364
     365    if (has_toc())\{ 
     366      var toc_link = document.createElement('li');
     367          toc_link.id = "toc_link";
     368          toc_link.onclick = function()\{ switch_toc(); return false;\};
     369          toc_link.appendChild(document.createTextNode('Hide the table of content'));                 
     370          print_message.appendChild(toc_link);   
     371         \}
     372
     373         //insert the print message node
     374         var div_nodes = document.getElementsByTagName("div");   
     375         for (var i=0;i < div_nodes.length ; i++ )\{
     376            var div_node = div_nodes[i];
     377             if (div_node.className =="document")\{         
     378                 var parent = div_node.parentNode;
     379                 parent.insertBefore(print_message,div_node);
     380           \}
     381        \}
     382     \}
     383
     384  \}
     385 
     386 
     387 function cancel_print() \{
     388    // Destroy the preview message
     389   var print_message = document.getElementById('print-message');
     390   var parent = print_message.parentNode;
     391   parent.removeChild(print_message);
     392   
     393    show_toc();
     394    // Switch back stylesheet
     395    setActiveStyleSheet("default");
     396  \}
     397
     398 function setActiveStyleSheet(title) \{
     399    var i, a, main;
     400    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) \{
     401      if(a.getAttribute("rel").indexOf("style") != -1
     402         && a.getAttribute("title")) \{
     403        a.disabled = true;
     404        if(a.getAttribute("title") == title) a.disabled = false;
     405    \}
     406   \ }
     407  \}
     408
     409}
    257410
    258411
     
    283436</div> <!-- document:footer -->
    284437
    285 <p>
     438<div class="navarrowsbottom">
    286439_navarrowsbottom_
    287 </p>
     440</div>
    288441_endspacer__htmlfooter_
    289442}
Note: See TracChangeset for help on using the changeset viewer.