aboutsummaryrefslogtreecommitdiffstats
path: root/draklive/9/et/content/main.js
blob: 457dfe1aa029dcdfb42efa1b76737ce5227fa225 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/* global stemmer */

/**
 * Miscellaneous js functions for WebHelp
 * Kasun Gajasinghe, http://kasunbg.blogspot.com
 * David Cramer, http://www.thingbag.net
 *
 */

function adjust(){
  var headerHeight = $("#header").outerHeight( true );
  $("#leftnavigation").css('top' , headerHeight);
  if(document.body.clientWidth >= 701)
    $("#content").css('top' , headerHeight+'px');
  else
    $("#content").css('top' , 0+'px');
}

$( window ).resize(function() {
  adjust();
});

$(document).ready(function() {  
  adjust();

  var href = window.location.href;
  var indexOfTermToSearch = href.indexOf('?search=');
  if (indexOfTermToSearch !== -1)
  {
    var term = decodeURI(href.substring(indexOfTermToSearch+8));
    $('#textToSearch').val(term);
    document.cookie='textToSearch='+term;
    searchHighlight(term);
  }

    $(function() {
            $("#tabs").tabs({
                cookie: {
                    expires: 2
                }
            });
        });

    //Generate the tree
    $("#ulTreeDiv").attr("style","");
    $("#tree").treeview({
        collapsed: true,
        animated: "medium",
        control: "#sidetreecontrol",
        persist: "cookie"
    });

    //after toc fully styled, display it. Until loading, a 'loading' image will be displayed
    $("#tocLoading").attr("style","display:none;");
    //$("#ulTreeDiv").attr("style","display:block;");

    //.searchButton is the css class applied to 'Go' button 
    $(function() {
		$("button", ".searchButton").button();

		$("button", ".searchButton").click(function() {return false;});
	});

    //'ui-tabs-1' is the cookie name which is used for the persistence of the tabs.(Content/Search tab)
    if ($.cookie('ui-tabs-1') === '1') {    //search tab is visible 
      let textToSearch = $.cookie('textToSearch') ;
        if ( textToSearch !== undefined && textToSearch !== null && textToSearch.length > 0) {
            document.getElementById('textToSearch').value = $.cookie('textToSearch');
            Verifie('diaSearch_Form');

          var hcookie = selectTxtToHigh() ;
          searchHighlight(hcookie);
        }
    }

    syncToc(); //Synchronize the toc tree with the content pane, when loading the page.
    //$("#doSearch").button(); //add jquery button styling to 'Go' button
});

function selectTxtToHigh() {
  var allCookies = document.cookie.split(";");
  var hcookie;
  for (var iCookie = 0; iCookie < allCookies.length; iCookie++) {
    var cookie = allCookies[iCookie];
    var indexOfEq = cookie.indexOf('=');
    var key = cookie.substring(0, indexOfEq);
    if (key.includes( "highlight")){
      hcookie = cookie.substring(indexOfEq + 1);
    }
  }
  return hcookie;
}


/**
 * Synchronize with the tableOfContents 
 */

function syncToc() {
    var tocid = document.getElementById("zz_current-id").getAttribute("data-id");
    var a = document.getElementById(tocid);

    if (a !== undefined && a !== null ) {
        //Expanding the child sections of the selected node.
        var nodeClass = a.getAttribute("class");
        if (nodeClass !== null && !nodeClass.match(/collapsable/)) {
            a.setAttribute("class", "collapsable");
            //remove display:none; css style from <ul> block in the selected node.
            var ulNode = a.getElementsByTagName("ul")[0];
            if (ulNode !== undefined) {
                if (ulNode.hasAttribute("style")) {
                    ulNode.setAttribute("style", "display: block; background-color: #D8D8D8 !important;");
                } else {
                    var ulStyle = document.createAttribute("style");
                    ulStyle.nodeValue = "display: block; background-color: #D8D8D8 !important;";
                    ulNode.setAttributeNode(ulStyle);
            }   }
            //adjust tree's + sign to -
            var divNode = a.getElementsByTagName("div")[0];
            if (divNode !== undefined) {
                if (divNode.hasAttribute("class")) {
                    divNode.setAttribute("class", "hitarea collapsable-hitarea");
                } else {
                    var divClass = document.createAttribute("class");
                    divClass.nodeValue = "hitarea collapsable-hitarea";
                    divNode.setAttributeNode(divClass);
            }   }
            //set persistence cookie when a node is auto expanded
            //     setCookieForExpandedNode("webhelp-currentid");
        }
        var b = a.getElementsByTagName("a")[0];

        if (b !== undefined) {
            //Setting the background for selected node.
            var style = a.getAttribute("style", 2);
            if (style !== null && !style.match(/background-color: Background;/)) {
                a.setAttribute("style", "background-color: #D8D8D8;  " + style);
                b.setAttribute("style", "color: black;");
            } else if (style !== null) {
              a.setAttribute("style", "background-color: #D8D8D8;  " + style);
              b.setAttribute("style", "color: black;");
            } else {
              a.setAttribute("style", "background-color: #D8D8D8;  ");
              b.setAttribute("style", "color: black;");
        }
        }

        //shows the node related to current content.
        //goes a recursive call from current node to ancestor nodes, displaying all of them.
        while (a.parentNode && a.parentNode.nodeName) {
            var parentNode = a.parentNode;
            var nodeName = parentNode.nodeName;

            if (nodeName.toLowerCase() === "ul") {
              parentNode.setAttribute("style", "display: block;");
            } else if (nodeName.toLocaleLowerCase() === "li") {
                parentNode.setAttribute("class", "collapsable");
                parentNode.firstChild.setAttribute("class", "hitarea collapsable-hitarea ");
            }
            a = parentNode;
}   }  }

/**
 * Code for Show/Hide TOC
 *
 */
function showHideToc() {
    var showHideButton = $("#showHideButton");
    var leftNavigation = $("#leftnavigation");
    var header = $("#header");
    var headerHeight = header.outerHeight( true );
    var content = $("#content");
    var navigationDisplay = leftNavigation.css('display');

    if (showHideButton !== undefined
        && ( navigationDisplay === "block")) {
        //Hide TOC
        showHideButton.removeClass('pointLeft').addClass('pointRight');
        content.css("margin", "0 0 0 0");
        leftNavigation.css("display","none");
        showHideButton.attr("title", "Show table of contents");
        if(document.body.clientWidth <= 700)
          content.css('display','block');
    } else {
        //Show the TOC
        showHideButton.removeClass('pointRight').addClass('pointLeft');
        content.css("margin", "0 0 0 315px");
        leftNavigation.css("display","block");
        showHideButton.attr("title", "Hide table of contents");
        if(document.body.clientWidth <= 700)
          content.css('display','none');
    }
    leftNavigation.css('top' , headerHeight);
}

/**
 * Code for searh highlighting
 */
var highlightOn = true;
function searchHighlight(searchText) {
    highlightOn = true;
    if (searchText !== undefined) {
        var wList;
        var sList = new Array();    //stem list 
        //Highlight the search terms
        searchText = searchText.toLowerCase().replace(/<\//g, "_st_").replace(/\$_/g, "_di_").replace(/\.|%2C|%3B|%21|%3A|@|\/|\*/g, " ").replace(/(%20)+/g, " ").replace(/_st_/g, "</").replace(/_di_/g, "%24_");
        searchText = searchText.replace(/  +/g, " ");
        searchText = searchText.replace(/ $/, "").replace(/^ /, "");

        wList = searchText.split(" ");
        $("#content").highlight(wList); //Highlight the search input

        if(typeof stemmer !== "undefined" ){
            //Highlight the stems
            for (var i = 0; i < wList.length; i++) {
                var stemW = stemmer(wList[i]);
                sList.push(stemW);
            }
        } else {
            sList = wList;
        }
        $("#content").highlight(sList); //Highlight the search input's all stems

        var _content = document.getElementById("content");
        var spans = _content.getElementsByTagName("span");
        var hasOne = false;
        for (i = 0; i < spans.length; i++) {
            var span = spans[i];
            if (span.className === "highlight") {
                span.setAttribute("id", "firstHighlight");
                hasOne = true;
                break;
            }
        }
        if (hasOne) {
            document.getElementById("firstHighlight").scrollIntoView();
        }
    }
}

function searchUnhighlight(){
    highlightOn = false;
     //unhighlight the search input's all stems
    $("#content").unhighlight();
    $("#content").unhighlight();
}

function toggleHighlight(){
    if(highlightOn) {
        searchUnhighlight();
    } else {
      var hcookie = selectTxtToHigh() ;
      searchHighlight(hcookie);
    }
}