summaryrefslogtreecommitdiffstats
path: root/doc/src/template/scripts/functions.js
blob: 47539d2defba89f1c26b499db69f9eea5dffbc57 (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
256
257
258
// Removing search results
function hideSearchResults() {
/* hiding search results as the user clicks on the different categories */
  $('#resultdialog').removeClass('active');
	$("#resultlist").removeClass().addClass('all');
	$("#resultlinks").removeClass().addClass('all');
	$("#searchcount").removeClass().addClass('all');
}
/* closing the searhc result dialog */
$('#resultclose').click(function(e) {
  e.preventDefault();
  hideSearchResults();
});

$(document.body).click(function() {
});

/* START non link areas where cursor should change to pointing hand */
$('.t_button').mouseover(function() {
    $('.t_button').css('cursor','pointer');
});
/* END non link areas  */
/* Changing font size to smaller */
$('#smallA').click(function() {
		$('.mainContent .heading,.mainContent h1, .mainContent h2, .mainContent h3, .mainContent p, .mainContent li, .mainContent table').css('font-size','smaller');
		$('.t_button').removeClass('active')
		$(this).addClass('active')
});

/* Reset font size */
$('#medA').click(function() {
		$('.mainContent .heading').css('font','600 16px/1 Arial');
		$('.mainContent h1').css('font','600 18px/1.2 Arial');
		$('.mainContent h2').css('font','600 16px/1.2 Arial');
		$('.mainContent h3').css('font','600 14px/1.2 Arial');
		$('.mainContent p').css('font','13px/20px Verdana');
		$('.mainContent li').css('font','400 13px/1 Verdana');
		$('.mainContent li').css('line-height','14px');
		$('.mainContent .toc li').css('font', 'normal 10px/1.2 Verdana');
		$('.mainContent table').css('font','13px/1.2 Verdana');
		$('.mainContent .heading').css('font','600 16px/1 Arial');
		$('.mainContent .indexboxcont li').css('font','600 13px/1 Verdana');
		$('.t_button').removeClass('active')
		$(this).addClass('active')
});
/* Changing font size to bigger */
$('#bigA').click(function() {
		$('.mainContent .heading,.mainContent h1, .mainContent h2, .mainContent h3, .mainContent p, .mainContent li, .mainContent table').css('font-size','large');
		$('.mainContent .heading,.mainContent h1, .mainContent h2, .mainContent h3, .mainContent p, .mainContent li, .mainContent table').css('line-height','25px');
		$('.t_button').removeClass('active')
		$(this).addClass('active')
});

/* Show page content after closing feedback box */
$('.feedclose').click(function() {
	$('.bd').show();
	$('.hd').show();
	$('.footer').show();
	$('#feedbackBox').hide();
	$('#blurpage').hide();
});

/* Hide page content and show feedback box */
$('.feedback').click(function() {
	$('.bd').hide();
	$('.hd').hide();
	$('.footer').hide();
	$('#feedbackBox').show();
	$('#blurpage').show();
});
/* Default search URL */
var qturl = "";

/* The next function handles the response data (in xml) returned by the search engine */

// Process data sent back from the server. The data is structured as a XML.
/*
XML structure handled by function processNokiaData()
<page> - container for each page returned
<pageWords/> - contains keywords
<pageTitle/> - contains page title/header content 
<pageUrl/> - contains page URL - URL relative to root
<pageType> - contains page type - APIPage/Article/Example
</page>
*/


function processNokiaData(response){
/* fetch the responce from the server using page as the root element */
	var propertyTags = response.getElementsByTagName('page');
	/* reset counters */	
	var apiCount = 0;
	var articleCount = 0;
	var exampleCount = 0;
	var full_li_element;

/* remove any old results */
	$('#resultlist li').remove();


	/* running through the elements in the xml structure */
 	for (var i=0; i<propertyTags.length; i++) {
		/* for every element named pageWords*/
		for (var j=0; j< propertyTags[i].getElementsByTagName('pageWords').length; j++) {
			/* start a new list element */
			full_li_element = '<li';
					/* if the pageType element reads APIPage, add class name api */
      if (propertyTags[j].getElementsByTagName('pageType')[0].firstChild.nodeValue == 'APIPage') {
      	full_li_element += ' class="api"';
      	apiCount++;
      }
					/* if the pageType element reads Article, add class name article */
      else if (propertyTags[j].getElementsByTagName('pageType')[0].firstChild.nodeValue == 'Article') {
      	full_li_element += ' class="article"';
      	articleCount++;
      }
					/* if the pageType element reads Example, add class name example */
      else if (propertyTags[j].getElementsByTagName('pageType')[0].firstChild.nodeValue == 'Example') {
      	full_li_element += ' class="example"';
      	exampleCount++;
      }
			/* adding the link element*/
			full_li_element += '><a href="'+qturl;
			/* adding the URL attribute*/
			full_li_element += propertyTags[i].getElementsByTagName('pageUrl')[j].firstChild.nodeValue;
      		/* adding the link title and closing the link and list elements */
			full_li_element += '">' + propertyTags[i].getElementsByTagName('pageWords')[0].firstChild.nodeValue + '</a></li>';
			/* appending the list element to the #resultlist div*/
			$('#resultlist').append(full_li_element);
		}
	}

	/* if the result is not empty */
	if (propertyTags.length > 0) {
	/* add class name active to show the dialog */
	  $('#resultdialog').addClass('active');
	  /* setting number of hits*/
	  $('#resultcount').html(propertyTags.length);
	  $('#apicount').html(apiCount);
	  $('#articlecount').html(articleCount);
	  $('#examplecount').html(exampleCount);
	  
	}
	else {
	  $('#pageType').addClass('red');
	  }
  


  // Filtering results in display
	$('p#resultlinks a').click(function(e) {
  	e.preventDefault();
	// Displays API ref pages
		if (this.id == "showapiresults") {
			$("#resultlist").removeClass().addClass('api');
			$("#resultlinks").removeClass().addClass('api');
			$("#searchcount").removeClass().addClass('api');
		}
	// Displays Articles
		else if (this.id == "showarticleresults") {
			$("#resultlist").removeClass().addClass('article');
			$("#resultlinks").removeClass().addClass('article');
			$("#searchcount").removeClass().addClass('article');
		}
	// Displays Examples
		if (this.id == "showexampleresults") {
			$("#resultlist").removeClass().addClass('example');
			$("#resultlinks").removeClass().addClass('example');
			$("#searchcount").removeClass().addClass('example');
		}
	// Displays All
		if (this.id == "showallresults") {
			$("#resultlist").removeClass().addClass('all');
			$("#resultlinks").removeClass().addClass('all');
			$("#searchcount").removeClass().addClass('all');
		}
	});
}

//build regular expression object to find empty string or any number of blank
var blankRE=/^\s*$/;


function CheckEmptyAndLoadList()
{
	/* Start Extracting information for feedback and adding this to the feedback form */
	var pageUrl = window.location.href;
	var pageVal = $('title').html();
	$('#pageType').removeClass('red');
	$('#feedUrl').remove();
	$('#pageVal').remove();
	$('.menuAlert').remove();
	$('#feedform').append('<input id="feedUrl" name="feedUrl" value="'+pageUrl+'" style="display:none;">');
	$('#feedform').append('<input id="pageVal" name="pageVal" value="'+pageVal+'" style="display:none;">');
	/* End Extracting information for feedback and adding this to the feedback form */

	/* extracts search query */
	var value = document.getElementById('pageType').value; 
	/* if the search is less than three chars long remove class names and remove elements from old search*/
	if((blankRE.test(value)) || (value.length < 3))
	{
	$('#resultdialog').removeClass('active');
	$('#resultlist li').remove();
	}
}

// Loads on doc ready - prepares search 
	$(document).ready(function () {
	/* fetch page title*/ 
	var pageTitle = $('title').html();
	/* getting content from search box */
          var currentString = $('#pageType').val() ;
	  /* if the search box is not empty run CheckEmptyAndLoadList*/
		  if(currentString.length < 1){
      	   		CheckEmptyAndLoadList();			
		  }

		/* on key-up in the search box execute the following */
        $('#pageType').keyup(function () {
		/* extract the search box content */
          var searchString = $('#pageType').val() ;
	  /* if the string is less than three characters */
          if ((searchString == null) || (searchString.length < 3)) {
			/* remove classes and elements*/
				$('#pageType').removeClass('loading');
				 $('.searching').remove(); 
			/*  run CheckEmptyAndLoadList */
      	   		CheckEmptyAndLoadList();

				$('.report').remove();
				return;
		   }
	   /* if timer checks out */
            if (this.timer) clearTimeout(this.timer);
            this.timer = setTimeout(function () {
			/* add loading image by adding loading class */
				$('#pageType').addClass('loading');
				$('.searching').remove(); 

			/* run the actual search */
               $.ajax({
                contentType: "application/x-www-form-urlencoded",
                url: 'http://' + location.host + '/nokiasearch/GetDataServlet',
                data: 'searchString='+searchString,
                dataType:'xml',
				type: 'post',	 
                success: function (response, textStatus) {
				/* on success remove loading img */
				$('.searching').remove(); 
				$('#pageType').removeClass('loading');

                processNokiaData(response);

 }     
              });
            }, 500); /* timer set to 500 ms */
        });
      });