/[drupal]/contributions/modules/semantic_search/js/semantic_search.contrib.js
ViewVC logotype

Contents of /contributions/modules/semantic_search/js/semantic_search.contrib.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Jun 5 06:37:06 2007 UTC (2 years, 5 months ago) by hendler
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/javascript
adding files from our SVN
1 /**
2 * cookie handling
3 * http://techpatterns.com/downloads/javascript_cookies.php
4 */
5 function Set_Cookie( name, value, expires, path, domain, secure )
6 {
7 // set time, it's in milliseconds
8 var today = new Date();
9 today.setTime( today.getTime() );
10
11 /*
12 if the expires variable is set, make the correct
13 expires time, the current script below will set
14 it for x number of days, to make it for hours,
15 delete * 24, for minutes, delete * 60 * 24
16 */
17 if ( expires )
18 {
19 expires = expires * 1000 * 60 * 60 * 24;
20 }
21 var expires_date = new Date( today.getTime() + (expires) );
22
23 document.cookie = name + "=" +escape( value ) +
24 ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
25 ( ( path ) ? ";path=" + path : "" ) +
26 ( ( domain ) ? ";domain=" + domain : "" ) +
27 ( ( secure ) ? ";secure" : "" );
28 }
29
30
31 // this function gets the cookie, if it exists
32 function Get_Cookie( name ) {
33
34 var start = document.cookie.indexOf( name + "=" );
35 var len = start + name.length + 1;
36 if ( ( !start ) &&
37 ( name != document.cookie.substring( 0, name.length ) ) )
38 {
39 return null;
40 }
41 if ( start == -1 ) return null;
42 var end = document.cookie.indexOf( ";", len );
43 if ( end == -1 ) end = document.cookie.length;
44 return unescape( document.cookie.substring( len, end ) );
45 }
46
47
48 // this deletes the cookie when called
49 function Delete_Cookie( name, path, domain ) {
50 if ( Get_Cookie( name ) ) document.cookie = name + "=" +
51 ( ( path ) ? ";path=" + path : "") +
52 ( ( domain ) ? ";domain=" + domain : "" ) +
53 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
54 }
55
56
57 /**
58 *
59 * URL encode / decode
60 * http://www.webtoolkit.info/
61 *
62 **/
63
64 var SEMANTIC_SEARCHUrl = {
65
66 // public method for url encoding
67 encode : function (string) {
68 return escape(this._utf8_encode(string));
69 },
70
71 // public method for url decoding
72 decode : function (string) {
73 return this._utf8_decode(unescape(string));
74 },
75
76 // private method for UTF-8 encoding
77 _utf8_encode : function (string) {
78 string = string.replace(/\r\n/g,"\n");
79 var utftext = "";
80
81 for (var n = 0; n < string.length; n++) {
82
83 var c = string.charCodeAt(n);
84
85 if (c < 128) {
86 utftext += String.fromCharCode(c);
87 }
88 else if((c > 127) && (c < 2048)) {
89 utftext += String.fromCharCode((c >> 6) | 192);
90 utftext += String.fromCharCode((c & 63) | 128);
91 }
92 else {
93 utftext += String.fromCharCode((c >> 12) | 224);
94 utftext += String.fromCharCode(((c >> 6) & 63) | 128);
95 utftext += String.fromCharCode((c & 63) | 128);
96 }
97
98 }
99
100 return utftext;
101 },
102
103 // private method for UTF-8 decoding
104 _utf8_decode : function (utftext) {
105 var string = "";
106 var i = 0;
107 var c = c1 = c2 = 0;
108
109 while ( i < utftext.length ) {
110
111 c = utftext.charCodeAt(i);
112
113 if (c < 128) {
114 string += String.fromCharCode(c);
115 i++;
116 }
117 else if((c > 191) && (c < 224)) {
118 c2 = utftext.charCodeAt(i+1);
119 string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
120 i += 2;
121 }
122 else {
123 c2 = utftext.charCodeAt(i+1);
124 c3 = utftext.charCodeAt(i+2);
125 string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
126 i += 3;
127 }
128
129 }
130
131 return string;
132 }
133
134
135
136 }
137
138
139 // This code was written by Tyler Akins and has been placed in the
140 // public domain. It would be nice if you left this header intact.
141 // Base64 code from Tyler Akins -- http://rumkin.com
142
143 var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
144
145 function encode64(input) {
146 var output = "";
147 var chr1, chr2, chr3;
148 var enc1, enc2, enc3, enc4;
149 var i = 0;
150
151 do {
152 chr1 = input.charCodeAt(i++);
153 chr2 = input.charCodeAt(i++);
154 chr3 = input.charCodeAt(i++);
155
156 enc1 = chr1 >> 2;
157 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
158 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
159 enc4 = chr3 & 63;
160
161 if (isNaN(chr2)) {
162 enc3 = enc4 = 64;
163 } else if (isNaN(chr3)) {
164 enc4 = 64;
165 }
166
167 output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
168 keyStr.charAt(enc3) + keyStr.charAt(enc4);
169 } while (i < input.length);
170
171 return output;
172 }
173
174 function decode64(input) {
175 var output = "";
176 var chr1, chr2, chr3;
177 var enc1, enc2, enc3, enc4;
178 var i = 0;
179
180 // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
181 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
182
183 do {
184 enc1 = keyStr.indexOf(input.charAt(i++));
185 enc2 = keyStr.indexOf(input.charAt(i++));
186 enc3 = keyStr.indexOf(input.charAt(i++));
187 enc4 = keyStr.indexOf(input.charAt(i++));
188
189 chr1 = (enc1 << 2) | (enc2 >> 4);
190 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
191 chr3 = ((enc3 & 3) << 6) | enc4;
192
193 output = output + String.fromCharCode(chr1);
194
195 if (enc3 != 64) {
196 output = output + String.fromCharCode(chr2);
197 }
198 if (enc4 != 64) {
199 output = output + String.fromCharCode(chr3);
200 }
201 } while (i < input.length);
202
203 return output;
204 }

  ViewVC Help
Powered by ViewVC 1.1.2