plugins/org.symbian.tools.wrttools.doc.WebDeveloper/html/js/page.js
changeset 470 d4809db37847
parent 229 716254ccbcc0
equal deleted inserted replaced
469:4d198a32ac7d 470:d4809db37847
       
     1 // TODO: move these constants to common.js
       
     2 var URL_BASE = "index.html"; 
       
     3 var URL_SEPARATOR = "?content=";
       
     4 var URL_SEPARATOR_PATTERN = "\\?content=(.+)$";
       
     5 
       
     6 /**
       
     7  * Initialize links
       
     8  */
       
     9 function initPage() {
       
    10   initialTocSync();
       
    11   /*
       
    12     if (tocSupported) {
       
    13         var as = document.getElementsByTagName("a");
       
    14         for (var i = 0; i < as.length; i++) {
       
    15             attachEventListener(as[i], "click", syncTocHandler);
       
    16             if (as[i].addEventListener) {
       
    17                 as[i].addEventListener("mousedown", syncTocHandler, false);
       
    18             } else if (as[i].attachEvent) {
       
    19                 as[i].setAttribute("onmousedown", syncTocHandlerIE);    
       
    20             }
       
    21         }
       
    22     }
       
    23     */    
       
    24 }
       
    25 
       
    26 /**
       
    27  * Do initial TOC synchronization.
       
    28  */
       
    29 function initialTocSync() {
       
    30       if (automaticSync) {
       
    31           var baseUrl = getBaseUrl();
       
    32           var contentUrl = String(window.location);
       
    33           var href = getRelativeUrl(contentUrl, baseUrl);
       
    34           findTocItem(href);
       
    35     }
       
    36 }
       
    37 
       
    38 /**
       
    39  * TOC sync
       
    40  */
       
    41 function syncTocHandler(event) {
       
    42     if (tocSupported) {
       
    43         var n = getTargetNode(event);
       
    44         var href = n.getAttribute("href");
       
    45         /*
       
    46         if (isClass(n, "javadoc_ref")) {
       
    47         if (href.indexOf('#') != -1) {
       
    48             href = href.substring(0, url.indexOf('#'));
       
    49         }
       
    50       var a = href.split("/");
       
    51       var last = a.length - 1;
       
    52       while (a[last].indexOf(".") != -1) {
       
    53           last--;
       
    54       }
       
    55       a = a.slice(0, last + 1);
       
    56       href = a.join("/") + "/package-summary.html";
       
    57       alert(n.getAttribute("href") + "\n" + href);
       
    58         }
       
    59         */
       
    60     findTocItem(href);
       
    61     }
       
    62 }
       
    63 
       
    64 /**
       
    65  * Find current TOC node.
       
    66  *
       
    67  * TODO: move to common.js
       
    68  */
       
    69 function findTocItem(url) {
       
    70     if (tocSupported) {
       
    71         var u = url;
       
    72         if (url.indexOf('#') != -1) {
       
    73             u = u.substring(0, url.indexOf('#'));
       
    74         }
       
    75     var baseUrl = getBaseUrl();        
       
    76         if (!window.parent.frames.toc) { return; }
       
    77         var d = window.parent.frames.toc.document;
       
    78         var aes = d.getElementsByTagName(TOC_ELEMENT_LINK);
       
    79         for (var i = 0; i < aes.length; i++) {
       
    80             if (compareTocUrl(aes[i], getRelativeUrl(aes[i].href, baseUrl), u)) {
       
    81                 highlightTocItem(aes[i]);
       
    82                 // make sure TOC is expanded if needed
       
    83                 var item = aes[i].parentNode;
       
    84                 /*
       
    85         if (childCollapse) {
       
    86           collapseChildBlocks(item);
       
    87         }
       
    88         */                   
       
    89                 while (item != null) {
       
    90                     if (item.parentNode && item.parentNode.nodeName.toLowerCase() == TOC_ELEMENT_BLOCK &&
       
    91                             item.parentNode.parentNode && item.parentNode.parentNode.nodeName.toLowerCase() == TOC_ELEMENT_ITEM) {
       
    92                         item = item.parentNode.parentNode;
       
    93                       if (item.firstChild && item.firstChild.firstChild && item.firstChild.firstChild.data == TOC_SYMBOL_COLLAPSED) {
       
    94                           //toggle(n.firstChild);
       
    95                           tocNodeExpand(item.firstChild, false);
       
    96                       }
       
    97                     } else {
       
    98                         item = null;    
       
    99                     }
       
   100                 }
       
   101                 break;
       
   102             }
       
   103         }
       
   104     }
       
   105 }
       
   106 
       
   107 /**
       
   108  * Compare TOC link URL with document URL.
       
   109  *
       
   110  * TODO: move to common.js
       
   111  *
       
   112  * @param link TOC link element
       
   113  * @param tocUrl Relative TOC url
       
   114  * @param docUrl Relative document URL
       
   115  */
       
   116 function compareTocUrl(link, tocUrl, docUrl) {
       
   117   var _tocUrl = tocUrl.replace("\\", "/");
       
   118   var _docUrl = docUrl.replace("\\", "/");
       
   119   return _tocUrl === _docUrl; 
       
   120 }
       
   121 
       
   122 var infoWindow;
       
   123 
       
   124 /**
       
   125  * Open info window.
       
   126  *
       
   127  * @param event activation event
       
   128  */
       
   129 function openInfo(href) {
       
   130   //var target = getTargetNode(event)
       
   131   //var href = target.getAttribute("href");
       
   132   
       
   133   if(infoWindow == null || infoWindow.closed) {
       
   134     var width = 450;
       
   135     var height = 110 + 20;
       
   136     var left = window.screen.width / 2 - width;
       
   137     var top = window.screen.height / 2 - height;
       
   138     var infoWindow = window.open(href, "info",
       
   139         "left=" + left + ",top=" + top + ",height=" + height + ",width=" + width
       
   140         + ",menubar=no,toolbar=no,location=no,status=no,scrollbars=no,resizable=yes");
       
   141   } else {
       
   142     infoWindow.location = href;
       
   143   }  
       
   144   infoWindow.focus();
       
   145   
       
   146   if (event.stopPropagation) {
       
   147     event.stopPropagation();
       
   148   } else {
       
   149     event.cancelBubble = true;
       
   150   }
       
   151   if (event.preventDefault) {
       
   152     event.preventDefault();
       
   153   } else {
       
   154     event.returnValue = false;
       
   155   }
       
   156 
       
   157   return false;
       
   158 }