author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/gamma/js/Bookmarklet.js | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'frontend/gamma/js/Bookmarklet.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Bookmarklet.js | 801 |
1 files changed, 801 insertions, 0 deletions
diff --git a/frontend/gamma/js/Bookmarklet.js b/frontend/gamma/js/Bookmarklet.js new file mode 100644 index 0000000..a8e3e69 --- a/dev/null +++ b/frontend/gamma/js/Bookmarklet.js | |||
@@ -0,0 +1,801 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | clipperz_copiedContentToClipboard = false; | ||
30 | |||
31 | //############################################################################# | ||
32 | |||
33 | // Simple Set Clipboard System | ||
34 | // Author: Joseph Huckaby | ||
35 | |||
36 | var ZeroClipboard = { | ||
37 | |||
38 | version: "1.0.4", | ||
39 | clients: {}, // registered upload clients on page, indexed by id | ||
40 | //moviePath: 'ZeroClipboard.swf', // URL to movie | ||
41 | //moviePath: 'data:application/octet-stream;charset=utf-8;base64,Q1dTCYgGAAB4nH1V61LbRhTeXV2OJNsYczFgIEC4JCGABSRpSy+B2JDQQtWJocl0BqK1tUZqhOSRZAj/8ih9hz5AXsGZTl+ndHUhxU2nO56z3/l05uye7+wc6xr6DeUxqpcUhFCNXF9ffxjNcYhRo8U8NruO0IeRLTkm+BpEa4i8/+t3GRGUrRf5tktDe41dMC8Kpd14Q/DM911GPfHCd6zCLyzwa67Tafo0sAppuOWEHZdeyY1O4ERMbnajyPcKIYteUM+qdYPQD/It12m9jX2XBcSx5EYUON6ZwunOEXsXAY+O94HsAu8iFnjULe1mYN/je5u2WLnvAsnRNGrZ6rnfDZlxwQKxRV1XSd1ulPJ1/9KDBB13pDCiZ2ygEdsGj2WHvsXU3dc7taM3e/tHanjDZVqEV2HEzpUGa3V5dVd4Ocfz+5d1/5w6nnbgU4sF+17bFwPfjzT3k691aEDPGb92KBvNX1krmrOjqLNVrVLLb7K1ln9e3WlsVjd0/Um12XXcyPFy6ZHdyHHDkT5tt1JtF/rJerqn6Wu+F/ErsWCmPyiRjrYi54KlgZP/k2Tq9gPYSh5APZOYBVra2VicAtfyn+4qZwHt2E4rVJvszPH2HNcVD2lkS5eOxW3b9f1AtplzZkeKFdDLl/wkibodmyrUsmq241raYdye5ECpdrBf+2GQf0ncA4c3gJelHRrHjd03xs+7L9UMHh9lZN149aOSwuOfcnFO3qQmbb0V44aoSVEXlHeikXQzz1/bpzek8E50XN6o4r/KLfQpU/pMx/J/yz9cxmWhDOOyhMqD5SkJjQnKYnmpIlfuVe5XHlSWKw8rC6QoEayoWk7MFwaKg6Whx4AJEBGIBEQGQQFJBaKBlAMpD6QA0gCQIsglICNAxkGYAFIBMgkwDWQGhFkgc0DuApkHsqDmMZAVIKtA1oBUgejqOmc21E1uHwF5DOQJ4C+AfAnkKyBbQL4G8g2Qb4F8B+o2wA6QZ4DrIOyCsAfCcw0lUwR/ZvgiOP3IhwgWcDZIsCipIpJkPmskBBiBgpGiIqQJOJdYPqbiOaRiUcRIQ5hrIfT055ySiKYVzMLKkKmuDM8aAyInyW1yNCOF22Q5I8Xb5FhGSjLR8n/gnv5q+U+9t4/MojnYLtEhc3jljjGCGT4Z7bXL7bG9Udwefz9xjk9Vhl3crtjqqXwifS8hWzblJToZmylTbk+vYuMOjsECWjZnkuDZvTmcwbscGvOiKVcxXThZNGVjkQebS+17pmLcJwl8sI1v4PI2uYEPt4UbuLItxrCwoplgrMagaOZTENf2NK0NryE8gWRCVE3p6ae5j3aOFwyZb8of6RT3FYn7Y9yvmjlDx1mKGncSfVTC9Z/v6QyZE7q5rpsburmpm490U+K/12g6WXYc+nR4CKX/H31zGG1z5m9Pt5okCg==', | ||
42 | //moviePath: 'http://localhost:8000/tests/js/tests/Bookmarklet/ZeroClipboard.swf', | ||
43 | moviePath: 'http://www.clipperz.com/files/clipperz.com/bookmarklet/0.3.0/ZeroClipboard_1.0.4.swf', | ||
44 | //moviePath: './ZeroClipboard.swf', | ||
45 | nextId: 1, // ID of next movie | ||
46 | |||
47 | $: function(thingy) { | ||
48 | // simple DOM lookup utility function | ||
49 | if (typeof(thingy) == 'string') thingy = document.getElementById(thingy); | ||
50 | if (!thingy.addClass) { | ||
51 | // extend element with a few useful methods | ||
52 | thingy.hide = function() { this.style.display = 'none'; }; | ||
53 | thingy.show = function() { this.style.display = ''; }; | ||
54 | thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; }; | ||
55 | thingy.removeClass = function(name) { | ||
56 | this.className = this.className.replace( new RegExp("\\s*" + name + "\\s*"), " ").replace(/^\s+/, '').replace(/\s+$/, ''); | ||
57 | }; | ||
58 | thingy.hasClass = function(name) { | ||
59 | return !!this.className.match( new RegExp("\\s*" + name + "\\s*") ); | ||
60 | } | ||
61 | } | ||
62 | return thingy; | ||
63 | }, | ||
64 | |||
65 | setMoviePath: function(path) { | ||
66 | // set path to ZeroClipboard.swf | ||
67 | this.moviePath = path; | ||
68 | }, | ||
69 | |||
70 | dispatch: function(id, eventName, args) { | ||
71 | // receive event from flash movie, send to client | ||
72 | var client = this.clients[id]; | ||
73 | if (client) { | ||
74 | client.receiveEvent(eventName, args); | ||
75 | } | ||
76 | }, | ||
77 | |||
78 | register: function(id, client) { | ||
79 | // register new client to receive events | ||
80 | this.clients[id] = client; | ||
81 | }, | ||
82 | |||
83 | getDOMObjectPosition: function(obj) { | ||
84 | // get absolute coordinates for dom element | ||
85 | var info = { | ||
86 | left: 0, | ||
87 | top: 0, | ||
88 | width: obj.width ? obj.width : obj.offsetWidth, | ||
89 | height: obj.height ? obj.height : obj.offsetHeight | ||
90 | }; | ||
91 | |||
92 | while (obj) { | ||
93 | info.left += obj.offsetLeft; | ||
94 | info.top += obj.offsetTop; | ||
95 | obj = obj.offsetParent; | ||
96 | } | ||
97 | |||
98 | return info; | ||
99 | }, | ||
100 | |||
101 | Client: function(elem) { | ||
102 | // constructor for new simple upload client | ||
103 | this.handlers = {}; | ||
104 | |||
105 | // unique ID | ||
106 | this.id = ZeroClipboard.nextId++; | ||
107 | this.movieId = 'ZeroClipboardMovie_' + this.id; | ||
108 | |||
109 | // register client with singleton to receive flash events | ||
110 | ZeroClipboard.register(this.id, this); | ||
111 | |||
112 | // create movie | ||
113 | if (elem) this.glue(elem); | ||
114 | } | ||
115 | }; | ||
116 | |||
117 | ZeroClipboard.Client.prototype = { | ||
118 | |||
119 | id: 0, // unique ID for us | ||
120 | ready: false, // whether movie is ready to receive events or not | ||
121 | movie: null, // reference to movie object | ||
122 | clipText: '', // text to copy to clipboard | ||
123 | handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor | ||
124 | cssEffects: true, // enable CSS mouse effects on dom container | ||
125 | handlers: null, // user event handlers | ||
126 | |||
127 | glue: function(elem) { | ||
128 | // glue to DOM element | ||
129 | // elem can be ID or actual DOM element object | ||
130 | //console.log(">>> glue"); | ||
131 | this.domElement = ZeroClipboard.$(elem); | ||
132 | |||
133 | // float just above object, or zIndex 99 if dom element isn't set | ||
134 | var zIndex = 99; | ||
135 | if (this.domElement.style.zIndex) { | ||
136 | zIndex = parseInt(this.domElement.style.zIndex) + 1; | ||
137 | } | ||
138 | |||
139 | // find X/Y position of domElement | ||
140 | var box = ZeroClipboard.getDOMObjectPosition(this.domElement); | ||
141 | |||
142 | // create floating DIV above element | ||
143 | this.div = document.createElement('div'); | ||
144 | var style = this.div.style; | ||
145 | style.position = 'absolute'; | ||
146 | style.left = '' + box.left + 'px'; | ||
147 | style.top = '' + box.top + 'px'; | ||
148 | style.width = '' + box.width + 'px'; | ||
149 | style.height = '' + box.height + 'px'; | ||
150 | style.zIndex = zIndex; | ||
151 | |||
152 | // style.backgroundColor = '#f00'; // debug | ||
153 | |||
154 | var body = document.getElementsByTagName('body')[0]; | ||
155 | body.appendChild(this.div); | ||
156 | |||
157 | this.div.innerHTML = this.getHTML( box.width, box.height ); | ||
158 | //console.log("<<< glue"); | ||
159 | }, | ||
160 | |||
161 | getHTML: function(width, height) { | ||
162 | // return HTML for movie | ||
163 | var html = ''; | ||
164 | var flashvars = 'id=' + this.id + | ||
165 | '&width=' + width + | ||
166 | '&height=' + height; | ||
167 | |||
168 | if (navigator.userAgent.match(/MSIE/)) { | ||
169 | // IE gets an OBJECT tag | ||
170 | var protocol = location.href.match(/^https/i) ? 'https://' : 'http://'; | ||
171 | html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>'; | ||
172 | } | ||
173 | else { | ||
174 | // all other browsers get an EMBED tag | ||
175 | html += '<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />'; | ||
176 | } | ||
177 | return html; | ||
178 | }, | ||
179 | |||
180 | hide: function() { | ||
181 | // temporarily hide floater offscreen | ||
182 | if (this.div) { | ||
183 | this.div.style.left = '-2000px'; | ||
184 | } | ||
185 | }, | ||
186 | |||
187 | show: function() { | ||
188 | // show ourselves after a call to hide() | ||
189 | this.reposition(); | ||
190 | }, | ||
191 | |||
192 | destroy: function() { | ||
193 | // destroy control and floater | ||
194 | if (this.domElement && this.div) { | ||
195 | this.hide(); | ||
196 | this.div.innerHTML = ''; | ||
197 | |||
198 | var body = document.getElementsByTagName('body')[0]; | ||
199 | try { body.removeChild( this.div ); } catch(e) {;} | ||
200 | |||
201 | this.domElement = null; | ||
202 | this.div = null; | ||
203 | } | ||
204 | }, | ||
205 | |||
206 | reposition: function(elem) { | ||
207 | // reposition our floating div, optionally to new container | ||
208 | // warning: container CANNOT change size, only position | ||
209 | if (elem) { | ||
210 | this.domElement = ZeroClipboard.$(elem); | ||
211 | if (!this.domElement) this.hide(); | ||
212 | } | ||
213 | |||
214 | if (this.domElement && this.div) { | ||
215 | var box = ZeroClipboard.getDOMObjectPosition(this.domElement); | ||
216 | var style = this.div.style; | ||
217 | style.left = '' + box.left + 'px'; | ||
218 | style.top = '' + box.top + 'px'; | ||
219 | } | ||
220 | }, | ||
221 | |||
222 | setText: function(newText) { | ||
223 | // set text to be copied to clipboard | ||
224 | this.clipText = newText; | ||
225 | if (this.ready) this.movie.setText(newText); | ||
226 | }, | ||
227 | |||
228 | addEventListener: function(eventName, func) { | ||
229 | // add user event listener for event | ||
230 | // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel | ||
231 | eventName = eventName.toString().toLowerCase().replace(/^on/, ''); | ||
232 | if (!this.handlers[eventName]) this.handlers[eventName] = []; | ||
233 | this.handlers[eventName].push(func); | ||
234 | }, | ||
235 | |||
236 | setHandCursor: function(enabled) { | ||
237 | // enable hand cursor (true), or default arrow cursor (false) | ||
238 | this.handCursorEnabled = enabled; | ||
239 | if (this.ready) this.movie.setHandCursor(enabled); | ||
240 | }, | ||
241 | |||
242 | setCSSEffects: function(enabled) { | ||
243 | // enable or disable CSS effects on DOM container | ||
244 | this.cssEffects = !!enabled; | ||
245 | }, | ||
246 | |||
247 | receiveEvent: function(eventName, args) { | ||
248 | // receive event from flash | ||
249 | eventName = eventName.toString().toLowerCase().replace(/^on/, ''); | ||
250 | |||
251 | // special behavior for certain events | ||
252 | switch (eventName) { | ||
253 | case 'load': | ||
254 | // movie claims it is ready, but in IE this isn't always the case... | ||
255 | // bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function | ||
256 | this.movie = document.getElementById(this.movieId); | ||
257 | if (!this.movie) { | ||
258 | var self = this; | ||
259 | setTimeout( function() { self.receiveEvent('load', null); }, 1 ); | ||
260 | return; | ||
261 | } | ||
262 | |||
263 | // firefox on pc needs a "kick" in order to set these in certain cases | ||
264 | if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) { | ||
265 | var self = this; | ||
266 | setTimeout( function() { self.receiveEvent('load', null); }, 100 ); | ||
267 | this.ready = true; | ||
268 | return; | ||
269 | } | ||
270 | |||
271 | this.ready = true; | ||
272 | this.movie.setText( this.clipText ); | ||
273 | this.movie.setHandCursor( this.handCursorEnabled ); | ||
274 | break; | ||
275 | |||
276 | case 'mouseover': | ||
277 | if (this.domElement && this.cssEffects) { | ||
278 | this.domElement.addClass('hover'); | ||
279 | if (this.recoverActive) this.domElement.addClass('active'); | ||
280 | } | ||
281 | break; | ||
282 | |||
283 | case 'mouseout': | ||
284 | if (this.domElement && this.cssEffects) { | ||
285 | this.recoverActive = false; | ||
286 | if (this.domElement.hasClass('active')) { | ||
287 | this.domElement.removeClass('active'); | ||
288 | this.recoverActive = true; | ||
289 | } | ||
290 | this.domElement.removeClass('hover'); | ||
291 | } | ||
292 | break; | ||
293 | |||
294 | case 'mousedown': | ||
295 | if (this.domElement && this.cssEffects) { | ||
296 | this.domElement.addClass('active'); | ||
297 | } | ||
298 | break; | ||
299 | |||
300 | case 'mouseup': | ||
301 | if (this.domElement && this.cssEffects) { | ||
302 | this.domElement.removeClass('active'); | ||
303 | this.recoverActive = false; | ||
304 | } | ||
305 | break; | ||
306 | } // switch eventName | ||
307 | |||
308 | if (this.handlers[eventName]) { | ||
309 | for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) { | ||
310 | var func = this.handlers[eventName][idx]; | ||
311 | |||
312 | if (typeof(func) == 'function') { | ||
313 | // actual function reference | ||
314 | func(this, args); | ||
315 | } | ||
316 | else if ((typeof(func) == 'object') && (func.length == 2)) { | ||
317 | // PHP style object + method, i.e. [myObject, 'myMethod'] | ||
318 | func[0][ func[1] ](this, args); | ||
319 | } | ||
320 | else if (typeof(func) == 'string') { | ||
321 | // name of function | ||
322 | window[func](this, args); | ||
323 | } | ||
324 | } // foreach event handler defined | ||
325 | } // user defined handler for event | ||
326 | } | ||
327 | |||
328 | }; | ||
329 | |||
330 | //############################################################################# | ||
331 | |||
332 | var clip = null; | ||
333 | |||
334 | function $(id) { return document.getElementById(id); } | ||
335 | |||
336 | function initClip() { | ||
337 | //console.log(">>> initClip"); | ||
338 | clip = new ZeroClipboard.Client(); | ||
339 | clip.setHandCursor( true ); | ||
340 | |||
341 | //clip.addEventListener('load', my_load); | ||
342 | //clip.addEventListener('mouseOver', my_mouse_over); | ||
343 | clip.addEventListener('complete', my_complete); | ||
344 | |||
345 | //clip.glue( 'd_clip_button' ); | ||
346 | //console.log("<<< initClip"); | ||
347 | } | ||
348 | |||
349 | //function my_load(client) { | ||
350 | //console.log("Flash movie loaded and ready."); | ||
351 | //} | ||
352 | |||
353 | //function my_mouse_over(client) { | ||
354 | //// we can cheat a little here -- update the text on mouse over | ||
355 | //clip.setText( $('fe_text').value ); | ||
356 | //} | ||
357 | |||
358 | function my_complete(client, text) { | ||
359 | //console.log("Copied text to clipboard: ... "); | ||
360 | //console.log("Copied text to clipboard: " + text ); | ||
361 | clipperz_copiedContentToClipboard = true; | ||
362 | showTooltip(); | ||
363 | } | ||
364 | |||
365 | //function debugstr(msg) { | ||
366 | //var p = document.createElement('p'); | ||
367 | //p.innerHTML = msg; | ||
368 | //$('d_debug').appendChild(p); | ||
369 | //} | ||
370 | |||
371 | //############################################################################# | ||
372 | |||
373 | _cble = null; | ||
374 | |||
375 | //----------------------------------------------------------------------------- | ||
376 | |||
377 | isLoginForm = function(aForm) { | ||
378 | var inputFields; | ||
379 | var passwordFieldsFound; | ||
380 | var i,c; | ||
381 | |||
382 | //console.log("is login form: " + aForm.name + " (" + aForm.id + ")"); | ||
383 | passwordFieldsFound = 0; | ||
384 | inputFields = aForm.elements; | ||
385 | c = inputFields.length; | ||
386 | for (i=0; i<c; i++) { | ||
387 | if (inputFields[i].type == "password") { | ||
388 | passwordFieldsFound ++; | ||
389 | } | ||
390 | } | ||
391 | //console.log("number of password fields found: " + passwordFieldsFound); | ||
392 | return (passwordFieldsFound == 1); | ||
393 | }; | ||
394 | |||
395 | //----------------------------------------------------------------------------- | ||
396 | |||
397 | findLoginForm = function(aDocument, aLevel) { | ||
398 | varresult; | ||
399 | vardocumentForms; | ||
400 | var i,c; | ||
401 | |||
402 | result = null; | ||
403 | |||
404 | try { | ||
405 | documentForms = aDocument.getElementsByTagName('form'); | ||
406 | |||
407 | c = documentForms.length; | ||
408 | for (i=0; (i<c) && (result == null); i++) { | ||
409 | if (isLoginForm(documentForms[i])) { | ||
410 | result = documentForms[i]; | ||
411 | } | ||
412 | } | ||
413 | |||
414 | if ((result == null) && (aLevel == 0)) { | ||
415 | var iFrames; | ||
416 | |||
417 | iFrames = aDocument.getElementsByTagName('iframe'); | ||
418 | c = iFrames.length; | ||
419 | for (i=0; (i<c) && (result == null); i++) { | ||
420 | result = findLoginForm(iFrames[i].contentDocument, (aLevel + 1)); | ||
421 | } | ||
422 | } | ||
423 | } catch (e) { | ||
424 | _cble = e; | ||
425 | } | ||
426 | |||
427 | return result; | ||
428 | }; | ||
429 | |||
430 | //----------------------------------------------------------------------------- | ||
431 | |||
432 | inputElementValues = function(anInputElement) { | ||
433 | varresult; | ||
434 | |||
435 | //if ((anInputElement instanceof HTMLInputElement) && (anInputElement.getAttribute('name') != null)) { | ||
436 | if ((anInputElement.tagName.toLowerCase() == "input") && (anInputElement.getAttribute('name') != null)) { | ||
437 | result = {}; | ||
438 | result.type = anInputElement.getAttribute('type') || "text"; | ||
439 | result.name = anInputElement.getAttribute('name'); | ||
440 | // result.value = anInputElement.getAttribute('value'); | ||
441 | result.value = anInputElement.value; | ||
442 | if (anInputElement.type.toLowerCase() == 'radio') { | ||
443 | result.checked = anInputElement.checked; | ||
444 | } | ||
445 | //} else if ((anInputElement instanceof HTMLSelectElement) && (anInputElement.getAttribute('name') != null)) { | ||
446 | } else if ((anInputElement.tagName.toLowerCase() == 'select') && (anInputElement.getAttribute('name') != null)) { | ||
447 | varoptions; | ||
448 | var c,i; | ||
449 | |||
450 | //console.log("input element values: %o", anInputElement); | ||
451 | result = {}; | ||
452 | result.type = "select"; | ||
453 | result.name = anInputElement.getAttribute('name'); | ||
454 | |||
455 | result.options = []; | ||
456 | options = anInputElement.options; | ||
457 | c = options.length; | ||
458 | for (i=0; i<c; i++) { | ||
459 | varoption; | ||
460 | |||
461 | option = {}; | ||
462 | option.selected = options[i].selected; | ||
463 | option.label = options[i].label || options[i].innerHTML; | ||
464 | option.value = options[i].value; | ||
465 | result.options.push(option); | ||
466 | } | ||
467 | } else { | ||
468 | result = null; | ||
469 | } | ||
470 | |||
471 | return result; | ||
472 | }; | ||
473 | |||
474 | //----------------------------------------------------------------------------- | ||
475 | |||
476 | formParameters = function(aLoginForm) { | ||
477 | varresult; | ||
478 | vari, c; | ||
479 | varaction; | ||
480 | |||
481 | if (aLoginForm == null) { | ||
482 | result = null; | ||
483 | } else { | ||
484 | varradioValues; | ||
485 | varradioValueName; | ||
486 | |||
487 | result = {}; | ||
488 | radioValues = {}; | ||
489 | |||
490 | action = aLoginForm.action; | ||
491 | if (action.constructor != String) { | ||
492 | action = aLoginForm.getAttribute('action'); | ||
493 | } | ||
494 | |||
495 | if (/^https?\:\/\/.*/.test(action)) { | ||
496 | action = action; | ||
497 | } else if (/^\/.*/.test(action)) { | ||
498 | action = window.location.protocol + '/' + '/' + window.location.hostname + action; | ||
499 | } else { | ||
500 | action = window.location.href.replace(/\/[^\/]*$/, '/' + action); | ||
501 | } | ||
502 | |||
503 | result.attributes = {}; | ||
504 | result.attributes.action = action; | ||
505 | result.attributes.method = aLoginForm.getAttribute('method'); | ||
506 | |||
507 | result.inputs = []; | ||
508 | c = aLoginForm.elements.length; | ||
509 | for (i=0; i<c; i++) { | ||
510 | varinputElement; | ||
511 | varelementValues; | ||
512 | |||
513 | inputElement = aLoginForm.elements[i]; | ||
514 | elementValues = inputElementValues(inputElement); | ||
515 | if (elementValues != null) { | ||
516 | if (elementValues.type != "radio") { | ||
517 | result.inputs.push(elementValues); | ||
518 | } else { | ||
519 | varradioValue; | ||
520 | varvalues; | ||
521 | |||
522 | radioValue = radioValues[elementValues.name]; | ||
523 | if (radioValue == null) { | ||
524 | radioValue = {}; | ||
525 | radioValue.name = elementValues.name; | ||
526 | radioValue.type = "radio"; | ||
527 | radioValue.options = []; | ||
528 | |||
529 | radioValues[elementValues.name] = radioValue; | ||
530 | } | ||
531 | |||
532 | values = {}; | ||
533 | values.value = elementValues.value; | ||
534 | values.checked = elementValues.checked; | ||
535 | |||
536 | radioValue.options.push(values); | ||
537 | } | ||
538 | } | ||
539 | } | ||
540 | |||
541 | for (radioValueName in radioValues) { | ||
542 | if (typeof(radioValues[radioValueName]) != "function") { | ||
543 | result.inputs.push(radioValues[radioValueName]); | ||
544 | } | ||
545 | } | ||
546 | } | ||
547 | |||
548 | return result; | ||
549 | }; | ||
550 | |||
551 | //----------------------------------------------------------------------------- | ||
552 | |||
553 | selectFaviconURL = function () { | ||
554 | var result; | ||
555 | var links; | ||
556 | var link; | ||
557 | var i; | ||
558 | |||
559 | // <link rel="icon" type="image/x-icon" href="http://example.com/favicon.ico" /> | ||
560 | // <link rel="icon" type="image/vnd.microsoft.icon"href="http://example.com/image.ico" /> | ||
561 | // <link rel="SHORTCUT ICON" type="image/x-icon" href="/horde/imp/graphics/favicon.ico" /> | ||
562 | links = document.getElementsByTagName("head")[0].getElementsByTagName('link'); | ||
563 | |||
564 | i = 0; | ||
565 | link = null; | ||
566 | while ((link == null) && (i < links.length)) { | ||
567 | if ((links[i].rel.toLowerCase() == 'icon') || (links[i].rel.toLowerCase() == 'shortcut icon')) { | ||
568 | link = links[i]; | ||
569 | } | ||
570 | |||
571 | i++; | ||
572 | } | ||
573 | |||
574 | if (link != null) { | ||
575 | result = link.href; | ||
576 | } else { | ||
577 | result = "http://" + window.location.hostname + "/favicon.ico"; | ||
578 | } | ||
579 | |||
580 | return result; | ||
581 | } | ||
582 | |||
583 | //----------------------------------------------------------------------------- | ||
584 | |||
585 | pageParameters = function() { | ||
586 | var result; | ||
587 | |||
588 | result = {}; | ||
589 | result['title'] = document.title; | ||
590 | result['favicon'] = selectFaviconURL(); | ||
591 | result['url'] = window.location.href; | ||
592 | |||
593 | return result; | ||
594 | }; | ||
595 | |||
596 | //----------------------------------------------------------------------------- | ||
597 | |||
598 | reprString = function (o) { | ||
599 | return ('"' + o.replace(/(["\\])/g, '\\$1') + '"' | ||
600 | ).replace(/[\f]/g, "\\f" | ||
601 | ).replace(/[\b]/g, "\\b" | ||
602 | ).replace(/[\n]/g, "\\n" | ||
603 | ).replace(/[\t]/g, "\\t" | ||
604 | ).replace(/[\r]/g, "\\r"); | ||
605 | }; | ||
606 | |||
607 | //----------------------------------------------------------------------------- | ||
608 | |||
609 | serializeJSON = function (o) { | ||
610 | var objtype = typeof(o); | ||
611 | if (objtype == "number" || objtype == "boolean") { | ||
612 | return o + ""; | ||
613 | } else if (o === null) { | ||
614 | return "null"; | ||
615 | } | ||
616 | |||
617 | //var m = MochiKit.Base; | ||
618 | //var reprString = m.reprString; | ||
619 | if (objtype == "string") { | ||
620 | return reprString(o); | ||
621 | } | ||
622 | |||
623 | //recurse | ||
624 | var me = arguments.callee; | ||
625 | //array | ||
626 | if (objtype != "function" && typeof(o.length) == "number") { | ||
627 | var res = []; | ||
628 | for (var i = 0; i < o.length; i++) { | ||
629 | var val = me(o[i]); | ||
630 | if (typeof(val) != "string") { | ||
631 | val = "undefined"; | ||
632 | } | ||
633 | res.push(val); | ||
634 | } | ||
635 | return "[" + res.join(",\n") + "]"; | ||
636 | } | ||
637 | |||
638 | //undefined is outside of the spec | ||
639 | if (objtype == "undefined") { | ||
640 | // throw new TypeError("undefined can not be serialized as JSON"); | ||
641 | throw new TypeError("error"); | ||
642 | } | ||
643 | |||
644 | //generic object code path | ||
645 | res = []; | ||
646 | for (var k in o) { | ||
647 | if (typeof(o[k]) != "function") { | ||
648 | var useKey; | ||
649 | if (typeof(k) == "number") { | ||
650 | useKey = '"' + k + '"'; | ||
651 | } else if (typeof(k) == "string") { | ||
652 | useKey = reprString(k); | ||
653 | } else { | ||
654 | //skip non-string or number keys | ||
655 | continue; | ||
656 | } | ||
657 | |||
658 | val = me(o[k]); | ||
659 | if (typeof(val) != "string") { | ||
660 | //skip non-serializable values | ||
661 | continue; | ||
662 | } | ||
663 | res.push(useKey + ":" + " " + val); | ||
664 | } | ||
665 | } | ||
666 | |||
667 | return "{" + res.join(",\n") + "}"; | ||
668 | }; | ||
669 | |||
670 | //----------------------------------------------------------------------------- | ||
671 | |||
672 | getLoginFormConfiguration = function() { | ||
673 | varparameters; | ||
674 | |||
675 | parameters = {}; | ||
676 | parameters.page = pageParameters(); | ||
677 | parameters.form = formParameters(findLoginForm(document, 0)); | ||
678 | parameters.version = "0.3.0"; | ||
679 | |||
680 | return parameters; | ||
681 | } | ||
682 | |||
683 | //############################################################################# | ||
684 | |||
685 | //----------------------------------------------------------------------------- | ||
686 | |||
687 | closeClick = function () { | ||
688 | varbookmarkletDiv; | ||
689 | |||
690 | bookmarkletDiv = document.getElementById("clipperzBookmarkletWrapper"); | ||
691 | bookmarkletDiv.parentNode.removeChild(bookmarkletDiv); | ||
692 | }; | ||
693 | |||
694 | //----------------------------------------------------------------------------- | ||
695 | |||
696 | logFormParameters = function(someParameters, anException) { | ||
697 | var showException; | ||
698 | varmessage; | ||
699 | |||
700 | if ((someParameters != null) && (someParameters.form != null) && (anException == null)) { | ||
701 | showException = false; | ||
702 | message = traslatableTexts['noExceptionMessage']; | ||
703 | } else { | ||
704 | showException = true | ||
705 | message = traslatableTexts['exceptionMessage']; | ||
706 | } | ||
707 | |||
708 | var newCSS = document.createElement('link'); | ||
709 | newCSS.setAttribute("type", "text/css"); | ||
710 | newCSS.setAttribute("rel", "stylesheet"); | ||
711 | newCSS.setAttribute("media", "screen"); | ||
712 | newCSS.setAttribute("href", "http://www.clipperz.com/files/clipperz.com/bookmarklet/0.3.0/Bookmarklet.css"); | ||
713 | document.getElementsByTagName("head")[0].appendChild(newCSS); | ||
714 | |||
715 | var innerHTML; | ||
716 | |||
717 | innerHTML = ""; | ||
718 | innerHTML +="<div id='clipperzBookmarklet'>" + | ||
719 | "<div id='clipperzBookmarkletClose'></div>" + | ||
720 | "<div id='clipperzBookmarkletResult'>" + | ||
721 | "<div id='clipperzBookmarkletResultIcon' class=" + ((showException == false) ? 'ok' : 'fail') + "></div>" + | ||
722 | "<p id='clipperzBookmarkletResultText'>" + message + "</p>" + | ||
723 | "</div>"; | ||
724 | |||
725 | if (showException == false) { | ||
726 | innerHTML +="<div id='clipperzBookmarletButton'><span>" + traslatableTexts['copy'] + "</span></div>" + | ||
727 | "<div id='clipperzBookmarletAfterCopyHint' class='hidden'>" + | ||
728 | "<p id='clipperzBookmarkletHintText'>Lorem ipsum</p>" + | ||
729 | "</div>"; | ||
730 | } | ||
731 | |||
732 | innerHTML +="</div>"; | ||
733 | |||
734 | var newDiv = document.createElement('div'); | ||
735 | newDiv.setAttribute("id", "clipperzBookmarkletWrapper"); | ||
736 | newDiv.innerHTML = innerHTML; | ||
737 | document.body.appendChild(newDiv); | ||
738 | |||
739 | $('clipperzBookmarkletClose').onclick = closeClick; | ||
740 | |||
741 | if (showException == false) { | ||
742 | $('clipperzBookmarletButton').onclick = showTooltip; | ||
743 | setTimeout("clip.glue('clipperzBookmarletButton');", 1000); | ||
744 | } | ||
745 | } | ||
746 | |||
747 | showTooltip = function () { | ||
748 | if (clipperz_copiedContentToClipboard == true) { | ||
749 | //console.log("SUCCEED"); | ||
750 | $('clipperzBookmarkletHintText').innerHTML = traslatableTexts['successfulMessage']; | ||
751 | $('clipperzBookmarletAfterCopyHint').className = 'visible'; | ||
752 | } else { | ||
753 | //console.log("FAIL"); | ||
754 | $('clipperzBookmarkletHintText').innerHTML = traslatableTexts['failMessage']; | ||
755 | } | ||
756 | } | ||
757 | |||
758 | //############################################################################# | ||
759 | |||
760 | traslatableTexts = { | ||
761 | 'noExceptionMessage':"@BOOKMARKLET_NO_EXCEPTION_MESSAGE@", | ||
762 | 'exceptionMessage': "@BOOKMARKLET_EXCEPTION_MESSAGE@", | ||
763 | 'copy': "@BOOKMARKLET_COPY@", | ||
764 | 'successfulMessage':"@BOOKMARKLET_SUCCESSFUL_MESSAGE@", | ||
765 | 'failMessage': "@BOOKMARKLET_FAIL_MESSAGE@" | ||
766 | |||
767 | // 'noExceptionMessage':"The direct login configuration has been collected.", | ||
768 | // 'exceptionMessage': "Sorry! There was an error while processing the page.", | ||
769 | // 'copy': "copy", | ||
770 | // 'successfulMessage':"DONE!", | ||
771 | // 'failMessage': "Failed! :(" | ||
772 | } | ||
773 | |||
774 | //############################################################################# | ||
775 | |||
776 | runBookmarklet = function () { | ||
777 | varparameters; | ||
778 | |||
779 | try { | ||
780 | initClip(); | ||
781 | |||
782 | parameters = getLoginFormConfiguration(); | ||
783 | //console.log("configuration", serializeJSON(parameters)) | ||
784 | clip.setText(serializeJSON(parameters)); | ||
785 | clip.setHandCursor( true ); | ||
786 | // clip.glue('clipperzBookmarletButton'); | ||
787 | |||
788 | logFormParameters(parameters, _cble); | ||
789 | } catch (e) { | ||
790 | logFormParameters(parameters, e); | ||
791 | } | ||
792 | |||
793 | }; | ||
794 | |||
795 | //############################################################################# | ||
796 | |||
797 | if (document.body != null) { | ||
798 | runBookmarklet(); | ||
799 | }; | ||
800 | |||
801 | //############################################################################# | ||