Diffstat (limited to 'frontend/gamma/js/Bookmarklet_2.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Bookmarklet_2.js | 767 |
1 files changed, 767 insertions, 0 deletions
diff --git a/frontend/gamma/js/Bookmarklet_2.js b/frontend/gamma/js/Bookmarklet_2.js new file mode 100644 index 0000000..f9c40a9 --- a/dev/null +++ b/frontend/gamma/js/Bookmarklet_2.js | |||
@@ -0,0 +1,767 @@ | |||
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 | nextId: 1, // ID of next movie | ||
45 | |||
46 | $: function(thingy) { | ||
47 | // simple DOM lookup utility function | ||
48 | if (typeof(thingy) == 'string') thingy = document.getElementById(thingy); | ||
49 | if (!thingy.addClass) { | ||
50 | // extend element with a few useful methods | ||
51 | thingy.hide = function() { this.style.display = 'none'; }; | ||
52 | thingy.show = function() { this.style.display = ''; }; | ||
53 | thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; }; | ||
54 | thingy.removeClass = function(name) { | ||
55 | this.className = this.className.replace( new RegExp("\\s*" + name + "\\s*"), " ").replace(/^\s+/, '').replace(/\s+$/, ''); | ||
56 | }; | ||
57 | thingy.hasClass = function(name) { | ||
58 | return !!this.className.match( new RegExp("\\s*" + name + "\\s*") ); | ||
59 | } | ||
60 | } | ||
61 | return thingy; | ||
62 | }, | ||
63 | |||
64 | setMoviePath: function(path) { | ||
65 | // set path to ZeroClipboard.swf | ||
66 | this.moviePath = path; | ||
67 | }, | ||
68 | |||
69 | dispatch: function(id, eventName, args) { | ||
70 | // receive event from flash movie, send to client | ||
71 | var client = this.clients[id]; | ||
72 | if (client) { | ||
73 | client.receiveEvent(eventName, args); | ||
74 | } | ||
75 | }, | ||
76 | |||
77 | register: function(id, client) { | ||
78 | // register new client to receive events | ||
79 | this.clients[id] = client; | ||
80 | }, | ||
81 | |||
82 | getDOMObjectPosition: function(obj) { | ||
83 | // get absolute coordinates for dom element | ||
84 | var info = { | ||
85 | left: 0, | ||
86 | top: 0, | ||
87 | width: obj.width ? obj.width : obj.offsetWidth, | ||
88 | height: obj.height ? obj.height : obj.offsetHeight | ||
89 | }; | ||
90 | |||
91 | while (obj) { | ||
92 | info.left += obj.offsetLeft; | ||
93 | info.top += obj.offsetTop; | ||
94 | obj = obj.offsetParent; | ||
95 | } | ||
96 | |||
97 | return info; | ||
98 | }, | ||
99 | |||
100 | Client: function(elem) { | ||
101 | // constructor for new simple upload client | ||
102 | this.handlers = {}; | ||
103 | |||
104 | // unique ID | ||
105 | this.id = ZeroClipboard.nextId++; | ||
106 | this.movieId = 'ZeroClipboardMovie_' + this.id; | ||
107 | |||
108 | // register client with singleton to receive flash events | ||
109 | ZeroClipboard.register(this.id, this); | ||
110 | |||
111 | // create movie | ||
112 | if (elem) this.glue(elem); | ||
113 | } | ||
114 | }; | ||
115 | |||
116 | ZeroClipboard.Client.prototype = { | ||
117 | |||
118 | id: 0, // unique ID for us | ||
119 | ready: false, // whether movie is ready to receive events or not | ||
120 | movie: null, // reference to movie object | ||
121 | clipText: '', // text to copy to clipboard | ||
122 | handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor | ||
123 | cssEffects: true, // enable CSS mouse effects on dom container | ||
124 | handlers: null, // user event handlers | ||
125 | |||
126 | glue: function(elem) { | ||
127 | // glue to DOM element | ||
128 | // elem can be ID or actual DOM element object | ||
129 | //console.log(">>> glue"); | ||
130 | this.domElement = ZeroClipboard.$(elem); | ||
131 | |||
132 | // float just above object, or zIndex 99 if dom element isn't set | ||
133 | var zIndex = 99; | ||
134 | if (this.domElement.style.zIndex) { | ||
135 | zIndex = parseInt(this.domElement.style.zIndex) + 1; | ||
136 | } | ||
137 | |||
138 | // find X/Y position of domElement | ||
139 | var box = ZeroClipboard.getDOMObjectPosition(this.domElement); | ||
140 | |||
141 | // create floating DIV above element | ||
142 | this.div = document.createElement('div'); | ||
143 | var style = this.div.style; | ||
144 | style.position = 'absolute'; | ||
145 | style.left = '' + box.left + 'px'; | ||
146 | style.top = '' + box.top + 'px'; | ||
147 | style.width = '' + box.width + 'px'; | ||
148 | style.height = '' + box.height + 'px'; | ||
149 | style.zIndex = zIndex; | ||
150 | |||
151 | // style.backgroundColor = '#f00'; // debug | ||
152 | |||
153 | var body = document.getElementsByTagName('body')[0]; | ||
154 | body.appendChild(this.div); | ||
155 | |||
156 | this.div.innerHTML = this.getHTML( box.width, box.height ); | ||
157 | //console.log("<<< glue"); | ||
158 | }, | ||
159 | |||
160 | getHTML: function(width, height) { | ||
161 | // return HTML for movie | ||
162 | var html = ''; | ||
163 | var flashvars = 'id=' + this.id + | ||
164 | '&width=' + width + | ||
165 | '&height=' + height; | ||
166 | |||
167 | if (navigator.userAgent.match(/MSIE/)) { | ||
168 | // IE gets an OBJECT tag | ||
169 | var protocol = location.href.match(/^https/i) ? 'https://' : 'http://'; | ||
170 | 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>'; | ||
171 | } | ||
172 | else { | ||
173 | // all other browsers get an EMBED tag | ||
174 | 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" />'; | ||
175 | } | ||
176 | return html; | ||
177 | }, | ||
178 | |||
179 | hide: function() { | ||
180 | // temporarily hide floater offscreen | ||
181 | if (this.div) { | ||
182 | this.div.style.left = '-2000px'; | ||
183 | } | ||
184 | }, | ||
185 | |||
186 | show: function() { | ||
187 | // show ourselves after a call to hide() | ||
188 | this.reposition(); | ||
189 | }, | ||
190 | |||
191 | destroy: function() { | ||
192 | // destroy control and floater | ||
193 | if (this.domElement && this.div) { | ||
194 | this.hide(); | ||
195 | this.div.innerHTML = ''; | ||
196 | |||
197 | var body = document.getElementsByTagName('body')[0]; | ||
198 | try { body.removeChild( this.div ); } catch(e) {;} | ||
199 | |||
200 | this.domElement = null; | ||
201 | this.div = null; | ||
202 | } | ||
203 | }, | ||
204 | |||
205 | reposition: function(elem) { | ||
206 | // reposition our floating div, optionally to new container | ||
207 | // warning: container CANNOT change size, only position | ||
208 | if (elem) { | ||
209 | this.domElement = ZeroClipboard.$(elem); | ||
210 | if (!this.domElement) this.hide(); | ||
211 | } | ||
212 | |||
213 | if (this.domElement && this.div) { | ||
214 | var box = ZeroClipboard.getDOMObjectPosition(this.domElement); | ||
215 | var style = this.div.style; | ||
216 | style.left = '' + box.left + 'px'; | ||
217 | style.top = '' + box.top + 'px'; | ||
218 | } | ||
219 | }, | ||
220 | |||
221 | setText: function(newText) { | ||
222 | // set text to be copied to clipboard | ||
223 | this.clipText = newText; | ||
224 | if (this.ready) this.movie.setText(newText); | ||
225 | }, | ||
226 | |||
227 | addEventListener: function(eventName, func) { | ||
228 | // add user event listener for event | ||
229 | // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel | ||
230 | eventName = eventName.toString().toLowerCase().replace(/^on/, ''); | ||
231 | if (!this.handlers[eventName]) this.handlers[eventName] = []; | ||
232 | this.handlers[eventName].push(func); | ||
233 | }, | ||
234 | |||
235 | setHandCursor: function(enabled) { | ||
236 | // enable hand cursor (true), or default arrow cursor (false) | ||
237 | this.handCursorEnabled = enabled; | ||
238 | if (this.ready) this.movie.setHandCursor(enabled); | ||
239 | }, | ||
240 | |||
241 | setCSSEffects: function(enabled) { | ||
242 | // enable or disable CSS effects on DOM container | ||
243 | this.cssEffects = !!enabled; | ||
244 | }, | ||
245 | |||
246 | receiveEvent: function(eventName, args) { | ||
247 | // receive event from flash | ||
248 | eventName = eventName.toString().toLowerCase().replace(/^on/, ''); | ||
249 | |||
250 | // special behavior for certain events | ||
251 | switch (eventName) { | ||
252 | case 'load': | ||
253 | // movie claims it is ready, but in IE this isn't always the case... | ||
254 | // bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function | ||
255 | this.movie = document.getElementById(this.movieId); | ||
256 | if (!this.movie) { | ||
257 | var self = this; | ||
258 | setTimeout( function() { self.receiveEvent('load', null); }, 1 ); | ||
259 | return; | ||
260 | } | ||
261 | |||
262 | // firefox on pc needs a "kick" in order to set these in certain cases | ||
263 | if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) { | ||
264 | var self = this; | ||
265 | setTimeout( function() { self.receiveEvent('load', null); }, 100 ); | ||
266 | this.ready = true; | ||
267 | return; | ||
268 | } | ||
269 | |||
270 | this.ready = true; | ||
271 | this.movie.setText( this.clipText ); | ||
272 | this.movie.setHandCursor( this.handCursorEnabled ); | ||
273 | break; | ||
274 | |||
275 | case 'mouseover': | ||
276 | if (this.domElement && this.cssEffects) { | ||
277 | this.domElement.addClass('hover'); | ||
278 | if (this.recoverActive) this.domElement.addClass('active'); | ||
279 | } | ||
280 | break; | ||
281 | |||
282 | case 'mouseout': | ||
283 | if (this.domElement && this.cssEffects) { | ||
284 | this.recoverActive = false; | ||
285 | if (this.domElement.hasClass('active')) { | ||
286 | this.domElement.removeClass('active'); | ||
287 | this.recoverActive = true; | ||
288 | } | ||
289 | this.domElement.removeClass('hover'); | ||
290 | } | ||
291 | break; | ||
292 | |||
293 | case 'mousedown': | ||
294 | if (this.domElement && this.cssEffects) { | ||
295 | this.domElement.addClass('active'); | ||
296 | } | ||
297 | break; | ||
298 | |||
299 | case 'mouseup': | ||
300 | if (this.domElement && this.cssEffects) { | ||
301 | this.domElement.removeClass('active'); | ||
302 | this.recoverActive = false; | ||
303 | } | ||
304 | break; | ||
305 | } // switch eventName | ||
306 | |||
307 | if (this.handlers[eventName]) { | ||
308 | for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) { | ||
309 | var func = this.handlers[eventName][idx]; | ||
310 | |||
311 | if (typeof(func) == 'function') { | ||
312 | // actual function reference | ||
313 | func(this, args); | ||
314 | } | ||
315 | else if ((typeof(func) == 'object') && (func.length == 2)) { | ||
316 | // PHP style object + method, i.e. [myObject, 'myMethod'] | ||
317 | func[0][ func[1] ](this, args); | ||
318 | } | ||
319 | else if (typeof(func) == 'string') { | ||
320 | // name of function | ||
321 | window[func](this, args); | ||
322 | } | ||
323 | } // foreach event handler defined | ||
324 | } // user defined handler for event | ||
325 | } | ||
326 | |||
327 | }; | ||
328 | |||
329 | //############################################################################# | ||
330 | |||
331 | var clip = null; | ||
332 | |||
333 | function $(id) { return document.getElementById(id); } | ||
334 | |||
335 | function initClip() { | ||
336 | //console.log(">>> initClip"); | ||
337 | clip = new ZeroClipboard.Client(); | ||
338 | clip.setHandCursor( true ); | ||
339 | |||
340 | //clip.addEventListener('load', my_load); | ||
341 | //clip.addEventListener('mouseOver', my_mouse_over); | ||
342 | clip.addEventListener('complete', my_complete); | ||
343 | |||
344 | //clip.glue( 'd_clip_button' ); | ||
345 | //console.log("<<< initClip"); | ||
346 | } | ||
347 | |||
348 | //function my_load(client) { | ||
349 | //console.log("Flash movie loaded and ready."); | ||
350 | //} | ||
351 | |||
352 | //function my_mouse_over(client) { | ||
353 | //// we can cheat a little here -- update the text on mouse over | ||
354 | //clip.setText( $('fe_text').value ); | ||
355 | //} | ||
356 | |||
357 | function my_complete(client, text) { | ||
358 | //console.log("Copied text to clipboard: ... "); | ||
359 | //console.log("Copied text to clipboard: " + text ); | ||
360 | clipperz_copiedContentToClipboard = true; | ||
361 | showTooltip(); | ||
362 | } | ||
363 | |||
364 | //function debugstr(msg) { | ||
365 | //var p = document.createElement('p'); | ||
366 | //p.innerHTML = msg; | ||
367 | //$('d_debug').appendChild(p); | ||
368 | //} | ||
369 | |||
370 | //############################################################################# | ||
371 | |||
372 | _cble = null; | ||
373 | |||
374 | //----------------------------------------------------------------------------- | ||
375 | |||
376 | isLoginForm = function(aForm) { | ||
377 | var inputFields; | ||
378 | var passwordFieldsFound; | ||
379 | var i,c; | ||
380 | |||
381 | //console.log("is login form: " + aForm.name + " (" + aForm.id + ")"); | ||
382 | passwordFieldsFound = 0; | ||
383 | inputFields = aForm.elements; | ||
384 | c = inputFields.length; | ||
385 | for (i=0; i<c; i++) { | ||
386 | if (inputFields[i].type == "password") { | ||
387 | passwordFieldsFound ++; | ||
388 | } | ||
389 | } | ||
390 | //console.log("number of password fields found: " + passwordFieldsFound); | ||
391 | return (passwordFieldsFound == 1); | ||
392 | }; | ||
393 | |||
394 | //----------------------------------------------------------------------------- | ||
395 | |||
396 | findLoginForm = function(aDocument, aLevel) { | ||
397 | varresult; | ||
398 | vardocumentForms; | ||
399 | var i,c; | ||
400 | |||
401 | result = null; | ||
402 | |||
403 | try { | ||
404 | documentForms = aDocument.getElementsByTagName('form'); | ||
405 | |||
406 | c = documentForms.length; | ||
407 | for (i=0; (i<c) && (result == null); i++) { | ||
408 | if (isLoginForm(documentForms[i])) { | ||
409 | result = documentForms[i]; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | if ((result == null) && (aLevel == 0)) { | ||
414 | var iFrames; | ||
415 | |||
416 | iFrames = aDocument.getElementsByTagName('iframe'); | ||
417 | c = iFrames.length; | ||
418 | for (i=0; (i<c) && (result == null); i++) { | ||
419 | result = findLoginForm(iFrames[i].contentDocument, (aLevel + 1)); | ||
420 | } | ||
421 | } | ||
422 | } catch (e) { | ||
423 | _cble = e; | ||
424 | } | ||
425 | |||
426 | return result; | ||
427 | }; | ||
428 | |||
429 | //----------------------------------------------------------------------------- | ||
430 | |||
431 | inputElementValues = function(anInputElement) { | ||
432 | varresult; | ||
433 | |||
434 | //if ((anInputElement instanceof HTMLInputElement) && (anInputElement.getAttribute('name') != null)) { | ||
435 | if ((anInputElement.tagName.toLowerCase() == "input") && (anInputElement.getAttribute('name') != null)) { | ||
436 | result = {}; | ||
437 | result.type = anInputElement.getAttribute('type') || "text"; | ||
438 | result.name = anInputElement.getAttribute('name'); | ||
439 | // result.value = anInputElement.getAttribute('value'); | ||
440 | result.value = anInputElement.value; | ||
441 | if (anInputElement.type.toLowerCase() == 'radio') { | ||
442 | result.checked = anInputElement.checked; | ||
443 | } | ||
444 | //} else if ((anInputElement instanceof HTMLSelectElement) && (anInputElement.getAttribute('name') != null)) { | ||
445 | } else if ((anInputElement.tagName.toLowerCase() == 'select') && (anInputElement.getAttribute('name') != null)) { | ||
446 | varoptions; | ||
447 | var c,i; | ||
448 | |||
449 | //console.log("input element values: %o", anInputElement); | ||
450 | result = {}; | ||
451 | result.type = "select"; | ||
452 | result.name = anInputElement.getAttribute('name'); | ||
453 | |||
454 | result.options = []; | ||
455 | options = anInputElement.options; | ||
456 | c = options.length; | ||
457 | for (i=0; i<c; i++) { | ||
458 | varoption; | ||
459 | |||
460 | option = {}; | ||
461 | option.selected = options[i].selected; | ||
462 | option.label = options[i].label || options[i].innerHTML; | ||
463 | option.value = options[i].value; | ||
464 | result.options.push(option); | ||
465 | } | ||
466 | } else { | ||
467 | result = null; | ||
468 | } | ||
469 | |||
470 | return result; | ||
471 | }; | ||
472 | |||
473 | //----------------------------------------------------------------------------- | ||
474 | |||
475 | formParameters = function(aLoginForm) { | ||
476 | varresult; | ||
477 | vari, c; | ||
478 | varaction; | ||
479 | |||
480 | if (aLoginForm == null) { | ||
481 | result = null; | ||
482 | } else { | ||
483 | varradioValues; | ||
484 | varradioValueName; | ||
485 | |||
486 | result = {}; | ||
487 | radioValues = {}; | ||
488 | |||
489 | action = aLoginForm.action; | ||
490 | if (action.constructor != String) { | ||
491 | action = aLoginForm.getAttribute('action'); | ||
492 | } | ||
493 | |||
494 | if (/^https?\:\/\/.*/.test(action)) { | ||
495 | action = action; | ||
496 | } else if (/^\/.*/.test(action)) { | ||
497 | action = window.location.protocol + '/' + '/' + window.location.hostname + action; | ||
498 | } else { | ||
499 | action = window.location.href.replace(/\/[^\/]*$/, '/' + action); | ||
500 | } | ||
501 | |||
502 | result.attributes = {}; | ||
503 | result.attributes.action = action; | ||
504 | result.attributes.method = aLoginForm.getAttribute('method'); | ||
505 | |||
506 | result.inputs = []; | ||
507 | c = aLoginForm.elements.length; | ||
508 | for (i=0; i<c; i++) { | ||
509 | varinputElement; | ||
510 | varelementValues; | ||
511 | |||
512 | inputElement = aLoginForm.elements[i]; | ||
513 | elementValues = inputElementValues(inputElement); | ||
514 | if (elementValues != null) { | ||
515 | if (elementValues.type != "radio") { | ||
516 | result.inputs.push(elementValues); | ||
517 | } else { | ||
518 | varradioValue; | ||
519 | varvalues; | ||
520 | |||
521 | radioValue = radioValues[elementValues.name]; | ||
522 | if (radioValue == null) { | ||
523 | radioValue = {}; | ||
524 | radioValue.name = elementValues.name; | ||
525 | radioValue.type = "radio"; | ||
526 | radioValue.options = []; | ||
527 | |||
528 | radioValues[elementValues.name] = radioValue; | ||
529 | } | ||
530 | |||
531 | values = {}; | ||
532 | values.value = elementValues.value; | ||
533 | values.checked = elementValues.checked; | ||
534 | |||
535 | radioValue.options.push(values); | ||
536 | } | ||
537 | } | ||
538 | } | ||
539 | |||
540 | for (radioValueName in radioValues) { | ||
541 | if (typeof(radioValues[radioValueName]) != "function") { | ||
542 | result.inputs.push(radioValues[radioValueName]); | ||
543 | } | ||
544 | } | ||
545 | } | ||
546 | |||
547 | return result; | ||
548 | }; | ||
549 | |||
550 | //----------------------------------------------------------------------------- | ||
551 | |||
552 | pageParameters = function() { | ||
553 | var result; | ||
554 | |||
555 | result = {}; | ||
556 | result['title'] = document.title; | ||
557 | //<link rel="icon" href="http://example.com/favicon.ico" type="image/x-icon"> | ||
558 | |||
559 | return result; | ||
560 | }; | ||
561 | |||
562 | //----------------------------------------------------------------------------- | ||
563 | |||
564 | reprString = function (o) { | ||
565 | return ('"' + o.replace(/(["\\])/g, '\\$1') + '"' | ||
566 | ).replace(/[\f]/g, "\\f" | ||
567 | ).replace(/[\b]/g, "\\b" | ||
568 | ).replace(/[\n]/g, "\\n" | ||
569 | ).replace(/[\t]/g, "\\t" | ||
570 | ).replace(/[\r]/g, "\\r"); | ||
571 | }; | ||
572 | |||
573 | //----------------------------------------------------------------------------- | ||
574 | |||
575 | serializeJSON = function (o) { | ||
576 | var objtype = typeof(o); | ||
577 | if (objtype == "number" || objtype == "boolean") { | ||
578 | return o + ""; | ||
579 | } else if (o === null) { | ||
580 | return "null"; | ||
581 | } | ||
582 | |||
583 | //var m = MochiKit.Base; | ||
584 | //var reprString = m.reprString; | ||
585 | if (objtype == "string") { | ||
586 | return reprString(o); | ||
587 | } | ||
588 | |||
589 | //recurse | ||
590 | var me = arguments.callee; | ||
591 | //array | ||
592 | if (objtype != "function" && typeof(o.length) == "number") { | ||
593 | var res = []; | ||
594 | for (var i = 0; i < o.length; i++) { | ||
595 | var val = me(o[i]); | ||
596 | if (typeof(val) != "string") { | ||
597 | val = "undefined"; | ||
598 | } | ||
599 | res.push(val); | ||
600 | } | ||
601 | return "[" + res.join(",\n") + "]"; | ||
602 | } | ||
603 | |||
604 | //undefined is outside of the spec | ||
605 | if (objtype == "undefined") { | ||
606 | // throw new TypeError("undefined can not be serialized as JSON"); | ||
607 | throw new TypeError("error"); | ||
608 | } | ||
609 | |||
610 | //generic object code path | ||
611 | res = []; | ||
612 | for (var k in o) { | ||
613 | if (typeof(o[k]) != "function") { | ||
614 | var useKey; | ||
615 | if (typeof(k) == "number") { | ||
616 | useKey = '"' + k + '"'; | ||
617 | } else if (typeof(k) == "string") { | ||
618 | useKey = reprString(k); | ||
619 | } else { | ||
620 | //skip non-string or number keys | ||
621 | continue; | ||
622 | } | ||
623 | |||
624 | val = me(o[k]); | ||
625 | if (typeof(val) != "string") { | ||
626 | //skip non-serializable values | ||
627 | continue; | ||
628 | } | ||
629 | res.push(useKey + ":" + " " + val); | ||
630 | } | ||
631 | } | ||
632 | |||
633 | return "{" + res.join(",\n") + "}"; | ||
634 | }; | ||
635 | |||
636 | //----------------------------------------------------------------------------- | ||
637 | |||
638 | getLoginFormConfiguration = function() { | ||
639 | varparameters; | ||
640 | |||
641 | parameters = {}; | ||
642 | parameters.page = pageParameters(); | ||
643 | parameters.form = formParameters(findLoginForm(document, 0)); | ||
644 | parameters.version = "0.3.0"; | ||
645 | |||
646 | return parameters; | ||
647 | } | ||
648 | |||
649 | //############################################################################# | ||
650 | |||
651 | //----------------------------------------------------------------------------- | ||
652 | |||
653 | closeClick = function () { | ||
654 | varbookmarkletDiv; | ||
655 | |||
656 | bookmarkletDiv = document.getElementById("clipperzBookmarkletWrapper"); | ||
657 | bookmarkletDiv.parentNode.removeChild(bookmarkletDiv); | ||
658 | }; | ||
659 | |||
660 | //----------------------------------------------------------------------------- | ||
661 | |||
662 | logFormParameters = function(someParameters, anException) { | ||
663 | var showException; | ||
664 | varmessage; | ||
665 | |||
666 | if ((someParameters != null) && (someParameters.form != null) && (anException == null)) { | ||
667 | showException = false; | ||
668 | message = "The direct login configuration has been collected."; | ||
669 | } else { | ||
670 | showException = true | ||
671 | message = "Sorry! There was an error while processing the page."; | ||
672 | } | ||
673 | |||
674 | var newCSS = document.createElement('link'); | ||
675 | newCSS.setAttribute("type", "text/css"); | ||
676 | newCSS.setAttribute("rel", "stylesheet"); | ||
677 | newCSS.setAttribute("media", "screen"); | ||
678 | newCSS.setAttribute("href", "http://www.clipperz.com/files/clipperz.com/bookmarklet/0.3.0/Bookmarklet.css"); | ||
679 | //newCSS.innerHTML = cssHTML; | ||
680 | document.getElementsByTagName("head")[0].appendChild(newCSS); | ||
681 | |||
682 | var innerHTML; | ||
683 | |||
684 | innerHTML = ""; | ||
685 | // innerHTML +="<div id='clipperzBookmarklet' style='" + reset_css + clipperzBookmarklet_style + "'>" + | ||
686 | // "<div id='clipperzBookmarkletClose' style='" + reset_css + clipperzBookmarkletClose_style + "'></div>" + | ||
687 | // "<div id='clipperzBookmarkletResult' style='" + reset_css + clipperzBookmarkletResult_style + "'>" + | ||
688 | // "<div id='clipperzBookmarkletResultIcon' style='" + reset_css + clipperzBookmarkletResultIcon_style + "'></div>" + | ||
689 | // "<p id='clipperzBookmarkletResultText' style='" + reset_css + clipperzBookmarkletResultText_style + "'>" + message + "</p>" + | ||
690 | // "</div>"; | ||
691 | // | ||
692 | //if (showException == false) { | ||
693 | // innerHTML +="<div id='clipperzBookmarletButton' style='" + clipperzBookmarletButton_style + "'></div>" + | ||
694 | // "<div id='clipperzBookmarletAfterCopyHint' style='" + clipperzBookmarletAfterCopyHint_style + "'>" + | ||
695 | // "<p id='clipperzBookmarkletHintText' style='" + clipperzBookmarkletHintText_style + "'></p>" + | ||
696 | // "</div>"; | ||
697 | //} | ||
698 | |||
699 | innerHTML +="<div id='clipperzBookmarklet'>" + | ||
700 | "<div id='clipperzBookmarkletClose'></div>" + | ||
701 | "<div id='clipperzBookmarkletResult'>" + | ||
702 | "<div id='clipperzBookmarkletResultIcon'></div>" + | ||
703 | "<p id='clipperzBookmarkletResultText'>" + message + "</p>" + | ||
704 | "</div>"; | ||
705 | |||
706 | if (showException == false) { | ||
707 | innerHTML +="<div id='clipperzBookmarletButton'></div>" + | ||
708 | "<div id='clipperzBookmarletAfterCopyHint' class='hidden'>" + | ||
709 | "<p id='clipperzBookmarkletHintText'>Lorem ipsum</p>" + | ||
710 | "</div>"; | ||
711 | } | ||
712 | |||
713 | innerHTML +="</div>"; | ||
714 | |||
715 | var newDiv = document.createElement('div'); | ||
716 | newDiv.setAttribute("id", "clipperzBookmarkletWrapper"); | ||
717 | newDiv.innerHTML = innerHTML; | ||
718 | document.body.appendChild(newDiv); | ||
719 | |||
720 | $('clipperzBookmarkletClose').onclick = closeClick; | ||
721 | |||
722 | if (showException == false) { | ||
723 | $('clipperzBookmarletButton').onclick = showTooltip; | ||
724 | setTimeout("clip.glue('clipperzBookmarletButton');", 1000); | ||
725 | } | ||
726 | } | ||
727 | |||
728 | showTooltip = function () { | ||
729 | if (clipperz_copiedContentToClipboard == true) { | ||
730 | //console.log("SUCCEED"); | ||
731 | $('clipperzBookmarkletHintText').innerHTML = "DONE!"; | ||
732 | $('clipperzBookmarletAfterCopyHint').className = 'visible'; | ||
733 | } else { | ||
734 | //console.log("FAIL"); | ||
735 | $('clipperzBookmarkletHintText').innerHTML = "Failed! :("; | ||
736 | } | ||
737 | } | ||
738 | |||
739 | //############################################################################# | ||
740 | |||
741 | //############################################################################# | ||
742 | |||
743 | runBookmarklet = function () { | ||
744 | varparameters; | ||
745 | |||
746 | try { | ||
747 | initClip(); | ||
748 | |||
749 | parameters = getLoginFormConfiguration(); | ||
750 | //console.log("configuration", serializeJSON(parameters)) | ||
751 | clip.setText(serializeJSON(parameters)); | ||
752 | // clip.glue('clipperzBookmarletButton'); | ||
753 | |||
754 | logFormParameters(parameters, _cble); | ||
755 | } catch (e) { | ||
756 | logFormParameters(parameters, e); | ||
757 | } | ||
758 | |||
759 | } | ||
760 | |||
761 | //############################################################################# | ||
762 | |||
763 | if (document.body != null) { | ||
764 | runBookmarklet(); | ||
765 | } | ||
766 | |||
767 | //############################################################################# | ||