source: trunk/doc/src/template/scripts/narrow.js

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 3.9 KB
Line 
1/* This function generates menus and search box in narrow/slim fit mode */
2var narrowInit = function() {
3 /* 1: Create search form */
4 var narrowSearch = $('<div id="narrowsearch"></div>');
5 var searchform = $("#qtdocsearch");
6 narrowSearch.append(searchform);
7 $("#qtdocheader .content .qtref").after(narrowSearch);
8
9 /* 2: Create dropdowns */
10 var narrowmenu = $('<ul id="narrowmenu" class="sf-menu"></ul>');
11
12 /* Lookup */
13 var lookuptext = $("#lookup h2").attr("title");
14 $("#lookup ul").removeAttr("id");
15 $("#lookup ul li").removeAttr("class");
16 $("#lookup ul li").removeAttr("style");
17 var lookupul = $("#lookup ul");
18 var lookuplist = $('<li></li>');
19 var lookuplink = $('<a href="#"></a>');
20 lookuplink.append(lookuptext);
21 lookuplist.append(lookuplink);
22 lookuplist.append(lookupul);
23 narrowmenu.append(lookuplist);
24
25 /* Topics */
26 var topicstext = $("#topics h2").attr("title");
27 $("#topics ul").removeAttr("id");
28 $("#topics ul li").removeAttr("class");
29 $("#topics ul li").removeAttr("style");
30 var topicsul = $("#topics ul");
31 var topicslist = $('<li></li>');
32 var topicslink = $('<a href="#"></a>');
33 topicslink.append(topicstext);
34 topicslist.append(topicslink);
35 topicslist.append(topicsul);
36 narrowmenu.append(topicslist);
37
38 /* Examples */
39 var examplestext = $("#examples h2").attr("title");
40 $("#examples ul").removeAttr("id");
41 $("#examples ul li").removeAttr("class");
42 $("#examples ul li").removeAttr("style");
43 var examplesul = $("#examples ul");
44 var exampleslist = $('<li></li>');
45 var exampleslink = $('<a href="#"></a>');
46 exampleslink.append(examplestext);
47 exampleslist.append(exampleslink);
48 exampleslist.append(examplesul);
49 narrowmenu.append(exampleslist);
50
51 $("#shortCut").after(narrowmenu);
52 $('ul#narrowmenu').superfish({
53 delay: 100,
54 autoArrows: false,
55 disableHI: true
56 });
57}
58
59/* Executes on doc ready */
60$(document).ready(function(){
61 /* check if body has the narrow class */
62 if ($('body').hasClass('narrow')) {
63 /* run narrowInit */
64 narrowInit();
65 }
66
67 /* messure window width and add class if it is smaller than 600 px */
68 if($(window).width()<600) {
69 $('body').addClass('narrow');
70 /* if the search box contains */
71 if ($("#narrowsearch").length == 0) {
72 /* run narrowInit */
73 narrowInit();
74 }
75 }
76 else { /* if the window is wider than 600 px, narrow is removed */
77 $('body').removeClass('narrow');
78 if ($("#narrowsearch").length == 0) {
79 }
80 }
81});
82/* binding resize event to this funciton */
83$(window).bind('resize', function () {
84 /* if the window is wider than 600 px, narrow class is added */
85 if($(window).width()<600) {
86 $('body').addClass('narrow');
87 if ($("#narrowsearch").length == 0) {
88 narrowInit();
89 }
90 }
91 else {
92 /* else we remove the narrow class */
93 $('body').removeClass('narrow');
94 }
95});
96
97 $('#narrowsearch').keyup(function () {
98 /* extract the search box content */
99 var searchString = $('#narrowsearch').val();
100 /* if the string is less than three characters */
101 if ((searchString == null) || (searchString.length < 3)) {
102 /* remove classes and elements*/
103 $('#narrowsearch').removeClass('loading');
104 $('.searching').remove();
105 /* run CheckEmptyAndLoadList */
106 CheckEmptyAndLoadList();
107
108 $('.report').remove();
109 return;
110 }
111 /* if timer checks out */
112 if (this.timer) clearTimeout(this.timer);
113 this.timer = setTimeout(function () {
114 /* add loading image by adding loading class */
115 $('#narrowsearch').addClass('loading');
116 $('.searching').remove();
117
118 /* run the actual search */
119 $.ajax({
120 contentType: "application/x-www-form-urlencoded",
121 url: 'http://' + location.host + '/nokiasearch/GetDataServlet',
122 data: 'searchString='+searchString,
123 dataType:'xml',
124 type: 'post',
125 success: function (response, textStatus) {
126 /* on success remove loading img */
127 $('.searching').remove();
128 $('#narrowsearch').removeClass('loading');
129 processNokiaData(response);
130 }
131 });
132 }, 500); /* timer set to 500 ms */
133 });
Note: See TracBrowser for help on using the repository browser.