1
2//jQuery( document ).ready(function() {
3jQuery (function() {
4
5function escapeRegExp (expr) {
6  return expr.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
7}
8
9 if(JSINFO['se_actual_tpl'] == 'icke-template'  && !JSINFO['se_suspend']) {
10     icke_OnMobileFix();
11  }
12  if(JSINFO['se_suspend']) {
13         if (jQuery('p.sectoggle').length > 0){
14          jQuery('p.sectoggle').hide();
15       }
16        SectionToggle.is_active = false;
17    }
18    else {
19            if(JSINFO['se_device'])  {
20                SectionToggle.device_class =  JSINFO['se_device'];
21            }
22
23
24            SectionToggle.check_status();
25
26            if(!SectionToggle.is_active) {
27                 if (jQuery('p.sectoggle').length > 0){
28                      jQuery('p.sectoggle').hide();
29                   }
30            }
31
32if(SectionToggle.is_active && !JSINFO['toc_xcl']) {
33jQuery("ul.toc li div.li a, ul.toc li a").click(function(){
34      var text = jQuery(this).html();
35      text = text.toLowerCase();
36      text =  text.replace(/\s/g, "_");
37      if(SectionToggle.toc_xcl.indexOf(text) > -1) return;
38      var id = '#' + text;
39      jQuery(id).toggleClass('st_closed st_opened');
40      jQuery(id).next().toggle()
41});
42}
43         jQuery(SectionToggle.headers).each(function(index,elem ) {
44               if( typeof(jQuery(elem).next().html())  === 'undefined') return;
45
46		       var skip = false;
47			   var regex;
48               var hash = jQuery(elem).html().replace(/\s/g, "_");
49               regex = RegExp('\\b' + escapeRegExp(hash.toLowerCase()) + '\\b');
50
51		       if(hash.toLowerCase() == SectionToggle.hash || regex.test(JSINFO['h_ini_open'])) {
52                   skip = true;
53               }
54			   else if(SectionToggle.hash){
55                  regex = RegExp('^' +SectionToggle.hash,'i');  //bootstrap3
56				  if(regex.test(hash)) {
57					 skip = true;
58				  }
59		       }
60
61               if(SectionToggle.is_active && jQuery(elem).next().html().match(/\w/))  {
62                   this.onclick=function() {
63                   SectionToggle.checkheader(elem,index);
64                };
65
66                this.onmouseover = elem.style.cursor='pointer';
67                var $class = 'st_closed header__' + index;
68                jQuery(this).addClass($class);
69                 if(skip)  {
70                      jQuery(elem).removeClass('st_closed').addClass('st_opened');
71                }
72
73                /* add toggle icon and  hide data below this header */
74                if(!this.getAttribute('class').match(/toggle/)) {
75                     jQuery(elem).next().toggle();
76                     if(skip)  jQuery(elem).next().toggle();
77               }
78              }
79          if(JSINFO['start_open'])  {
80            SectionToggle.open_all();
81        }
82
83
84        });
85    }
86});
87var SectionToggle = {
88  checkheader: function (el, index) {
89    var classes = el.getAttribute("class");
90    if (!classes.match(/(header__\d+)/)) return;
91
92    jQuery(el).toggleClass("st_closed st_opened");
93    jQuery(el).next().toggle();
94  },
95
96  open_all: function () {
97    jQuery(this.headers).each(function (index, elem) {
98      if (
99        this.getAttribute("class") &&
100        !this.getAttribute("class").match(/toggle/)
101      ) {
102        jQuery(elem).removeClass("st_closed").addClass("st_opened");
103        jQuery(elem).next().show();
104      }
105    });
106  },
107
108  close_all: function () {
109    jQuery(this.headers).each(function (index, elem) {
110      if (!this.getAttribute("class").match(/toggle/)) {
111        jQuery(elem).removeClass("st_opened").addClass("st_closed");
112        jQuery(elem).next().hide();
113      }
114    });
115  },
116  check_status: function () {
117    if (JSINFO.se_platform == "n") return;
118    if (JSINFO.se_act != "show") return;
119    if (JSINFO.se_platform == "a") {
120      this.is_active = true;
121    } else if (JSINFO.se_platform == "m" && this.device_class.match(/mobile/)) {
122      this.is_active = true;
123    }
124
125    if (this.is_active) {
126      /*normalize url hash */
127      if (window.location.hash) {
128        SectionToggle.hash = window.location.hash.toLowerCase();
129        SectionToggle.hash = SectionToggle.hash.replace(/#/, "");
130        SectionToggle.hash = SectionToggle.hash.replace(/\s/g, "_");
131      }
132      this.set_headers();
133    }
134  },
135
136  set_headers: function () {
137    var nheaders = parseInt(JSINFO["se_headers"]) + 1;
138    var toc_headers_xcl = "";
139    var xclheaders = new Array(0, 0, 0, 0, 0, 0, 0);
140    if (JSINFO["se_xcl_headers"]) {
141      xcl = JSINFO["se_xcl_headers"].split(",");
142      for (var i = 0; i < xcl.length; i++) {
143        xclheaders[xcl[i]] = 1;
144      }
145    }
146
147    var which_id = "#dokuwiki__content";
148    if (JSINFO["se_name"] != "_empty_" && JSINFO["se_template"] == "other") {
149      which_id = JSINFO["se_name"];
150    }
151
152    /* if(JSINFO['alt_tpl']) {
153    alert(JSINFO['alt_tpl']);
154    }
155    else alert(JSINFO['se_template']);
156	*/
157
158    if (jQuery("div #section__toggle").length > 0) {
159      which_id = "#section__toggle";
160    }
161    which_id = "div " + which_id;
162    var id_string = "";
163
164    if (jQuery(which_id).length == 0) {
165      JSINFO["no_ini"] = 1;
166    }
167
168    // JSINFO['no_ini'] = 1;
169    if (JSINFO["no_ini"]) {
170      var qstr = "";
171
172      jQuery(":header").each(function (index, elem) {
173        var $id,
174          $class = jQuery(this).attr("class");
175        var tagname = jQuery(this).prop("tagName").toLowerCase();
176        matches = tagname.match(/h(\d)/);
177        if (matches[1] > JSINFO["se_headers"] || xclheaders[matches[1]]) return;
178
179        if ($class) {
180          if ($class.match(/sr-only|toggle/)) return;
181          var $classes = $class.match(/sectionedit\d+/);
182          if ($classes) {
183            tagname = tagname + "." + $classes[0];
184          }
185        } else {
186          $id = jQuery(this).attr("id");
187          tagname = tagname + "#" + $id;
188        }
189        if (qstr) qstr += ",";
190        qstr += tagname;
191      });
192      this.headers = qstr;
193      return;
194    }
195
196    for (var i = 1; i < nheaders; i++) {
197      if (xclheaders[i]) {
198        this.toc_xcl += which_id + " h" + i + ",";
199        continue;
200      }
201      id_string += which_id + " h" + i;
202      if (i < nheaders - 1) id_string += ",";
203    }
204    id_string = id_string.replace(/,+$/, "");
205    this.headers = id_string;
206
207    this.toc_xcl = this.toc_xcl.replace(/,+$/, "");
208    jQuery(this.toc_xcl).each(function (index, elem) {
209      var id = jQuery(this).attr("id");
210      if (id) {
211        id = id.replace(/\s/g, "_");
212        toc_headers_xcl += id + ",";
213      }
214    });
215
216    this.toc_xcl = ">>" + toc_headers_xcl;
217    //console.log(this.toc_xcl);
218  },
219  updateSections: function () {
220    if (this.toggleState === "open") {
221      this.close_all();
222      this.toggleState = "close";
223    } else {
224      this.open_all();
225      this.toggleState = "open";
226    }
227  },
228
229  toggleState: "open",
230  headers: "",
231  toc_xcl: "",
232  device_class: "desktop",
233  is_active: false,
234  hash: "",
235};
236function icke_OnMobileFix() {
237	if(JSINFO['se_platform'] != 'm' && JSINFO['se_platform'] != 'a') return;
238	var MOBILE_WIDTH = 600;
239	var SHALLOWST_SECTION_TO_HIDE = 2;
240	var DEEPEST_SECTION_TO_HIDE = 6;
241	var i;
242	var $page;
243	if (jQuery(window).width() <= MOBILE_WIDTH) {
244		$page = jQuery('div.page');
245		for (i = SHALLOWST_SECTION_TO_HIDE; i < DEEPEST_SECTION_TO_HIDE; i += 1) {
246			$page.find('div.level' + i).show();
247			$page.find('h' + i).click(function toggleSection() {
248				jQuery(this).next('div').toggle();
249			});
250		}
251	}
252};
253
254