├── LICENSE ├── README └── snorql ├── index.html ├── link.png ├── namespaces.js ├── prototype.js ├── rdf_flyer.24.gif ├── scriptaculous ├── builder.js ├── controls.js ├── dragdrop.js ├── effects.js ├── scriptaculous.js ├── slider.js ├── sound.js └── unittest.js ├── snorql.js ├── sparql.js ├── style.css └── xml-to-html.xsl /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | SNORQL is an AJAXy front-end for exploring RDF SPARQL endpoints 2 | 3 | It was originally created by Richard Cyganaik ( http://richard.cyganiak.de/ ) 4 | for the D2R server project ( http://www4.wiwiss.fu-berlin.de/bizer/d2r-server/ ). 5 | 6 | SNORQL can be used with just about any SPARQL endpoint that supports JSON. To 7 | use SNORQL simply put the ./snorql directory somwhere sensible in the Apache 8 | web directory and modify ./snorql/snorql.js to conform with your setup. You 9 | can also modify the pre-defined namespaces in ./snorql/namespaces.js 10 | 11 | SNORQL is licensed under Apache-2 license (see ./LICENSE ). -------------------------------------------------------------------------------- /snorql/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Snorql: A SPARQL Explorer 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 |
20 |

Browse:

21 | 27 |
28 | 29 |
30 |

GRAPH:

31 |

32 | Default graph. 33 | List named graphs 34 |

35 |
36 | 37 |
38 |

GRAPH:

39 |

40 | Named graph goes here. 41 | Switch back to default graph 42 |

43 |
44 | 45 |
46 |

SPARQL:

47 |

48 |       
49 | 50 | 51 | 52 | 53 |
54 |
55 | 56 | Results: 57 | 63 | 64 | XSLT stylesheet URL: 65 | 66 | 67 | 68 | 69 |
70 |
71 | 72 |
73 |
74 |
75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /snorql/link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kurtjx/SNORQL/f0b9a375e0d757e9d69de144fbe8a101610aa139/snorql/link.png -------------------------------------------------------------------------------- /snorql/namespaces.js: -------------------------------------------------------------------------------- 1 | var D2R_namespacePrefixes = { 2 | rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 3 | rdfs: 'http://www.w3.org/2000/01/rdf-schema#', 4 | owl: 'http://www.w3.org/2002/07/owl#', 5 | dc: 'http://purl.org/dc/elements/1.1/', 6 | dcterms: 'http://purl.org/dc/terms/', 7 | foaf: 'http://xmlns.com/foaf/0.1/', 8 | sim: 'http://purl.org/ontology/similarity/', 9 | mo: 'http://purl.org/ontology/mo/', 10 | ov: 'http://open.vocab.org/terms/', 11 | xsd: 'http://www.w3.org/2001/XMLSchema#', 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /snorql/rdf_flyer.24.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kurtjx/SNORQL/f0b9a375e0d757e9d69de144fbe8a101610aa139/snorql/rdf_flyer.24.gif -------------------------------------------------------------------------------- /snorql/scriptaculous/builder.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us builder.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008 2 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 | // 5 | // script.aculo.us is freely distributable under the terms of an MIT-style license. 6 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 7 | 8 | var Builder = { 9 | NODEMAP: { 10 | AREA: 'map', 11 | CAPTION: 'table', 12 | COL: 'table', 13 | COLGROUP: 'table', 14 | LEGEND: 'fieldset', 15 | OPTGROUP: 'select', 16 | OPTION: 'select', 17 | PARAM: 'object', 18 | TBODY: 'table', 19 | TD: 'table', 20 | TFOOT: 'table', 21 | TH: 'table', 22 | THEAD: 'table', 23 | TR: 'table' 24 | }, 25 | // note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken, 26 | // due to a Firefox bug 27 | node: function(elementName) { 28 | elementName = elementName.toUpperCase(); 29 | 30 | // try innerHTML approach 31 | var parentTag = this.NODEMAP[elementName] || 'div'; 32 | var parentElement = document.createElement(parentTag); 33 | try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707 34 | parentElement.innerHTML = "<" + elementName + ">"; 35 | } catch(e) {} 36 | var element = parentElement.firstChild || null; 37 | 38 | // see if browser added wrapping tags 39 | if(element && (element.tagName.toUpperCase() != elementName)) 40 | element = element.getElementsByTagName(elementName)[0]; 41 | 42 | // fallback to createElement approach 43 | if(!element) element = document.createElement(elementName); 44 | 45 | // abort if nothing could be created 46 | if(!element) return; 47 | 48 | // attributes (or text) 49 | if(arguments[1]) 50 | if(this._isStringOrNumber(arguments[1]) || 51 | (arguments[1] instanceof Array) || 52 | arguments[1].tagName) { 53 | this._children(element, arguments[1]); 54 | } else { 55 | var attrs = this._attributes(arguments[1]); 56 | if(attrs.length) { 57 | try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707 58 | parentElement.innerHTML = "<" +elementName + " " + 59 | attrs + ">"; 60 | } catch(e) {} 61 | element = parentElement.firstChild || null; 62 | // workaround firefox 1.0.X bug 63 | if(!element) { 64 | element = document.createElement(elementName); 65 | for(attr in arguments[1]) 66 | element[attr == 'class' ? 'className' : attr] = arguments[1][attr]; 67 | } 68 | if(element.tagName.toUpperCase() != elementName) 69 | element = parentElement.getElementsByTagName(elementName)[0]; 70 | } 71 | } 72 | 73 | // text, or array of children 74 | if(arguments[2]) 75 | this._children(element, arguments[2]); 76 | 77 | return element; 78 | }, 79 | _text: function(text) { 80 | return document.createTextNode(text); 81 | }, 82 | 83 | ATTR_MAP: { 84 | 'className': 'class', 85 | 'htmlFor': 'for' 86 | }, 87 | 88 | _attributes: function(attributes) { 89 | var attrs = []; 90 | for(attribute in attributes) 91 | attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) + 92 | '="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'"') + '"'); 93 | return attrs.join(" "); 94 | }, 95 | _children: function(element, children) { 96 | if(children.tagName) { 97 | element.appendChild(children); 98 | return; 99 | } 100 | if(typeof children=='object') { // array can hold nodes and text 101 | children.flatten().each( function(e) { 102 | if(typeof e=='object') 103 | element.appendChild(e) 104 | else 105 | if(Builder._isStringOrNumber(e)) 106 | element.appendChild(Builder._text(e)); 107 | }); 108 | } else 109 | if(Builder._isStringOrNumber(children)) 110 | element.appendChild(Builder._text(children)); 111 | }, 112 | _isStringOrNumber: function(param) { 113 | return(typeof param=='string' || typeof param=='number'); 114 | }, 115 | build: function(html) { 116 | var element = this.node('div'); 117 | $(element).update(html.strip()); 118 | return element.down(); 119 | }, 120 | dump: function(scope) { 121 | if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope 122 | 123 | var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " + 124 | "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " + 125 | "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+ 126 | "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+ 127 | "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+ 128 | "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/); 129 | 130 | tags.each( function(tag){ 131 | scope[tag] = function() { 132 | return Builder.node.apply(Builder, [tag].concat($A(arguments))); 133 | } 134 | }); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /snorql/scriptaculous/controls.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us controls.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008 2 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 | // (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan) 5 | // (c) 2005-2007 Jon Tirsen (http://www.tirsen.com) 6 | // Contributors: 7 | // Richard Livsey 8 | // Rahul Bhargava 9 | // Rob Wills 10 | // 11 | // script.aculo.us is freely distributable under the terms of an MIT-style license. 12 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 13 | 14 | // Autocompleter.Base handles all the autocompletion functionality 15 | // that's independent of the data source for autocompletion. This 16 | // includes drawing the autocompletion menu, observing keyboard 17 | // and mouse events, and similar. 18 | // 19 | // Specific autocompleters need to provide, at the very least, 20 | // a getUpdatedChoices function that will be invoked every time 21 | // the text inside the monitored textbox changes. This method 22 | // should get the text for which to provide autocompletion by 23 | // invoking this.getToken(), NOT by directly accessing 24 | // this.element.value. This is to allow incremental tokenized 25 | // autocompletion. Specific auto-completion logic (AJAX, etc) 26 | // belongs in getUpdatedChoices. 27 | // 28 | // Tokenized incremental autocompletion is enabled automatically 29 | // when an autocompleter is instantiated with the 'tokens' option 30 | // in the options parameter, e.g.: 31 | // new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' }); 32 | // will incrementally autocomplete with a comma as the token. 33 | // Additionally, ',' in the above example can be replaced with 34 | // a token array, e.g. { tokens: [',', '\n'] } which 35 | // enables autocompletion on multiple tokens. This is most 36 | // useful when one of the tokens is \n (a newline), as it 37 | // allows smart autocompletion after linebreaks. 38 | 39 | if(typeof Effect == 'undefined') 40 | throw("controls.js requires including script.aculo.us' effects.js library"); 41 | 42 | var Autocompleter = { } 43 | Autocompleter.Base = Class.create({ 44 | baseInitialize: function(element, update, options) { 45 | element = $(element) 46 | this.element = element; 47 | this.update = $(update); 48 | this.hasFocus = false; 49 | this.changed = false; 50 | this.active = false; 51 | this.index = 0; 52 | this.entryCount = 0; 53 | this.oldElementValue = this.element.value; 54 | 55 | if(this.setOptions) 56 | this.setOptions(options); 57 | else 58 | this.options = options || { }; 59 | 60 | this.options.paramName = this.options.paramName || this.element.name; 61 | this.options.tokens = this.options.tokens || []; 62 | this.options.frequency = this.options.frequency || 0.4; 63 | this.options.minChars = this.options.minChars || 1; 64 | this.options.onShow = this.options.onShow || 65 | function(element, update){ 66 | if(!update.style.position || update.style.position=='absolute') { 67 | update.style.position = 'absolute'; 68 | Position.clone(element, update, { 69 | setHeight: false, 70 | offsetTop: element.offsetHeight 71 | }); 72 | } 73 | Effect.Appear(update,{duration:0.15}); 74 | }; 75 | this.options.onHide = this.options.onHide || 76 | function(element, update){ new Effect.Fade(update,{duration:0.15}) }; 77 | 78 | if(typeof(this.options.tokens) == 'string') 79 | this.options.tokens = new Array(this.options.tokens); 80 | // Force carriage returns as token delimiters anyway 81 | if (!this.options.tokens.include('\n')) 82 | this.options.tokens.push('\n'); 83 | 84 | this.observer = null; 85 | 86 | this.element.setAttribute('autocomplete','off'); 87 | 88 | Element.hide(this.update); 89 | 90 | Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this)); 91 | Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this)); 92 | }, 93 | 94 | show: function() { 95 | if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update); 96 | if(!this.iefix && 97 | (Prototype.Browser.IE) && 98 | (Element.getStyle(this.update, 'position')=='absolute')) { 99 | new Insertion.After(this.update, 100 | ''); 103 | this.iefix = $(this.update.id+'_iefix'); 104 | } 105 | if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50); 106 | }, 107 | 108 | fixIEOverlapping: function() { 109 | Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)}); 110 | this.iefix.style.zIndex = 1; 111 | this.update.style.zIndex = 2; 112 | Element.show(this.iefix); 113 | }, 114 | 115 | hide: function() { 116 | this.stopIndicator(); 117 | if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update); 118 | if(this.iefix) Element.hide(this.iefix); 119 | }, 120 | 121 | startIndicator: function() { 122 | if(this.options.indicator) Element.show(this.options.indicator); 123 | }, 124 | 125 | stopIndicator: function() { 126 | if(this.options.indicator) Element.hide(this.options.indicator); 127 | }, 128 | 129 | onKeyPress: function(event) { 130 | if(this.active) 131 | switch(event.keyCode) { 132 | case Event.KEY_TAB: 133 | case Event.KEY_RETURN: 134 | this.selectEntry(); 135 | Event.stop(event); 136 | case Event.KEY_ESC: 137 | this.hide(); 138 | this.active = false; 139 | Event.stop(event); 140 | return; 141 | case Event.KEY_LEFT: 142 | case Event.KEY_RIGHT: 143 | return; 144 | case Event.KEY_UP: 145 | this.markPrevious(); 146 | this.render(); 147 | Event.stop(event); 148 | return; 149 | case Event.KEY_DOWN: 150 | this.markNext(); 151 | this.render(); 152 | Event.stop(event); 153 | return; 154 | } 155 | else 156 | if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN || 157 | (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return; 158 | 159 | this.changed = true; 160 | this.hasFocus = true; 161 | 162 | if(this.observer) clearTimeout(this.observer); 163 | this.observer = 164 | setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000); 165 | }, 166 | 167 | activate: function() { 168 | this.changed = false; 169 | this.hasFocus = true; 170 | this.getUpdatedChoices(); 171 | }, 172 | 173 | onHover: function(event) { 174 | var element = Event.findElement(event, 'LI'); 175 | if(this.index != element.autocompleteIndex) 176 | { 177 | this.index = element.autocompleteIndex; 178 | this.render(); 179 | } 180 | Event.stop(event); 181 | }, 182 | 183 | onClick: function(event) { 184 | var element = Event.findElement(event, 'LI'); 185 | this.index = element.autocompleteIndex; 186 | this.selectEntry(); 187 | this.hide(); 188 | }, 189 | 190 | onBlur: function(event) { 191 | // needed to make click events working 192 | setTimeout(this.hide.bind(this), 250); 193 | this.hasFocus = false; 194 | this.active = false; 195 | }, 196 | 197 | render: function() { 198 | if(this.entryCount > 0) { 199 | for (var i = 0; i < this.entryCount; i++) 200 | this.index==i ? 201 | Element.addClassName(this.getEntry(i),"selected") : 202 | Element.removeClassName(this.getEntry(i),"selected"); 203 | if(this.hasFocus) { 204 | this.show(); 205 | this.active = true; 206 | } 207 | } else { 208 | this.active = false; 209 | this.hide(); 210 | } 211 | }, 212 | 213 | markPrevious: function() { 214 | if(this.index > 0) this.index-- 215 | else this.index = this.entryCount-1; 216 | this.getEntry(this.index).scrollIntoView(true); 217 | }, 218 | 219 | markNext: function() { 220 | if(this.index < this.entryCount-1) this.index++ 221 | else this.index = 0; 222 | this.getEntry(this.index).scrollIntoView(false); 223 | }, 224 | 225 | getEntry: function(index) { 226 | return this.update.firstChild.childNodes[index]; 227 | }, 228 | 229 | getCurrentEntry: function() { 230 | return this.getEntry(this.index); 231 | }, 232 | 233 | selectEntry: function() { 234 | this.active = false; 235 | this.updateElement(this.getCurrentEntry()); 236 | }, 237 | 238 | updateElement: function(selectedElement) { 239 | if (this.options.updateElement) { 240 | this.options.updateElement(selectedElement); 241 | return; 242 | } 243 | var value = ''; 244 | if (this.options.select) { 245 | var nodes = $(selectedElement).select('.' + this.options.select) || []; 246 | if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select); 247 | } else 248 | value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal'); 249 | 250 | var bounds = this.getTokenBounds(); 251 | if (bounds[0] != -1) { 252 | var newValue = this.element.value.substr(0, bounds[0]); 253 | var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/); 254 | if (whitespace) 255 | newValue += whitespace[0]; 256 | this.element.value = newValue + value + this.element.value.substr(bounds[1]); 257 | } else { 258 | this.element.value = value; 259 | } 260 | this.oldElementValue = this.element.value; 261 | this.element.focus(); 262 | 263 | if (this.options.afterUpdateElement) 264 | this.options.afterUpdateElement(this.element, selectedElement); 265 | }, 266 | 267 | updateChoices: function(choices) { 268 | if(!this.changed && this.hasFocus) { 269 | this.update.innerHTML = choices; 270 | Element.cleanWhitespace(this.update); 271 | Element.cleanWhitespace(this.update.down()); 272 | 273 | if(this.update.firstChild && this.update.down().childNodes) { 274 | this.entryCount = 275 | this.update.down().childNodes.length; 276 | for (var i = 0; i < this.entryCount; i++) { 277 | var entry = this.getEntry(i); 278 | entry.autocompleteIndex = i; 279 | this.addObservers(entry); 280 | } 281 | } else { 282 | this.entryCount = 0; 283 | } 284 | 285 | this.stopIndicator(); 286 | this.index = 0; 287 | 288 | if(this.entryCount==1 && this.options.autoSelect) { 289 | this.selectEntry(); 290 | this.hide(); 291 | } else { 292 | this.render(); 293 | } 294 | } 295 | }, 296 | 297 | addObservers: function(element) { 298 | Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this)); 299 | Event.observe(element, "click", this.onClick.bindAsEventListener(this)); 300 | }, 301 | 302 | onObserverEvent: function() { 303 | this.changed = false; 304 | this.tokenBounds = null; 305 | if(this.getToken().length>=this.options.minChars) { 306 | this.getUpdatedChoices(); 307 | } else { 308 | this.active = false; 309 | this.hide(); 310 | } 311 | this.oldElementValue = this.element.value; 312 | }, 313 | 314 | getToken: function() { 315 | var bounds = this.getTokenBounds(); 316 | return this.element.value.substring(bounds[0], bounds[1]).strip(); 317 | }, 318 | 319 | getTokenBounds: function() { 320 | if (null != this.tokenBounds) return this.tokenBounds; 321 | var value = this.element.value; 322 | if (value.strip().empty()) return [-1, 0]; 323 | var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue); 324 | var offset = (diff == this.oldElementValue.length ? 1 : 0); 325 | var prevTokenPos = -1, nextTokenPos = value.length; 326 | var tp; 327 | for (var index = 0, l = this.options.tokens.length; index < l; ++index) { 328 | tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1); 329 | if (tp > prevTokenPos) prevTokenPos = tp; 330 | tp = value.indexOf(this.options.tokens[index], diff + offset); 331 | if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp; 332 | } 333 | return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]); 334 | } 335 | }); 336 | 337 | Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) { 338 | var boundary = Math.min(newS.length, oldS.length); 339 | for (var index = 0; index < boundary; ++index) 340 | if (newS[index] != oldS[index]) 341 | return index; 342 | return boundary; 343 | }; 344 | 345 | Ajax.Autocompleter = Class.create(Autocompleter.Base, { 346 | initialize: function(element, update, url, options) { 347 | this.baseInitialize(element, update, options); 348 | this.options.asynchronous = true; 349 | this.options.onComplete = this.onComplete.bind(this); 350 | this.options.defaultParams = this.options.parameters || null; 351 | this.url = url; 352 | }, 353 | 354 | getUpdatedChoices: function() { 355 | this.startIndicator(); 356 | 357 | var entry = encodeURIComponent(this.options.paramName) + '=' + 358 | encodeURIComponent(this.getToken()); 359 | 360 | this.options.parameters = this.options.callback ? 361 | this.options.callback(this.element, entry) : entry; 362 | 363 | if(this.options.defaultParams) 364 | this.options.parameters += '&' + this.options.defaultParams; 365 | 366 | new Ajax.Request(this.url, this.options); 367 | }, 368 | 369 | onComplete: function(request) { 370 | this.updateChoices(request.responseText); 371 | } 372 | }); 373 | 374 | // The local array autocompleter. Used when you'd prefer to 375 | // inject an array of autocompletion options into the page, rather 376 | // than sending out Ajax queries, which can be quite slow sometimes. 377 | // 378 | // The constructor takes four parameters. The first two are, as usual, 379 | // the id of the monitored textbox, and id of the autocompletion menu. 380 | // The third is the array you want to autocomplete from, and the fourth 381 | // is the options block. 382 | // 383 | // Extra local autocompletion options: 384 | // - choices - How many autocompletion choices to offer 385 | // 386 | // - partialSearch - If false, the autocompleter will match entered 387 | // text only at the beginning of strings in the 388 | // autocomplete array. Defaults to true, which will 389 | // match text at the beginning of any *word* in the 390 | // strings in the autocomplete array. If you want to 391 | // search anywhere in the string, additionally set 392 | // the option fullSearch to true (default: off). 393 | // 394 | // - fullSsearch - Search anywhere in autocomplete array strings. 395 | // 396 | // - partialChars - How many characters to enter before triggering 397 | // a partial match (unlike minChars, which defines 398 | // how many characters are required to do any match 399 | // at all). Defaults to 2. 400 | // 401 | // - ignoreCase - Whether to ignore case when autocompleting. 402 | // Defaults to true. 403 | // 404 | // It's possible to pass in a custom function as the 'selector' 405 | // option, if you prefer to write your own autocompletion logic. 406 | // In that case, the other options above will not apply unless 407 | // you support them. 408 | 409 | Autocompleter.Local = Class.create(Autocompleter.Base, { 410 | initialize: function(element, update, array, options) { 411 | this.baseInitialize(element, update, options); 412 | this.options.array = array; 413 | }, 414 | 415 | getUpdatedChoices: function() { 416 | this.updateChoices(this.options.selector(this)); 417 | }, 418 | 419 | setOptions: function(options) { 420 | this.options = Object.extend({ 421 | choices: 10, 422 | partialSearch: true, 423 | partialChars: 2, 424 | ignoreCase: true, 425 | fullSearch: false, 426 | selector: function(instance) { 427 | var ret = []; // Beginning matches 428 | var partial = []; // Inside matches 429 | var entry = instance.getToken(); 430 | var count = 0; 431 | 432 | for (var i = 0; i < instance.options.array.length && 433 | ret.length < instance.options.choices ; i++) { 434 | 435 | var elem = instance.options.array[i]; 436 | var foundPos = instance.options.ignoreCase ? 437 | elem.toLowerCase().indexOf(entry.toLowerCase()) : 438 | elem.indexOf(entry); 439 | 440 | while (foundPos != -1) { 441 | if (foundPos == 0 && elem.length != entry.length) { 442 | ret.push("
  • " + elem.substr(0, entry.length) + "" + 443 | elem.substr(entry.length) + "
  • "); 444 | break; 445 | } else if (entry.length >= instance.options.partialChars && 446 | instance.options.partialSearch && foundPos != -1) { 447 | if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) { 448 | partial.push("
  • " + elem.substr(0, foundPos) + "" + 449 | elem.substr(foundPos, entry.length) + "" + elem.substr( 450 | foundPos + entry.length) + "
  • "); 451 | break; 452 | } 453 | } 454 | 455 | foundPos = instance.options.ignoreCase ? 456 | elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) : 457 | elem.indexOf(entry, foundPos + 1); 458 | 459 | } 460 | } 461 | if (partial.length) 462 | ret = ret.concat(partial.slice(0, instance.options.choices - ret.length)) 463 | return ""; 464 | } 465 | }, options || { }); 466 | } 467 | }); 468 | 469 | // AJAX in-place editor and collection editor 470 | // Full rewrite by Christophe Porteneuve (April 2007). 471 | 472 | // Use this if you notice weird scrolling problems on some browsers, 473 | // the DOM might be a bit confused when this gets called so do this 474 | // waits 1 ms (with setTimeout) until it does the activation 475 | Field.scrollFreeActivate = function(field) { 476 | setTimeout(function() { 477 | Field.activate(field); 478 | }, 1); 479 | } 480 | 481 | Ajax.InPlaceEditor = Class.create({ 482 | initialize: function(element, url, options) { 483 | this.url = url; 484 | this.element = element = $(element); 485 | this.prepareOptions(); 486 | this._controls = { }; 487 | arguments.callee.dealWithDeprecatedOptions(options); // DEPRECATION LAYER!!! 488 | Object.extend(this.options, options || { }); 489 | if (!this.options.formId && this.element.id) { 490 | this.options.formId = this.element.id + '-inplaceeditor'; 491 | if ($(this.options.formId)) 492 | this.options.formId = ''; 493 | } 494 | if (this.options.externalControl) 495 | this.options.externalControl = $(this.options.externalControl); 496 | if (!this.options.externalControl) 497 | this.options.externalControlOnly = false; 498 | this._originalBackground = this.element.getStyle('background-color') || 'transparent'; 499 | this.element.title = this.options.clickToEditText; 500 | this._boundCancelHandler = this.handleFormCancellation.bind(this); 501 | this._boundComplete = (this.options.onComplete || Prototype.emptyFunction).bind(this); 502 | this._boundFailureHandler = this.handleAJAXFailure.bind(this); 503 | this._boundSubmitHandler = this.handleFormSubmission.bind(this); 504 | this._boundWrapperHandler = this.wrapUp.bind(this); 505 | this.registerListeners(); 506 | }, 507 | checkForEscapeOrReturn: function(e) { 508 | if (!this._editing || e.ctrlKey || e.altKey || e.shiftKey) return; 509 | if (Event.KEY_ESC == e.keyCode) 510 | this.handleFormCancellation(e); 511 | else if (Event.KEY_RETURN == e.keyCode) 512 | this.handleFormSubmission(e); 513 | }, 514 | createControl: function(mode, handler, extraClasses) { 515 | var control = this.options[mode + 'Control']; 516 | var text = this.options[mode + 'Text']; 517 | if ('button' == control) { 518 | var btn = document.createElement('input'); 519 | btn.type = 'submit'; 520 | btn.value = text; 521 | btn.className = 'editor_' + mode + '_button'; 522 | if ('cancel' == mode) 523 | btn.onclick = this._boundCancelHandler; 524 | this._form.appendChild(btn); 525 | this._controls[mode] = btn; 526 | } else if ('link' == control) { 527 | var link = document.createElement('a'); 528 | link.href = '#'; 529 | link.appendChild(document.createTextNode(text)); 530 | link.onclick = 'cancel' == mode ? this._boundCancelHandler : this._boundSubmitHandler; 531 | link.className = 'editor_' + mode + '_link'; 532 | if (extraClasses) 533 | link.className += ' ' + extraClasses; 534 | this._form.appendChild(link); 535 | this._controls[mode] = link; 536 | } 537 | }, 538 | createEditField: function() { 539 | var text = (this.options.loadTextURL ? this.options.loadingText : this.getText()); 540 | var fld; 541 | if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) { 542 | fld = document.createElement('input'); 543 | fld.type = 'text'; 544 | var size = this.options.size || this.options.cols || 0; 545 | if (0 < size) fld.size = size; 546 | } else { 547 | fld = document.createElement('textarea'); 548 | fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows); 549 | fld.cols = this.options.cols || 40; 550 | } 551 | fld.name = this.options.paramName; 552 | fld.value = text; // No HTML breaks conversion anymore 553 | fld.className = 'editor_field'; 554 | if (this.options.submitOnBlur) 555 | fld.onblur = this._boundSubmitHandler; 556 | this._controls.editor = fld; 557 | if (this.options.loadTextURL) 558 | this.loadExternalText(); 559 | this._form.appendChild(this._controls.editor); 560 | }, 561 | createForm: function() { 562 | var ipe = this; 563 | function addText(mode, condition) { 564 | var text = ipe.options['text' + mode + 'Controls']; 565 | if (!text || condition === false) return; 566 | ipe._form.appendChild(document.createTextNode(text)); 567 | }; 568 | this._form = $(document.createElement('form')); 569 | this._form.id = this.options.formId; 570 | this._form.addClassName(this.options.formClassName); 571 | this._form.onsubmit = this._boundSubmitHandler; 572 | this.createEditField(); 573 | if ('textarea' == this._controls.editor.tagName.toLowerCase()) 574 | this._form.appendChild(document.createElement('br')); 575 | if (this.options.onFormCustomization) 576 | this.options.onFormCustomization(this, this._form); 577 | addText('Before', this.options.okControl || this.options.cancelControl); 578 | this.createControl('ok', this._boundSubmitHandler); 579 | addText('Between', this.options.okControl && this.options.cancelControl); 580 | this.createControl('cancel', this._boundCancelHandler, 'editor_cancel'); 581 | addText('After', this.options.okControl || this.options.cancelControl); 582 | }, 583 | destroy: function() { 584 | if (this._oldInnerHTML) 585 | this.element.innerHTML = this._oldInnerHTML; 586 | this.leaveEditMode(); 587 | this.unregisterListeners(); 588 | }, 589 | enterEditMode: function(e) { 590 | if (this._saving || this._editing) return; 591 | this._editing = true; 592 | this.triggerCallback('onEnterEditMode'); 593 | if (this.options.externalControl) 594 | this.options.externalControl.hide(); 595 | this.element.hide(); 596 | this.createForm(); 597 | this.element.parentNode.insertBefore(this._form, this.element); 598 | if (!this.options.loadTextURL) 599 | this.postProcessEditField(); 600 | if (e) Event.stop(e); 601 | }, 602 | enterHover: function(e) { 603 | if (this.options.hoverClassName) 604 | this.element.addClassName(this.options.hoverClassName); 605 | if (this._saving) return; 606 | this.triggerCallback('onEnterHover'); 607 | }, 608 | getText: function() { 609 | return this.element.innerHTML; 610 | }, 611 | handleAJAXFailure: function(transport) { 612 | this.triggerCallback('onFailure', transport); 613 | if (this._oldInnerHTML) { 614 | this.element.innerHTML = this._oldInnerHTML; 615 | this._oldInnerHTML = null; 616 | } 617 | }, 618 | handleFormCancellation: function(e) { 619 | this.wrapUp(); 620 | if (e) Event.stop(e); 621 | }, 622 | handleFormSubmission: function(e) { 623 | var form = this._form; 624 | var value = $F(this._controls.editor); 625 | this.prepareSubmission(); 626 | var params = this.options.callback(form, value) || ''; 627 | if (Object.isString(params)) 628 | params = params.toQueryParams(); 629 | params.editorId = this.element.id; 630 | if (this.options.htmlResponse) { 631 | var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions); 632 | Object.extend(options, { 633 | parameters: params, 634 | onComplete: this._boundWrapperHandler, 635 | onFailure: this._boundFailureHandler 636 | }); 637 | new Ajax.Updater({ success: this.element }, this.url, options); 638 | } else { 639 | var options = Object.extend({ method: 'get' }, this.options.ajaxOptions); 640 | Object.extend(options, { 641 | parameters: params, 642 | onComplete: this._boundWrapperHandler, 643 | onFailure: this._boundFailureHandler 644 | }); 645 | new Ajax.Request(this.url, options); 646 | } 647 | if (e) Event.stop(e); 648 | }, 649 | leaveEditMode: function() { 650 | this.element.removeClassName(this.options.savingClassName); 651 | this.removeForm(); 652 | this.leaveHover(); 653 | this.element.style.backgroundColor = this._originalBackground; 654 | this.element.show(); 655 | if (this.options.externalControl) 656 | this.options.externalControl.show(); 657 | this._saving = false; 658 | this._editing = false; 659 | this._oldInnerHTML = null; 660 | this.triggerCallback('onLeaveEditMode'); 661 | }, 662 | leaveHover: function(e) { 663 | if (this.options.hoverClassName) 664 | this.element.removeClassName(this.options.hoverClassName); 665 | if (this._saving) return; 666 | this.triggerCallback('onLeaveHover'); 667 | }, 668 | loadExternalText: function() { 669 | this._form.addClassName(this.options.loadingClassName); 670 | this._controls.editor.disabled = true; 671 | var options = Object.extend({ method: 'get' }, this.options.ajaxOptions); 672 | Object.extend(options, { 673 | parameters: 'editorId=' + encodeURIComponent(this.element.id), 674 | onComplete: Prototype.emptyFunction, 675 | onSuccess: function(transport) { 676 | this._form.removeClassName(this.options.loadingClassName); 677 | var text = transport.responseText; 678 | if (this.options.stripLoadedTextTags) 679 | text = text.stripTags(); 680 | this._controls.editor.value = text; 681 | this._controls.editor.disabled = false; 682 | this.postProcessEditField(); 683 | }.bind(this), 684 | onFailure: this._boundFailureHandler 685 | }); 686 | new Ajax.Request(this.options.loadTextURL, options); 687 | }, 688 | postProcessEditField: function() { 689 | var fpc = this.options.fieldPostCreation; 690 | if (fpc) 691 | $(this._controls.editor)['focus' == fpc ? 'focus' : 'activate'](); 692 | }, 693 | prepareOptions: function() { 694 | this.options = Object.clone(Ajax.InPlaceEditor.DefaultOptions); 695 | Object.extend(this.options, Ajax.InPlaceEditor.DefaultCallbacks); 696 | [this._extraDefaultOptions].flatten().compact().each(function(defs) { 697 | Object.extend(this.options, defs); 698 | }.bind(this)); 699 | }, 700 | prepareSubmission: function() { 701 | this._saving = true; 702 | this.removeForm(); 703 | this.leaveHover(); 704 | this.showSaving(); 705 | }, 706 | registerListeners: function() { 707 | this._listeners = { }; 708 | var listener; 709 | $H(Ajax.InPlaceEditor.Listeners).each(function(pair) { 710 | listener = this[pair.value].bind(this); 711 | this._listeners[pair.key] = listener; 712 | if (!this.options.externalControlOnly) 713 | this.element.observe(pair.key, listener); 714 | if (this.options.externalControl) 715 | this.options.externalControl.observe(pair.key, listener); 716 | }.bind(this)); 717 | }, 718 | removeForm: function() { 719 | if (!this._form) return; 720 | this._form.remove(); 721 | this._form = null; 722 | this._controls = { }; 723 | }, 724 | showSaving: function() { 725 | this._oldInnerHTML = this.element.innerHTML; 726 | this.element.innerHTML = this.options.savingText; 727 | this.element.addClassName(this.options.savingClassName); 728 | this.element.style.backgroundColor = this._originalBackground; 729 | this.element.show(); 730 | }, 731 | triggerCallback: function(cbName, arg) { 732 | if ('function' == typeof this.options[cbName]) { 733 | this.options[cbName](this, arg); 734 | } 735 | }, 736 | unregisterListeners: function() { 737 | $H(this._listeners).each(function(pair) { 738 | if (!this.options.externalControlOnly) 739 | this.element.stopObserving(pair.key, pair.value); 740 | if (this.options.externalControl) 741 | this.options.externalControl.stopObserving(pair.key, pair.value); 742 | }.bind(this)); 743 | }, 744 | wrapUp: function(transport) { 745 | this.leaveEditMode(); 746 | // Can't use triggerCallback due to backward compatibility: requires 747 | // binding + direct element 748 | this._boundComplete(transport, this.element); 749 | } 750 | }); 751 | 752 | Object.extend(Ajax.InPlaceEditor.prototype, { 753 | dispose: Ajax.InPlaceEditor.prototype.destroy 754 | }); 755 | 756 | Ajax.InPlaceCollectionEditor = Class.create(Ajax.InPlaceEditor, { 757 | initialize: function($super, element, url, options) { 758 | this._extraDefaultOptions = Ajax.InPlaceCollectionEditor.DefaultOptions; 759 | $super(element, url, options); 760 | }, 761 | 762 | createEditField: function() { 763 | var list = document.createElement('select'); 764 | list.name = this.options.paramName; 765 | list.size = 1; 766 | this._controls.editor = list; 767 | this._collection = this.options.collection || []; 768 | if (this.options.loadCollectionURL) 769 | this.loadCollection(); 770 | else 771 | this.checkForExternalText(); 772 | this._form.appendChild(this._controls.editor); 773 | }, 774 | 775 | loadCollection: function() { 776 | this._form.addClassName(this.options.loadingClassName); 777 | this.showLoadingText(this.options.loadingCollectionText); 778 | var options = Object.extend({ method: 'get' }, this.options.ajaxOptions); 779 | Object.extend(options, { 780 | parameters: 'editorId=' + encodeURIComponent(this.element.id), 781 | onComplete: Prototype.emptyFunction, 782 | onSuccess: function(transport) { 783 | var js = transport.responseText.strip(); 784 | if (!/^\[.*\]$/.test(js)) // TODO: improve sanity check 785 | throw 'Server returned an invalid collection representation.'; 786 | this._collection = eval(js); 787 | this.checkForExternalText(); 788 | }.bind(this), 789 | onFailure: this.onFailure 790 | }); 791 | new Ajax.Request(this.options.loadCollectionURL, options); 792 | }, 793 | 794 | showLoadingText: function(text) { 795 | this._controls.editor.disabled = true; 796 | var tempOption = this._controls.editor.firstChild; 797 | if (!tempOption) { 798 | tempOption = document.createElement('option'); 799 | tempOption.value = ''; 800 | this._controls.editor.appendChild(tempOption); 801 | tempOption.selected = true; 802 | } 803 | tempOption.update((text || '').stripScripts().stripTags()); 804 | }, 805 | 806 | checkForExternalText: function() { 807 | this._text = this.getText(); 808 | if (this.options.loadTextURL) 809 | this.loadExternalText(); 810 | else 811 | this.buildOptionList(); 812 | }, 813 | 814 | loadExternalText: function() { 815 | this.showLoadingText(this.options.loadingText); 816 | var options = Object.extend({ method: 'get' }, this.options.ajaxOptions); 817 | Object.extend(options, { 818 | parameters: 'editorId=' + encodeURIComponent(this.element.id), 819 | onComplete: Prototype.emptyFunction, 820 | onSuccess: function(transport) { 821 | this._text = transport.responseText.strip(); 822 | this.buildOptionList(); 823 | }.bind(this), 824 | onFailure: this.onFailure 825 | }); 826 | new Ajax.Request(this.options.loadTextURL, options); 827 | }, 828 | 829 | buildOptionList: function() { 830 | this._form.removeClassName(this.options.loadingClassName); 831 | this._collection = this._collection.map(function(entry) { 832 | return 2 === entry.length ? entry : [entry, entry].flatten(); 833 | }); 834 | var marker = ('value' in this.options) ? this.options.value : this._text; 835 | var textFound = this._collection.any(function(entry) { 836 | return entry[0] == marker; 837 | }.bind(this)); 838 | this._controls.editor.update(''); 839 | var option; 840 | this._collection.each(function(entry, index) { 841 | option = document.createElement('option'); 842 | option.value = entry[0]; 843 | option.selected = textFound ? entry[0] == marker : 0 == index; 844 | option.appendChild(document.createTextNode(entry[1])); 845 | this._controls.editor.appendChild(option); 846 | }.bind(this)); 847 | this._controls.editor.disabled = false; 848 | Field.scrollFreeActivate(this._controls.editor); 849 | } 850 | }); 851 | 852 | //**** DEPRECATION LAYER FOR InPlace[Collection]Editor! **** 853 | //**** This only exists for a while, in order to let **** 854 | //**** users adapt to the new API. Read up on the new **** 855 | //**** API and convert your code to it ASAP! **** 856 | 857 | Ajax.InPlaceEditor.prototype.initialize.dealWithDeprecatedOptions = function(options) { 858 | if (!options) return; 859 | function fallback(name, expr) { 860 | if (name in options || expr === undefined) return; 861 | options[name] = expr; 862 | }; 863 | fallback('cancelControl', (options.cancelLink ? 'link' : (options.cancelButton ? 'button' : 864 | options.cancelLink == options.cancelButton == false ? false : undefined))); 865 | fallback('okControl', (options.okLink ? 'link' : (options.okButton ? 'button' : 866 | options.okLink == options.okButton == false ? false : undefined))); 867 | fallback('highlightColor', options.highlightcolor); 868 | fallback('highlightEndColor', options.highlightendcolor); 869 | }; 870 | 871 | Object.extend(Ajax.InPlaceEditor, { 872 | DefaultOptions: { 873 | ajaxOptions: { }, 874 | autoRows: 3, // Use when multi-line w/ rows == 1 875 | cancelControl: 'link', // 'link'|'button'|false 876 | cancelText: 'cancel', 877 | clickToEditText: 'Click to edit', 878 | externalControl: null, // id|elt 879 | externalControlOnly: false, 880 | fieldPostCreation: 'activate', // 'activate'|'focus'|false 881 | formClassName: 'inplaceeditor-form', 882 | formId: null, // id|elt 883 | highlightColor: '#ffff99', 884 | highlightEndColor: '#ffffff', 885 | hoverClassName: '', 886 | htmlResponse: true, 887 | loadingClassName: 'inplaceeditor-loading', 888 | loadingText: 'Loading...', 889 | okControl: 'button', // 'link'|'button'|false 890 | okText: 'ok', 891 | paramName: 'value', 892 | rows: 1, // If 1 and multi-line, uses autoRows 893 | savingClassName: 'inplaceeditor-saving', 894 | savingText: 'Saving...', 895 | size: 0, 896 | stripLoadedTextTags: false, 897 | submitOnBlur: false, 898 | textAfterControls: '', 899 | textBeforeControls: '', 900 | textBetweenControls: '' 901 | }, 902 | DefaultCallbacks: { 903 | callback: function(form) { 904 | return Form.serialize(form); 905 | }, 906 | onComplete: function(transport, element) { 907 | // For backward compatibility, this one is bound to the IPE, and passes 908 | // the element directly. It was too often customized, so we don't break it. 909 | new Effect.Highlight(element, { 910 | startcolor: this.options.highlightColor, keepBackgroundImage: true }); 911 | }, 912 | onEnterEditMode: null, 913 | onEnterHover: function(ipe) { 914 | ipe.element.style.backgroundColor = ipe.options.highlightColor; 915 | if (ipe._effect) 916 | ipe._effect.cancel(); 917 | }, 918 | onFailure: function(transport, ipe) { 919 | alert('Error communication with the server: ' + transport.responseText.stripTags()); 920 | }, 921 | onFormCustomization: null, // Takes the IPE and its generated form, after editor, before controls. 922 | onLeaveEditMode: null, 923 | onLeaveHover: function(ipe) { 924 | ipe._effect = new Effect.Highlight(ipe.element, { 925 | startcolor: ipe.options.highlightColor, endcolor: ipe.options.highlightEndColor, 926 | restorecolor: ipe._originalBackground, keepBackgroundImage: true 927 | }); 928 | } 929 | }, 930 | Listeners: { 931 | click: 'enterEditMode', 932 | keydown: 'checkForEscapeOrReturn', 933 | mouseover: 'enterHover', 934 | mouseout: 'leaveHover' 935 | } 936 | }); 937 | 938 | Ajax.InPlaceCollectionEditor.DefaultOptions = { 939 | loadingCollectionText: 'Loading options...' 940 | }; 941 | 942 | // Delayed observer, like Form.Element.Observer, 943 | // but waits for delay after last key input 944 | // Ideal for live-search fields 945 | 946 | Form.Element.DelayedObserver = Class.create({ 947 | initialize: function(element, delay, callback) { 948 | this.delay = delay || 0.5; 949 | this.element = $(element); 950 | this.callback = callback; 951 | this.timer = null; 952 | this.lastValue = $F(this.element); 953 | Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this)); 954 | }, 955 | delayedListener: function(event) { 956 | if(this.lastValue == $F(this.element)) return; 957 | if(this.timer) clearTimeout(this.timer); 958 | this.timer = setTimeout(this.onTimerEvent.bind(this), this.delay * 1000); 959 | this.lastValue = $F(this.element); 960 | }, 961 | onTimerEvent: function() { 962 | this.timer = null; 963 | this.callback(this.element, $F(this.element)); 964 | } 965 | }); 966 | -------------------------------------------------------------------------------- /snorql/scriptaculous/dragdrop.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us dragdrop.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008 2 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 | // (c) 2005-2007 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz) 5 | // 6 | // script.aculo.us is freely distributable under the terms of an MIT-style license. 7 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 8 | 9 | if(Object.isUndefined(Effect)) 10 | throw("dragdrop.js requires including script.aculo.us' effects.js library"); 11 | 12 | var Droppables = { 13 | drops: [], 14 | 15 | remove: function(element) { 16 | this.drops = this.drops.reject(function(d) { return d.element==$(element) }); 17 | }, 18 | 19 | add: function(element) { 20 | element = $(element); 21 | var options = Object.extend({ 22 | greedy: true, 23 | hoverclass: null, 24 | tree: false 25 | }, arguments[1] || { }); 26 | 27 | // cache containers 28 | if(options.containment) { 29 | options._containers = []; 30 | var containment = options.containment; 31 | if(Object.isArray(containment)) { 32 | containment.each( function(c) { options._containers.push($(c)) }); 33 | } else { 34 | options._containers.push($(containment)); 35 | } 36 | } 37 | 38 | if(options.accept) options.accept = [options.accept].flatten(); 39 | 40 | Element.makePositioned(element); // fix IE 41 | options.element = element; 42 | 43 | this.drops.push(options); 44 | }, 45 | 46 | findDeepestChild: function(drops) { 47 | deepest = drops[0]; 48 | 49 | for (i = 1; i < drops.length; ++i) 50 | if (Element.isParent(drops[i].element, deepest.element)) 51 | deepest = drops[i]; 52 | 53 | return deepest; 54 | }, 55 | 56 | isContained: function(element, drop) { 57 | var containmentNode; 58 | if(drop.tree) { 59 | containmentNode = element.treeNode; 60 | } else { 61 | containmentNode = element.parentNode; 62 | } 63 | return drop._containers.detect(function(c) { return containmentNode == c }); 64 | }, 65 | 66 | isAffected: function(point, element, drop) { 67 | return ( 68 | (drop.element!=element) && 69 | ((!drop._containers) || 70 | this.isContained(element, drop)) && 71 | ((!drop.accept) || 72 | (Element.classNames(element).detect( 73 | function(v) { return drop.accept.include(v) } ) )) && 74 | Position.within(drop.element, point[0], point[1]) ); 75 | }, 76 | 77 | deactivate: function(drop) { 78 | if(drop.hoverclass) 79 | Element.removeClassName(drop.element, drop.hoverclass); 80 | this.last_active = null; 81 | }, 82 | 83 | activate: function(drop) { 84 | if(drop.hoverclass) 85 | Element.addClassName(drop.element, drop.hoverclass); 86 | this.last_active = drop; 87 | }, 88 | 89 | show: function(point, element) { 90 | if(!this.drops.length) return; 91 | var drop, affected = []; 92 | 93 | this.drops.each( function(drop) { 94 | if(Droppables.isAffected(point, element, drop)) 95 | affected.push(drop); 96 | }); 97 | 98 | if(affected.length>0) 99 | drop = Droppables.findDeepestChild(affected); 100 | 101 | if(this.last_active && this.last_active != drop) this.deactivate(this.last_active); 102 | if (drop) { 103 | Position.within(drop.element, point[0], point[1]); 104 | if(drop.onHover) 105 | drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element)); 106 | 107 | if (drop != this.last_active) Droppables.activate(drop); 108 | } 109 | }, 110 | 111 | fire: function(event, element) { 112 | if(!this.last_active) return; 113 | Position.prepare(); 114 | 115 | if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active)) 116 | if (this.last_active.onDrop) { 117 | this.last_active.onDrop(element, this.last_active.element, event); 118 | return true; 119 | } 120 | }, 121 | 122 | reset: function() { 123 | if(this.last_active) 124 | this.deactivate(this.last_active); 125 | } 126 | } 127 | 128 | var Draggables = { 129 | drags: [], 130 | observers: [], 131 | 132 | register: function(draggable) { 133 | if(this.drags.length == 0) { 134 | this.eventMouseUp = this.endDrag.bindAsEventListener(this); 135 | this.eventMouseMove = this.updateDrag.bindAsEventListener(this); 136 | this.eventKeypress = this.keyPress.bindAsEventListener(this); 137 | 138 | Event.observe(document, "mouseup", this.eventMouseUp); 139 | Event.observe(document, "mousemove", this.eventMouseMove); 140 | Event.observe(document, "keypress", this.eventKeypress); 141 | } 142 | this.drags.push(draggable); 143 | }, 144 | 145 | unregister: function(draggable) { 146 | this.drags = this.drags.reject(function(d) { return d==draggable }); 147 | if(this.drags.length == 0) { 148 | Event.stopObserving(document, "mouseup", this.eventMouseUp); 149 | Event.stopObserving(document, "mousemove", this.eventMouseMove); 150 | Event.stopObserving(document, "keypress", this.eventKeypress); 151 | } 152 | }, 153 | 154 | activate: function(draggable) { 155 | if(draggable.options.delay) { 156 | this._timeout = setTimeout(function() { 157 | Draggables._timeout = null; 158 | window.focus(); 159 | Draggables.activeDraggable = draggable; 160 | }.bind(this), draggable.options.delay); 161 | } else { 162 | window.focus(); // allows keypress events if window isn't currently focused, fails for Safari 163 | this.activeDraggable = draggable; 164 | } 165 | }, 166 | 167 | deactivate: function() { 168 | this.activeDraggable = null; 169 | }, 170 | 171 | updateDrag: function(event) { 172 | if(!this.activeDraggable) return; 173 | var pointer = [Event.pointerX(event), Event.pointerY(event)]; 174 | // Mozilla-based browsers fire successive mousemove events with 175 | // the same coordinates, prevent needless redrawing (moz bug?) 176 | if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return; 177 | this._lastPointer = pointer; 178 | 179 | this.activeDraggable.updateDrag(event, pointer); 180 | }, 181 | 182 | endDrag: function(event) { 183 | if(this._timeout) { 184 | clearTimeout(this._timeout); 185 | this._timeout = null; 186 | } 187 | if(!this.activeDraggable) return; 188 | this._lastPointer = null; 189 | this.activeDraggable.endDrag(event); 190 | this.activeDraggable = null; 191 | }, 192 | 193 | keyPress: function(event) { 194 | if(this.activeDraggable) 195 | this.activeDraggable.keyPress(event); 196 | }, 197 | 198 | addObserver: function(observer) { 199 | this.observers.push(observer); 200 | this._cacheObserverCallbacks(); 201 | }, 202 | 203 | removeObserver: function(element) { // element instead of observer fixes mem leaks 204 | this.observers = this.observers.reject( function(o) { return o.element==element }); 205 | this._cacheObserverCallbacks(); 206 | }, 207 | 208 | notify: function(eventName, draggable, event) { // 'onStart', 'onEnd', 'onDrag' 209 | if(this[eventName+'Count'] > 0) 210 | this.observers.each( function(o) { 211 | if(o[eventName]) o[eventName](eventName, draggable, event); 212 | }); 213 | if(draggable.options[eventName]) draggable.options[eventName](draggable, event); 214 | }, 215 | 216 | _cacheObserverCallbacks: function() { 217 | ['onStart','onEnd','onDrag'].each( function(eventName) { 218 | Draggables[eventName+'Count'] = Draggables.observers.select( 219 | function(o) { return o[eventName]; } 220 | ).length; 221 | }); 222 | } 223 | } 224 | 225 | /*--------------------------------------------------------------------------*/ 226 | 227 | var Draggable = Class.create({ 228 | initialize: function(element) { 229 | var defaults = { 230 | handle: false, 231 | reverteffect: function(element, top_offset, left_offset) { 232 | var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02; 233 | new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur, 234 | queue: {scope:'_draggable', position:'end'} 235 | }); 236 | }, 237 | endeffect: function(element) { 238 | var toOpacity = Object.isNumber(element._opacity) ? element._opacity : 1.0; 239 | new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity, 240 | queue: {scope:'_draggable', position:'end'}, 241 | afterFinish: function(){ 242 | Draggable._dragging[element] = false 243 | } 244 | }); 245 | }, 246 | zindex: 1000, 247 | revert: false, 248 | quiet: false, 249 | scroll: false, 250 | scrollSensitivity: 20, 251 | scrollSpeed: 15, 252 | snap: false, // false, or xy or [x,y] or function(x,y){ return [x,y] } 253 | delay: 0 254 | }; 255 | 256 | if(!arguments[1] || Object.isUndefined(arguments[1].endeffect)) 257 | Object.extend(defaults, { 258 | starteffect: function(element) { 259 | element._opacity = Element.getOpacity(element); 260 | Draggable._dragging[element] = true; 261 | new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7}); 262 | } 263 | }); 264 | 265 | var options = Object.extend(defaults, arguments[1] || { }); 266 | 267 | this.element = $(element); 268 | 269 | if(options.handle && Object.isString(options.handle)) 270 | this.handle = this.element.down('.'+options.handle, 0); 271 | 272 | if(!this.handle) this.handle = $(options.handle); 273 | if(!this.handle) this.handle = this.element; 274 | 275 | if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) { 276 | options.scroll = $(options.scroll); 277 | this._isScrollChild = Element.childOf(this.element, options.scroll); 278 | } 279 | 280 | Element.makePositioned(this.element); // fix IE 281 | 282 | this.options = options; 283 | this.dragging = false; 284 | 285 | this.eventMouseDown = this.initDrag.bindAsEventListener(this); 286 | Event.observe(this.handle, "mousedown", this.eventMouseDown); 287 | 288 | Draggables.register(this); 289 | }, 290 | 291 | destroy: function() { 292 | Event.stopObserving(this.handle, "mousedown", this.eventMouseDown); 293 | Draggables.unregister(this); 294 | }, 295 | 296 | currentDelta: function() { 297 | return([ 298 | parseInt(Element.getStyle(this.element,'left') || '0'), 299 | parseInt(Element.getStyle(this.element,'top') || '0')]); 300 | }, 301 | 302 | initDrag: function(event) { 303 | if(!Object.isUndefined(Draggable._dragging[this.element]) && 304 | Draggable._dragging[this.element]) return; 305 | if(Event.isLeftClick(event)) { 306 | // abort on form elements, fixes a Firefox issue 307 | var src = Event.element(event); 308 | if((tag_name = src.tagName.toUpperCase()) && ( 309 | tag_name=='INPUT' || 310 | tag_name=='SELECT' || 311 | tag_name=='OPTION' || 312 | tag_name=='BUTTON' || 313 | tag_name=='TEXTAREA')) return; 314 | 315 | var pointer = [Event.pointerX(event), Event.pointerY(event)]; 316 | var pos = Position.cumulativeOffset(this.element); 317 | this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) }); 318 | 319 | Draggables.activate(this); 320 | Event.stop(event); 321 | } 322 | }, 323 | 324 | startDrag: function(event) { 325 | this.dragging = true; 326 | if(!this.delta) 327 | this.delta = this.currentDelta(); 328 | 329 | if(this.options.zindex) { 330 | this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0); 331 | this.element.style.zIndex = this.options.zindex; 332 | } 333 | 334 | if(this.options.ghosting) { 335 | this._clone = this.element.cloneNode(true); 336 | this.element._originallyAbsolute = (this.element.getStyle('position') == 'absolute'); 337 | if (!this.element._originallyAbsolute) 338 | Position.absolutize(this.element); 339 | this.element.parentNode.insertBefore(this._clone, this.element); 340 | } 341 | 342 | if(this.options.scroll) { 343 | if (this.options.scroll == window) { 344 | var where = this._getWindowScroll(this.options.scroll); 345 | this.originalScrollLeft = where.left; 346 | this.originalScrollTop = where.top; 347 | } else { 348 | this.originalScrollLeft = this.options.scroll.scrollLeft; 349 | this.originalScrollTop = this.options.scroll.scrollTop; 350 | } 351 | } 352 | 353 | Draggables.notify('onStart', this, event); 354 | 355 | if(this.options.starteffect) this.options.starteffect(this.element); 356 | }, 357 | 358 | updateDrag: function(event, pointer) { 359 | if(!this.dragging) this.startDrag(event); 360 | 361 | if(!this.options.quiet){ 362 | Position.prepare(); 363 | Droppables.show(pointer, this.element); 364 | } 365 | 366 | Draggables.notify('onDrag', this, event); 367 | 368 | this.draw(pointer); 369 | if(this.options.change) this.options.change(this); 370 | 371 | if(this.options.scroll) { 372 | this.stopScrolling(); 373 | 374 | var p; 375 | if (this.options.scroll == window) { 376 | with(this._getWindowScroll(this.options.scroll)) { p = [ left, top, left+width, top+height ]; } 377 | } else { 378 | p = Position.page(this.options.scroll); 379 | p[0] += this.options.scroll.scrollLeft + Position.deltaX; 380 | p[1] += this.options.scroll.scrollTop + Position.deltaY; 381 | p.push(p[0]+this.options.scroll.offsetWidth); 382 | p.push(p[1]+this.options.scroll.offsetHeight); 383 | } 384 | var speed = [0,0]; 385 | if(pointer[0] < (p[0]+this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[0]+this.options.scrollSensitivity); 386 | if(pointer[1] < (p[1]+this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[1]+this.options.scrollSensitivity); 387 | if(pointer[0] > (p[2]-this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[2]-this.options.scrollSensitivity); 388 | if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity); 389 | this.startScrolling(speed); 390 | } 391 | 392 | // fix AppleWebKit rendering 393 | if(Prototype.Browser.WebKit) window.scrollBy(0,0); 394 | 395 | Event.stop(event); 396 | }, 397 | 398 | finishDrag: function(event, success) { 399 | this.dragging = false; 400 | 401 | if(this.options.quiet){ 402 | Position.prepare(); 403 | var pointer = [Event.pointerX(event), Event.pointerY(event)]; 404 | Droppables.show(pointer, this.element); 405 | } 406 | 407 | if(this.options.ghosting) { 408 | if (!this.element._originallyAbsolute) 409 | Position.relativize(this.element); 410 | delete this.element._originallyAbsolute; 411 | Element.remove(this._clone); 412 | this._clone = null; 413 | } 414 | 415 | var dropped = false; 416 | if(success) { 417 | dropped = Droppables.fire(event, this.element); 418 | if (!dropped) dropped = false; 419 | } 420 | if(dropped && this.options.onDropped) this.options.onDropped(this.element); 421 | Draggables.notify('onEnd', this, event); 422 | 423 | var revert = this.options.revert; 424 | if(revert && Object.isFunction(revert)) revert = revert(this.element); 425 | 426 | var d = this.currentDelta(); 427 | if(revert && this.options.reverteffect) { 428 | if (dropped == 0 || revert != 'failure') 429 | this.options.reverteffect(this.element, 430 | d[1]-this.delta[1], d[0]-this.delta[0]); 431 | } else { 432 | this.delta = d; 433 | } 434 | 435 | if(this.options.zindex) 436 | this.element.style.zIndex = this.originalZ; 437 | 438 | if(this.options.endeffect) 439 | this.options.endeffect(this.element); 440 | 441 | Draggables.deactivate(this); 442 | Droppables.reset(); 443 | }, 444 | 445 | keyPress: function(event) { 446 | if(event.keyCode!=Event.KEY_ESC) return; 447 | this.finishDrag(event, false); 448 | Event.stop(event); 449 | }, 450 | 451 | endDrag: function(event) { 452 | if(!this.dragging) return; 453 | this.stopScrolling(); 454 | this.finishDrag(event, true); 455 | Event.stop(event); 456 | }, 457 | 458 | draw: function(point) { 459 | var pos = Position.cumulativeOffset(this.element); 460 | if(this.options.ghosting) { 461 | var r = Position.realOffset(this.element); 462 | pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY; 463 | } 464 | 465 | var d = this.currentDelta(); 466 | pos[0] -= d[0]; pos[1] -= d[1]; 467 | 468 | if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) { 469 | pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft; 470 | pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop; 471 | } 472 | 473 | var p = [0,1].map(function(i){ 474 | return (point[i]-pos[i]-this.offset[i]) 475 | }.bind(this)); 476 | 477 | if(this.options.snap) { 478 | if(Object.isFunction(this.options.snap)) { 479 | p = this.options.snap(p[0],p[1],this); 480 | } else { 481 | if(Object.isArray(this.options.snap)) { 482 | p = p.map( function(v, i) { 483 | return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this)) 484 | } else { 485 | p = p.map( function(v) { 486 | return (v/this.options.snap).round()*this.options.snap }.bind(this)) 487 | } 488 | }} 489 | 490 | var style = this.element.style; 491 | if((!this.options.constraint) || (this.options.constraint=='horizontal')) 492 | style.left = p[0] + "px"; 493 | if((!this.options.constraint) || (this.options.constraint=='vertical')) 494 | style.top = p[1] + "px"; 495 | 496 | if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering 497 | }, 498 | 499 | stopScrolling: function() { 500 | if(this.scrollInterval) { 501 | clearInterval(this.scrollInterval); 502 | this.scrollInterval = null; 503 | Draggables._lastScrollPointer = null; 504 | } 505 | }, 506 | 507 | startScrolling: function(speed) { 508 | if(!(speed[0] || speed[1])) return; 509 | this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed]; 510 | this.lastScrolled = new Date(); 511 | this.scrollInterval = setInterval(this.scroll.bind(this), 10); 512 | }, 513 | 514 | scroll: function() { 515 | var current = new Date(); 516 | var delta = current - this.lastScrolled; 517 | this.lastScrolled = current; 518 | if(this.options.scroll == window) { 519 | with (this._getWindowScroll(this.options.scroll)) { 520 | if (this.scrollSpeed[0] || this.scrollSpeed[1]) { 521 | var d = delta / 1000; 522 | this.options.scroll.scrollTo( left + d*this.scrollSpeed[0], top + d*this.scrollSpeed[1] ); 523 | } 524 | } 525 | } else { 526 | this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000; 527 | this.options.scroll.scrollTop += this.scrollSpeed[1] * delta / 1000; 528 | } 529 | 530 | Position.prepare(); 531 | Droppables.show(Draggables._lastPointer, this.element); 532 | Draggables.notify('onDrag', this); 533 | if (this._isScrollChild) { 534 | Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer); 535 | Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000; 536 | Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000; 537 | if (Draggables._lastScrollPointer[0] < 0) 538 | Draggables._lastScrollPointer[0] = 0; 539 | if (Draggables._lastScrollPointer[1] < 0) 540 | Draggables._lastScrollPointer[1] = 0; 541 | this.draw(Draggables._lastScrollPointer); 542 | } 543 | 544 | if(this.options.change) this.options.change(this); 545 | }, 546 | 547 | _getWindowScroll: function(w) { 548 | var T, L, W, H; 549 | with (w.document) { 550 | if (w.document.documentElement && documentElement.scrollTop) { 551 | T = documentElement.scrollTop; 552 | L = documentElement.scrollLeft; 553 | } else if (w.document.body) { 554 | T = body.scrollTop; 555 | L = body.scrollLeft; 556 | } 557 | if (w.innerWidth) { 558 | W = w.innerWidth; 559 | H = w.innerHeight; 560 | } else if (w.document.documentElement && documentElement.clientWidth) { 561 | W = documentElement.clientWidth; 562 | H = documentElement.clientHeight; 563 | } else { 564 | W = body.offsetWidth; 565 | H = body.offsetHeight 566 | } 567 | } 568 | return { top: T, left: L, width: W, height: H }; 569 | } 570 | }); 571 | 572 | Draggable._dragging = { }; 573 | 574 | /*--------------------------------------------------------------------------*/ 575 | 576 | var SortableObserver = Class.create({ 577 | initialize: function(element, observer) { 578 | this.element = $(element); 579 | this.observer = observer; 580 | this.lastValue = Sortable.serialize(this.element); 581 | }, 582 | 583 | onStart: function() { 584 | this.lastValue = Sortable.serialize(this.element); 585 | }, 586 | 587 | onEnd: function() { 588 | Sortable.unmark(); 589 | if(this.lastValue != Sortable.serialize(this.element)) 590 | this.observer(this.element) 591 | } 592 | }); 593 | 594 | var Sortable = { 595 | SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/, 596 | 597 | sortables: { }, 598 | 599 | _findRootElement: function(element) { 600 | while (element.tagName.toUpperCase() != "BODY") { 601 | if(element.id && Sortable.sortables[element.id]) return element; 602 | element = element.parentNode; 603 | } 604 | }, 605 | 606 | options: function(element) { 607 | element = Sortable._findRootElement($(element)); 608 | if(!element) return; 609 | return Sortable.sortables[element.id]; 610 | }, 611 | 612 | destroy: function(element){ 613 | var s = Sortable.options(element); 614 | 615 | if(s) { 616 | Draggables.removeObserver(s.element); 617 | s.droppables.each(function(d){ Droppables.remove(d) }); 618 | s.draggables.invoke('destroy'); 619 | 620 | delete Sortable.sortables[s.element.id]; 621 | } 622 | }, 623 | 624 | create: function(element) { 625 | element = $(element); 626 | var options = Object.extend({ 627 | element: element, 628 | tag: 'li', // assumes li children, override with tag: 'tagname' 629 | dropOnEmpty: false, 630 | tree: false, 631 | treeTag: 'ul', 632 | overlap: 'vertical', // one of 'vertical', 'horizontal' 633 | constraint: 'vertical', // one of 'vertical', 'horizontal', false 634 | containment: element, // also takes array of elements (or id's); or false 635 | handle: false, // or a CSS class 636 | only: false, 637 | delay: 0, 638 | hoverclass: null, 639 | ghosting: false, 640 | quiet: false, 641 | scroll: false, 642 | scrollSensitivity: 20, 643 | scrollSpeed: 15, 644 | format: this.SERIALIZE_RULE, 645 | 646 | // these take arrays of elements or ids and can be 647 | // used for better initialization performance 648 | elements: false, 649 | handles: false, 650 | 651 | onChange: Prototype.emptyFunction, 652 | onUpdate: Prototype.emptyFunction 653 | }, arguments[1] || { }); 654 | 655 | // clear any old sortable with same element 656 | this.destroy(element); 657 | 658 | // build options for the draggables 659 | var options_for_draggable = { 660 | revert: true, 661 | quiet: options.quiet, 662 | scroll: options.scroll, 663 | scrollSpeed: options.scrollSpeed, 664 | scrollSensitivity: options.scrollSensitivity, 665 | delay: options.delay, 666 | ghosting: options.ghosting, 667 | constraint: options.constraint, 668 | handle: options.handle }; 669 | 670 | if(options.starteffect) 671 | options_for_draggable.starteffect = options.starteffect; 672 | 673 | if(options.reverteffect) 674 | options_for_draggable.reverteffect = options.reverteffect; 675 | else 676 | if(options.ghosting) options_for_draggable.reverteffect = function(element) { 677 | element.style.top = 0; 678 | element.style.left = 0; 679 | }; 680 | 681 | if(options.endeffect) 682 | options_for_draggable.endeffect = options.endeffect; 683 | 684 | if(options.zindex) 685 | options_for_draggable.zindex = options.zindex; 686 | 687 | // build options for the droppables 688 | var options_for_droppable = { 689 | overlap: options.overlap, 690 | containment: options.containment, 691 | tree: options.tree, 692 | hoverclass: options.hoverclass, 693 | onHover: Sortable.onHover 694 | } 695 | 696 | var options_for_tree = { 697 | onHover: Sortable.onEmptyHover, 698 | overlap: options.overlap, 699 | containment: options.containment, 700 | hoverclass: options.hoverclass 701 | } 702 | 703 | // fix for gecko engine 704 | Element.cleanWhitespace(element); 705 | 706 | options.draggables = []; 707 | options.droppables = []; 708 | 709 | // drop on empty handling 710 | if(options.dropOnEmpty || options.tree) { 711 | Droppables.add(element, options_for_tree); 712 | options.droppables.push(element); 713 | } 714 | 715 | (options.elements || this.findElements(element, options) || []).each( function(e,i) { 716 | var handle = options.handles ? $(options.handles[i]) : 717 | (options.handle ? $(e).select('.' + options.handle)[0] : e); 718 | options.draggables.push( 719 | new Draggable(e, Object.extend(options_for_draggable, { handle: handle }))); 720 | Droppables.add(e, options_for_droppable); 721 | if(options.tree) e.treeNode = element; 722 | options.droppables.push(e); 723 | }); 724 | 725 | if(options.tree) { 726 | (Sortable.findTreeElements(element, options) || []).each( function(e) { 727 | Droppables.add(e, options_for_tree); 728 | e.treeNode = element; 729 | options.droppables.push(e); 730 | }); 731 | } 732 | 733 | // keep reference 734 | this.sortables[element.id] = options; 735 | 736 | // for onupdate 737 | Draggables.addObserver(new SortableObserver(element, options.onUpdate)); 738 | 739 | }, 740 | 741 | // return all suitable-for-sortable elements in a guaranteed order 742 | findElements: function(element, options) { 743 | return Element.findChildren( 744 | element, options.only, options.tree ? true : false, options.tag); 745 | }, 746 | 747 | findTreeElements: function(element, options) { 748 | return Element.findChildren( 749 | element, options.only, options.tree ? true : false, options.treeTag); 750 | }, 751 | 752 | onHover: function(element, dropon, overlap) { 753 | if(Element.isParent(dropon, element)) return; 754 | 755 | if(overlap > .33 && overlap < .66 && Sortable.options(dropon).tree) { 756 | return; 757 | } else if(overlap>0.5) { 758 | Sortable.mark(dropon, 'before'); 759 | if(dropon.previousSibling != element) { 760 | var oldParentNode = element.parentNode; 761 | element.style.visibility = "hidden"; // fix gecko rendering 762 | dropon.parentNode.insertBefore(element, dropon); 763 | if(dropon.parentNode!=oldParentNode) 764 | Sortable.options(oldParentNode).onChange(element); 765 | Sortable.options(dropon.parentNode).onChange(element); 766 | } 767 | } else { 768 | Sortable.mark(dropon, 'after'); 769 | var nextElement = dropon.nextSibling || null; 770 | if(nextElement != element) { 771 | var oldParentNode = element.parentNode; 772 | element.style.visibility = "hidden"; // fix gecko rendering 773 | dropon.parentNode.insertBefore(element, nextElement); 774 | if(dropon.parentNode!=oldParentNode) 775 | Sortable.options(oldParentNode).onChange(element); 776 | Sortable.options(dropon.parentNode).onChange(element); 777 | } 778 | } 779 | }, 780 | 781 | onEmptyHover: function(element, dropon, overlap) { 782 | var oldParentNode = element.parentNode; 783 | var droponOptions = Sortable.options(dropon); 784 | 785 | if(!Element.isParent(dropon, element)) { 786 | var index; 787 | 788 | var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only}); 789 | var child = null; 790 | 791 | if(children) { 792 | var offset = Element.offsetSize(dropon, droponOptions.overlap) * (1.0 - overlap); 793 | 794 | for (index = 0; index < children.length; index += 1) { 795 | if (offset - Element.offsetSize (children[index], droponOptions.overlap) >= 0) { 796 | offset -= Element.offsetSize (children[index], droponOptions.overlap); 797 | } else if (offset - (Element.offsetSize (children[index], droponOptions.overlap) / 2) >= 0) { 798 | child = index + 1 < children.length ? children[index + 1] : null; 799 | break; 800 | } else { 801 | child = children[index]; 802 | break; 803 | } 804 | } 805 | } 806 | 807 | dropon.insertBefore(element, child); 808 | 809 | Sortable.options(oldParentNode).onChange(element); 810 | droponOptions.onChange(element); 811 | } 812 | }, 813 | 814 | unmark: function() { 815 | if(Sortable._marker) Sortable._marker.hide(); 816 | }, 817 | 818 | mark: function(dropon, position) { 819 | // mark on ghosting only 820 | var sortable = Sortable.options(dropon.parentNode); 821 | if(sortable && !sortable.ghosting) return; 822 | 823 | if(!Sortable._marker) { 824 | Sortable._marker = 825 | ($('dropmarker') || Element.extend(document.createElement('DIV'))). 826 | hide().addClassName('dropmarker').setStyle({position:'absolute'}); 827 | document.getElementsByTagName("body").item(0).appendChild(Sortable._marker); 828 | } 829 | var offsets = Position.cumulativeOffset(dropon); 830 | Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'}); 831 | 832 | if(position=='after') 833 | if(sortable.overlap == 'horizontal') 834 | Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'}); 835 | else 836 | Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'}); 837 | 838 | Sortable._marker.show(); 839 | }, 840 | 841 | _tree: function(element, options, parent) { 842 | var children = Sortable.findElements(element, options) || []; 843 | 844 | for (var i = 0; i < children.length; ++i) { 845 | var match = children[i].id.match(options.format); 846 | 847 | if (!match) continue; 848 | 849 | var child = { 850 | id: encodeURIComponent(match ? match[1] : null), 851 | element: element, 852 | parent: parent, 853 | children: [], 854 | position: parent.children.length, 855 | container: $(children[i]).down(options.treeTag) 856 | } 857 | 858 | /* Get the element containing the children and recurse over it */ 859 | if (child.container) 860 | this._tree(child.container, options, child) 861 | 862 | parent.children.push (child); 863 | } 864 | 865 | return parent; 866 | }, 867 | 868 | tree: function(element) { 869 | element = $(element); 870 | var sortableOptions = this.options(element); 871 | var options = Object.extend({ 872 | tag: sortableOptions.tag, 873 | treeTag: sortableOptions.treeTag, 874 | only: sortableOptions.only, 875 | name: element.id, 876 | format: sortableOptions.format 877 | }, arguments[1] || { }); 878 | 879 | var root = { 880 | id: null, 881 | parent: null, 882 | children: [], 883 | container: element, 884 | position: 0 885 | } 886 | 887 | return Sortable._tree(element, options, root); 888 | }, 889 | 890 | /* Construct a [i] index for a particular node */ 891 | _constructIndex: function(node) { 892 | var index = ''; 893 | do { 894 | if (node.id) index = '[' + node.position + ']' + index; 895 | } while ((node = node.parent) != null); 896 | return index; 897 | }, 898 | 899 | sequence: function(element) { 900 | element = $(element); 901 | var options = Object.extend(this.options(element), arguments[1] || { }); 902 | 903 | return $(this.findElements(element, options) || []).map( function(item) { 904 | return item.id.match(options.format) ? item.id.match(options.format)[1] : ''; 905 | }); 906 | }, 907 | 908 | setSequence: function(element, new_sequence) { 909 | element = $(element); 910 | var options = Object.extend(this.options(element), arguments[2] || { }); 911 | 912 | var nodeMap = { }; 913 | this.findElements(element, options).each( function(n) { 914 | if (n.id.match(options.format)) 915 | nodeMap[n.id.match(options.format)[1]] = [n, n.parentNode]; 916 | n.parentNode.removeChild(n); 917 | }); 918 | 919 | new_sequence.each(function(ident) { 920 | var n = nodeMap[ident]; 921 | if (n) { 922 | n[1].appendChild(n[0]); 923 | delete nodeMap[ident]; 924 | } 925 | }); 926 | }, 927 | 928 | serialize: function(element) { 929 | element = $(element); 930 | var options = Object.extend(Sortable.options(element), arguments[1] || { }); 931 | var name = encodeURIComponent( 932 | (arguments[1] && arguments[1].name) ? arguments[1].name : element.id); 933 | 934 | if (options.tree) { 935 | return Sortable.tree(element, arguments[1]).children.map( function (item) { 936 | return [name + Sortable._constructIndex(item) + "[id]=" + 937 | encodeURIComponent(item.id)].concat(item.children.map(arguments.callee)); 938 | }).flatten().join('&'); 939 | } else { 940 | return Sortable.sequence(element, arguments[1]).map( function(item) { 941 | return name + "[]=" + encodeURIComponent(item); 942 | }).join('&'); 943 | } 944 | } 945 | } 946 | 947 | // Returns true if child is contained within element 948 | Element.isParent = function(child, element) { 949 | if (!child.parentNode || child == element) return false; 950 | if (child.parentNode == element) return true; 951 | return Element.isParent(child.parentNode, element); 952 | } 953 | 954 | Element.findChildren = function(element, only, recursive, tagName) { 955 | if(!element.hasChildNodes()) return null; 956 | tagName = tagName.toUpperCase(); 957 | if(only) only = [only].flatten(); 958 | var elements = []; 959 | $A(element.childNodes).each( function(e) { 960 | if(e.tagName && e.tagName.toUpperCase()==tagName && 961 | (!only || (Element.classNames(e).detect(function(v) { return only.include(v) })))) 962 | elements.push(e); 963 | if(recursive) { 964 | var grandchildren = Element.findChildren(e, only, recursive, tagName); 965 | if(grandchildren) elements.push(grandchildren); 966 | } 967 | }); 968 | 969 | return (elements.length>0 ? elements.flatten() : []); 970 | } 971 | 972 | Element.offsetSize = function (element, type) { 973 | return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')]; 974 | } 975 | -------------------------------------------------------------------------------- /snorql/scriptaculous/effects.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us effects.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008 2 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 | // Contributors: 5 | // Justin Palmer (http://encytemedia.com/) 6 | // Mark Pilgrim (http://diveintomark.org/) 7 | // Martin Bialasinki 8 | // 9 | // script.aculo.us is freely distributable under the terms of an MIT-style license. 10 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 11 | 12 | // converts rgb() and #xxx to #xxxxxx format, 13 | // returns self (or first argument) if not convertable 14 | String.prototype.parseColor = function() { 15 | var color = '#'; 16 | if (this.slice(0,4) == 'rgb(') { 17 | var cols = this.slice(4,this.length-1).split(','); 18 | var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3); 19 | } else { 20 | if (this.slice(0,1) == '#') { 21 | if (this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase(); 22 | if (this.length==7) color = this.toLowerCase(); 23 | } 24 | } 25 | return (color.length==7 ? color : (arguments[0] || this)); 26 | }; 27 | 28 | /*--------------------------------------------------------------------------*/ 29 | 30 | Element.collectTextNodes = function(element) { 31 | return $A($(element).childNodes).collect( function(node) { 32 | return (node.nodeType==3 ? node.nodeValue : 33 | (node.hasChildNodes() ? Element.collectTextNodes(node) : '')); 34 | }).flatten().join(''); 35 | }; 36 | 37 | Element.collectTextNodesIgnoreClass = function(element, className) { 38 | return $A($(element).childNodes).collect( function(node) { 39 | return (node.nodeType==3 ? node.nodeValue : 40 | ((node.hasChildNodes() && !Element.hasClassName(node,className)) ? 41 | Element.collectTextNodesIgnoreClass(node, className) : '')); 42 | }).flatten().join(''); 43 | }; 44 | 45 | Element.setContentZoom = function(element, percent) { 46 | element = $(element); 47 | element.setStyle({fontSize: (percent/100) + 'em'}); 48 | if (Prototype.Browser.WebKit) window.scrollBy(0,0); 49 | return element; 50 | }; 51 | 52 | Element.getInlineOpacity = function(element){ 53 | return $(element).style.opacity || ''; 54 | }; 55 | 56 | Element.forceRerendering = function(element) { 57 | try { 58 | element = $(element); 59 | var n = document.createTextNode(' '); 60 | element.appendChild(n); 61 | element.removeChild(n); 62 | } catch(e) { } 63 | }; 64 | 65 | /*--------------------------------------------------------------------------*/ 66 | 67 | var Effect = { 68 | _elementDoesNotExistError: { 69 | name: 'ElementDoesNotExistError', 70 | message: 'The specified DOM element does not exist, but is required for this effect to operate' 71 | }, 72 | Transitions: { 73 | linear: Prototype.K, 74 | sinoidal: function(pos) { 75 | return (-Math.cos(pos*Math.PI)/2) + 0.5; 76 | }, 77 | reverse: function(pos) { 78 | return 1-pos; 79 | }, 80 | flicker: function(pos) { 81 | var pos = ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4; 82 | return pos > 1 ? 1 : pos; 83 | }, 84 | wobble: function(pos) { 85 | return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5; 86 | }, 87 | pulse: function(pos, pulses) { 88 | pulses = pulses || 5; 89 | return ( 90 | ((pos % (1/pulses)) * pulses).round() == 0 ? 91 | ((pos * pulses * 2) - (pos * pulses * 2).floor()) : 92 | 1 - ((pos * pulses * 2) - (pos * pulses * 2).floor()) 93 | ); 94 | }, 95 | spring: function(pos) { 96 | return 1 - (Math.cos(pos * 4.5 * Math.PI) * Math.exp(-pos * 6)); 97 | }, 98 | none: function(pos) { 99 | return 0; 100 | }, 101 | full: function(pos) { 102 | return 1; 103 | } 104 | }, 105 | DefaultOptions: { 106 | duration: 1.0, // seconds 107 | fps: 100, // 100= assume 66fps max. 108 | sync: false, // true for combining 109 | from: 0.0, 110 | to: 1.0, 111 | delay: 0.0, 112 | queue: 'parallel' 113 | }, 114 | tagifyText: function(element) { 115 | var tagifyStyle = 'position:relative'; 116 | if (Prototype.Browser.IE) tagifyStyle += ';zoom:1'; 117 | 118 | element = $(element); 119 | $A(element.childNodes).each( function(child) { 120 | if (child.nodeType==3) { 121 | child.nodeValue.toArray().each( function(character) { 122 | element.insertBefore( 123 | new Element('span', {style: tagifyStyle}).update( 124 | character == ' ' ? String.fromCharCode(160) : character), 125 | child); 126 | }); 127 | Element.remove(child); 128 | } 129 | }); 130 | }, 131 | multiple: function(element, effect) { 132 | var elements; 133 | if (((typeof element == 'object') || 134 | Object.isFunction(element)) && 135 | (element.length)) 136 | elements = element; 137 | else 138 | elements = $(element).childNodes; 139 | 140 | var options = Object.extend({ 141 | speed: 0.1, 142 | delay: 0.0 143 | }, arguments[2] || { }); 144 | var masterDelay = options.delay; 145 | 146 | $A(elements).each( function(element, index) { 147 | new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay })); 148 | }); 149 | }, 150 | PAIRS: { 151 | 'slide': ['SlideDown','SlideUp'], 152 | 'blind': ['BlindDown','BlindUp'], 153 | 'appear': ['Appear','Fade'] 154 | }, 155 | toggle: function(element, effect) { 156 | element = $(element); 157 | effect = (effect || 'appear').toLowerCase(); 158 | var options = Object.extend({ 159 | queue: { position:'end', scope:(element.id || 'global'), limit: 1 } 160 | }, arguments[2] || { }); 161 | Effect[element.visible() ? 162 | Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options); 163 | } 164 | }; 165 | 166 | Effect.DefaultOptions.transition = Effect.Transitions.sinoidal; 167 | 168 | /* ------------- core effects ------------- */ 169 | 170 | Effect.ScopedQueue = Class.create(Enumerable, { 171 | initialize: function() { 172 | this.effects = []; 173 | this.interval = null; 174 | }, 175 | _each: function(iterator) { 176 | this.effects._each(iterator); 177 | }, 178 | add: function(effect) { 179 | var timestamp = new Date().getTime(); 180 | 181 | var position = Object.isString(effect.options.queue) ? 182 | effect.options.queue : effect.options.queue.position; 183 | 184 | switch(position) { 185 | case 'front': 186 | // move unstarted effects after this effect 187 | this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) { 188 | e.startOn += effect.finishOn; 189 | e.finishOn += effect.finishOn; 190 | }); 191 | break; 192 | case 'with-last': 193 | timestamp = this.effects.pluck('startOn').max() || timestamp; 194 | break; 195 | case 'end': 196 | // start effect after last queued effect has finished 197 | timestamp = this.effects.pluck('finishOn').max() || timestamp; 198 | break; 199 | } 200 | 201 | effect.startOn += timestamp; 202 | effect.finishOn += timestamp; 203 | 204 | if (!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit)) 205 | this.effects.push(effect); 206 | 207 | if (!this.interval) 208 | this.interval = setInterval(this.loop.bind(this), 15); 209 | }, 210 | remove: function(effect) { 211 | this.effects = this.effects.reject(function(e) { return e==effect }); 212 | if (this.effects.length == 0) { 213 | clearInterval(this.interval); 214 | this.interval = null; 215 | } 216 | }, 217 | loop: function() { 218 | var timePos = new Date().getTime(); 219 | for(var i=0, len=this.effects.length;i= this.startOn) { 274 | if (timePos >= this.finishOn) { 275 | this.render(1.0); 276 | this.cancel(); 277 | this.event('beforeFinish'); 278 | if (this.finish) this.finish(); 279 | this.event('afterFinish'); 280 | return; 281 | } 282 | var pos = (timePos - this.startOn) / this.totalTime, 283 | frame = (pos * this.totalFrames).round(); 284 | if (frame > this.currentFrame) { 285 | this.render(pos); 286 | this.currentFrame = frame; 287 | } 288 | } 289 | }, 290 | cancel: function() { 291 | if (!this.options.sync) 292 | Effect.Queues.get(Object.isString(this.options.queue) ? 293 | 'global' : this.options.queue.scope).remove(this); 294 | this.state = 'finished'; 295 | }, 296 | event: function(eventName) { 297 | if (this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this); 298 | if (this.options[eventName]) this.options[eventName](this); 299 | }, 300 | inspect: function() { 301 | var data = $H(); 302 | for(property in this) 303 | if (!Object.isFunction(this[property])) data.set(property, this[property]); 304 | return '#'; 305 | } 306 | }); 307 | 308 | Effect.Parallel = Class.create(Effect.Base, { 309 | initialize: function(effects) { 310 | this.effects = effects || []; 311 | this.start(arguments[1]); 312 | }, 313 | update: function(position) { 314 | this.effects.invoke('render', position); 315 | }, 316 | finish: function(position) { 317 | this.effects.each( function(effect) { 318 | effect.render(1.0); 319 | effect.cancel(); 320 | effect.event('beforeFinish'); 321 | if (effect.finish) effect.finish(position); 322 | effect.event('afterFinish'); 323 | }); 324 | } 325 | }); 326 | 327 | Effect.Tween = Class.create(Effect.Base, { 328 | initialize: function(object, from, to) { 329 | object = Object.isString(object) ? $(object) : object; 330 | var args = $A(arguments), method = args.last(), 331 | options = args.length == 5 ? args[3] : null; 332 | this.method = Object.isFunction(method) ? method.bind(object) : 333 | Object.isFunction(object[method]) ? object[method].bind(object) : 334 | function(value) { object[method] = value }; 335 | this.start(Object.extend({ from: from, to: to }, options || { })); 336 | }, 337 | update: function(position) { 338 | this.method(position); 339 | } 340 | }); 341 | 342 | Effect.Event = Class.create(Effect.Base, { 343 | initialize: function() { 344 | this.start(Object.extend({ duration: 0 }, arguments[0] || { })); 345 | }, 346 | update: Prototype.emptyFunction 347 | }); 348 | 349 | Effect.Opacity = Class.create(Effect.Base, { 350 | initialize: function(element) { 351 | this.element = $(element); 352 | if (!this.element) throw(Effect._elementDoesNotExistError); 353 | // make this work on IE on elements without 'layout' 354 | if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout)) 355 | this.element.setStyle({zoom: 1}); 356 | var options = Object.extend({ 357 | from: this.element.getOpacity() || 0.0, 358 | to: 1.0 359 | }, arguments[1] || { }); 360 | this.start(options); 361 | }, 362 | update: function(position) { 363 | this.element.setOpacity(position); 364 | } 365 | }); 366 | 367 | Effect.Move = Class.create(Effect.Base, { 368 | initialize: function(element) { 369 | this.element = $(element); 370 | if (!this.element) throw(Effect._elementDoesNotExistError); 371 | var options = Object.extend({ 372 | x: 0, 373 | y: 0, 374 | mode: 'relative' 375 | }, arguments[1] || { }); 376 | this.start(options); 377 | }, 378 | setup: function() { 379 | this.element.makePositioned(); 380 | this.originalLeft = parseFloat(this.element.getStyle('left') || '0'); 381 | this.originalTop = parseFloat(this.element.getStyle('top') || '0'); 382 | if (this.options.mode == 'absolute') { 383 | this.options.x = this.options.x - this.originalLeft; 384 | this.options.y = this.options.y - this.originalTop; 385 | } 386 | }, 387 | update: function(position) { 388 | this.element.setStyle({ 389 | left: (this.options.x * position + this.originalLeft).round() + 'px', 390 | top: (this.options.y * position + this.originalTop).round() + 'px' 391 | }); 392 | } 393 | }); 394 | 395 | // for backwards compatibility 396 | Effect.MoveBy = function(element, toTop, toLeft) { 397 | return new Effect.Move(element, 398 | Object.extend({ x: toLeft, y: toTop }, arguments[3] || { })); 399 | }; 400 | 401 | Effect.Scale = Class.create(Effect.Base, { 402 | initialize: function(element, percent) { 403 | this.element = $(element); 404 | if (!this.element) throw(Effect._elementDoesNotExistError); 405 | var options = Object.extend({ 406 | scaleX: true, 407 | scaleY: true, 408 | scaleContent: true, 409 | scaleFromCenter: false, 410 | scaleMode: 'box', // 'box' or 'contents' or { } with provided values 411 | scaleFrom: 100.0, 412 | scaleTo: percent 413 | }, arguments[2] || { }); 414 | this.start(options); 415 | }, 416 | setup: function() { 417 | this.restoreAfterFinish = this.options.restoreAfterFinish || false; 418 | this.elementPositioning = this.element.getStyle('position'); 419 | 420 | this.originalStyle = { }; 421 | ['top','left','width','height','fontSize'].each( function(k) { 422 | this.originalStyle[k] = this.element.style[k]; 423 | }.bind(this)); 424 | 425 | this.originalTop = this.element.offsetTop; 426 | this.originalLeft = this.element.offsetLeft; 427 | 428 | var fontSize = this.element.getStyle('font-size') || '100%'; 429 | ['em','px','%','pt'].each( function(fontSizeType) { 430 | if (fontSize.indexOf(fontSizeType)>0) { 431 | this.fontSize = parseFloat(fontSize); 432 | this.fontSizeType = fontSizeType; 433 | } 434 | }.bind(this)); 435 | 436 | this.factor = (this.options.scaleTo - this.options.scaleFrom)/100; 437 | 438 | this.dims = null; 439 | if (this.options.scaleMode=='box') 440 | this.dims = [this.element.offsetHeight, this.element.offsetWidth]; 441 | if (/^content/.test(this.options.scaleMode)) 442 | this.dims = [this.element.scrollHeight, this.element.scrollWidth]; 443 | if (!this.dims) 444 | this.dims = [this.options.scaleMode.originalHeight, 445 | this.options.scaleMode.originalWidth]; 446 | }, 447 | update: function(position) { 448 | var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position); 449 | if (this.options.scaleContent && this.fontSize) 450 | this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType }); 451 | this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale); 452 | }, 453 | finish: function(position) { 454 | if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle); 455 | }, 456 | setDimensions: function(height, width) { 457 | var d = { }; 458 | if (this.options.scaleX) d.width = width.round() + 'px'; 459 | if (this.options.scaleY) d.height = height.round() + 'px'; 460 | if (this.options.scaleFromCenter) { 461 | var topd = (height - this.dims[0])/2; 462 | var leftd = (width - this.dims[1])/2; 463 | if (this.elementPositioning == 'absolute') { 464 | if (this.options.scaleY) d.top = this.originalTop-topd + 'px'; 465 | if (this.options.scaleX) d.left = this.originalLeft-leftd + 'px'; 466 | } else { 467 | if (this.options.scaleY) d.top = -topd + 'px'; 468 | if (this.options.scaleX) d.left = -leftd + 'px'; 469 | } 470 | } 471 | this.element.setStyle(d); 472 | } 473 | }); 474 | 475 | Effect.Highlight = Class.create(Effect.Base, { 476 | initialize: function(element) { 477 | this.element = $(element); 478 | if (!this.element) throw(Effect._elementDoesNotExistError); 479 | var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || { }); 480 | this.start(options); 481 | }, 482 | setup: function() { 483 | // Prevent executing on elements not in the layout flow 484 | if (this.element.getStyle('display')=='none') { this.cancel(); return; } 485 | // Disable background image during the effect 486 | this.oldStyle = { }; 487 | if (!this.options.keepBackgroundImage) { 488 | this.oldStyle.backgroundImage = this.element.getStyle('background-image'); 489 | this.element.setStyle({backgroundImage: 'none'}); 490 | } 491 | if (!this.options.endcolor) 492 | this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff'); 493 | if (!this.options.restorecolor) 494 | this.options.restorecolor = this.element.getStyle('background-color'); 495 | // init color calculations 496 | this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this)); 497 | this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this)); 498 | }, 499 | update: function(position) { 500 | this.element.setStyle({backgroundColor: $R(0,2).inject('#',function(m,v,i){ 501 | return m+((this._base[i]+(this._delta[i]*position)).round().toColorPart()); }.bind(this)) }); 502 | }, 503 | finish: function() { 504 | this.element.setStyle(Object.extend(this.oldStyle, { 505 | backgroundColor: this.options.restorecolor 506 | })); 507 | } 508 | }); 509 | 510 | Effect.ScrollTo = function(element) { 511 | var options = arguments[1] || { }, 512 | scrollOffsets = document.viewport.getScrollOffsets(), 513 | elementOffsets = $(element).cumulativeOffset(), 514 | max = (window.height || document.body.scrollHeight) - document.viewport.getHeight(); 515 | 516 | if (options.offset) elementOffsets[1] += options.offset; 517 | 518 | return new Effect.Tween(null, 519 | scrollOffsets.top, 520 | elementOffsets[1] > max ? max : elementOffsets[1], 521 | options, 522 | function(p){ scrollTo(scrollOffsets.left, p.round()) } 523 | ); 524 | }; 525 | 526 | /* ------------- combination effects ------------- */ 527 | 528 | Effect.Fade = function(element) { 529 | element = $(element); 530 | var oldOpacity = element.getInlineOpacity(); 531 | var options = Object.extend({ 532 | from: element.getOpacity() || 1.0, 533 | to: 0.0, 534 | afterFinishInternal: function(effect) { 535 | if (effect.options.to!=0) return; 536 | effect.element.hide().setStyle({opacity: oldOpacity}); 537 | } 538 | }, arguments[1] || { }); 539 | return new Effect.Opacity(element,options); 540 | }; 541 | 542 | Effect.Appear = function(element) { 543 | element = $(element); 544 | var options = Object.extend({ 545 | from: (element.getStyle('display') == 'none' ? 0.0 : element.getOpacity() || 0.0), 546 | to: 1.0, 547 | // force Safari to render floated elements properly 548 | afterFinishInternal: function(effect) { 549 | effect.element.forceRerendering(); 550 | }, 551 | beforeSetup: function(effect) { 552 | effect.element.setOpacity(effect.options.from).show(); 553 | }}, arguments[1] || { }); 554 | return new Effect.Opacity(element,options); 555 | }; 556 | 557 | Effect.Puff = function(element) { 558 | element = $(element); 559 | var oldStyle = { 560 | opacity: element.getInlineOpacity(), 561 | position: element.getStyle('position'), 562 | top: element.style.top, 563 | left: element.style.left, 564 | width: element.style.width, 565 | height: element.style.height 566 | }; 567 | return new Effect.Parallel( 568 | [ new Effect.Scale(element, 200, 569 | { sync: true, scaleFromCenter: true, scaleContent: true, restoreAfterFinish: true }), 570 | new Effect.Opacity(element, { sync: true, to: 0.0 } ) ], 571 | Object.extend({ duration: 1.0, 572 | beforeSetupInternal: function(effect) { 573 | Position.absolutize(effect.effects[0].element) 574 | }, 575 | afterFinishInternal: function(effect) { 576 | effect.effects[0].element.hide().setStyle(oldStyle); } 577 | }, arguments[1] || { }) 578 | ); 579 | }; 580 | 581 | Effect.BlindUp = function(element) { 582 | element = $(element); 583 | element.makeClipping(); 584 | return new Effect.Scale(element, 0, 585 | Object.extend({ scaleContent: false, 586 | scaleX: false, 587 | restoreAfterFinish: true, 588 | afterFinishInternal: function(effect) { 589 | effect.element.hide().undoClipping(); 590 | } 591 | }, arguments[1] || { }) 592 | ); 593 | }; 594 | 595 | Effect.BlindDown = function(element) { 596 | element = $(element); 597 | var elementDimensions = element.getDimensions(); 598 | return new Effect.Scale(element, 100, Object.extend({ 599 | scaleContent: false, 600 | scaleX: false, 601 | scaleFrom: 0, 602 | scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, 603 | restoreAfterFinish: true, 604 | afterSetup: function(effect) { 605 | effect.element.makeClipping().setStyle({height: '0px'}).show(); 606 | }, 607 | afterFinishInternal: function(effect) { 608 | effect.element.undoClipping(); 609 | } 610 | }, arguments[1] || { })); 611 | }; 612 | 613 | Effect.SwitchOff = function(element) { 614 | element = $(element); 615 | var oldOpacity = element.getInlineOpacity(); 616 | return new Effect.Appear(element, Object.extend({ 617 | duration: 0.4, 618 | from: 0, 619 | transition: Effect.Transitions.flicker, 620 | afterFinishInternal: function(effect) { 621 | new Effect.Scale(effect.element, 1, { 622 | duration: 0.3, scaleFromCenter: true, 623 | scaleX: false, scaleContent: false, restoreAfterFinish: true, 624 | beforeSetup: function(effect) { 625 | effect.element.makePositioned().makeClipping(); 626 | }, 627 | afterFinishInternal: function(effect) { 628 | effect.element.hide().undoClipping().undoPositioned().setStyle({opacity: oldOpacity}); 629 | } 630 | }) 631 | } 632 | }, arguments[1] || { })); 633 | }; 634 | 635 | Effect.DropOut = function(element) { 636 | element = $(element); 637 | var oldStyle = { 638 | top: element.getStyle('top'), 639 | left: element.getStyle('left'), 640 | opacity: element.getInlineOpacity() }; 641 | return new Effect.Parallel( 642 | [ new Effect.Move(element, {x: 0, y: 100, sync: true }), 643 | new Effect.Opacity(element, { sync: true, to: 0.0 }) ], 644 | Object.extend( 645 | { duration: 0.5, 646 | beforeSetup: function(effect) { 647 | effect.effects[0].element.makePositioned(); 648 | }, 649 | afterFinishInternal: function(effect) { 650 | effect.effects[0].element.hide().undoPositioned().setStyle(oldStyle); 651 | } 652 | }, arguments[1] || { })); 653 | }; 654 | 655 | Effect.Shake = function(element) { 656 | element = $(element); 657 | var options = Object.extend({ 658 | distance: 20, 659 | duration: 0.5 660 | }, arguments[1] || {}); 661 | var distance = parseFloat(options.distance); 662 | var split = parseFloat(options.duration) / 10.0; 663 | var oldStyle = { 664 | top: element.getStyle('top'), 665 | left: element.getStyle('left') }; 666 | return new Effect.Move(element, 667 | { x: distance, y: 0, duration: split, afterFinishInternal: function(effect) { 668 | new Effect.Move(effect.element, 669 | { x: -distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) { 670 | new Effect.Move(effect.element, 671 | { x: distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) { 672 | new Effect.Move(effect.element, 673 | { x: -distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) { 674 | new Effect.Move(effect.element, 675 | { x: distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) { 676 | new Effect.Move(effect.element, 677 | { x: -distance, y: 0, duration: split, afterFinishInternal: function(effect) { 678 | effect.element.undoPositioned().setStyle(oldStyle); 679 | }}) }}) }}) }}) }}) }}); 680 | }; 681 | 682 | Effect.SlideDown = function(element) { 683 | element = $(element).cleanWhitespace(); 684 | // SlideDown need to have the content of the element wrapped in a container element with fixed height! 685 | var oldInnerBottom = element.down().getStyle('bottom'); 686 | var elementDimensions = element.getDimensions(); 687 | return new Effect.Scale(element, 100, Object.extend({ 688 | scaleContent: false, 689 | scaleX: false, 690 | scaleFrom: window.opera ? 0 : 1, 691 | scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, 692 | restoreAfterFinish: true, 693 | afterSetup: function(effect) { 694 | effect.element.makePositioned(); 695 | effect.element.down().makePositioned(); 696 | if (window.opera) effect.element.setStyle({top: ''}); 697 | effect.element.makeClipping().setStyle({height: '0px'}).show(); 698 | }, 699 | afterUpdateInternal: function(effect) { 700 | effect.element.down().setStyle({bottom: 701 | (effect.dims[0] - effect.element.clientHeight) + 'px' }); 702 | }, 703 | afterFinishInternal: function(effect) { 704 | effect.element.undoClipping().undoPositioned(); 705 | effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom}); } 706 | }, arguments[1] || { }) 707 | ); 708 | }; 709 | 710 | Effect.SlideUp = function(element) { 711 | element = $(element).cleanWhitespace(); 712 | var oldInnerBottom = element.down().getStyle('bottom'); 713 | var elementDimensions = element.getDimensions(); 714 | return new Effect.Scale(element, window.opera ? 0 : 1, 715 | Object.extend({ scaleContent: false, 716 | scaleX: false, 717 | scaleMode: 'box', 718 | scaleFrom: 100, 719 | scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, 720 | restoreAfterFinish: true, 721 | afterSetup: function(effect) { 722 | effect.element.makePositioned(); 723 | effect.element.down().makePositioned(); 724 | if (window.opera) effect.element.setStyle({top: ''}); 725 | effect.element.makeClipping().show(); 726 | }, 727 | afterUpdateInternal: function(effect) { 728 | effect.element.down().setStyle({bottom: 729 | (effect.dims[0] - effect.element.clientHeight) + 'px' }); 730 | }, 731 | afterFinishInternal: function(effect) { 732 | effect.element.hide().undoClipping().undoPositioned(); 733 | effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom}); 734 | } 735 | }, arguments[1] || { }) 736 | ); 737 | }; 738 | 739 | // Bug in opera makes the TD containing this element expand for a instance after finish 740 | Effect.Squish = function(element) { 741 | return new Effect.Scale(element, window.opera ? 1 : 0, { 742 | restoreAfterFinish: true, 743 | beforeSetup: function(effect) { 744 | effect.element.makeClipping(); 745 | }, 746 | afterFinishInternal: function(effect) { 747 | effect.element.hide().undoClipping(); 748 | } 749 | }); 750 | }; 751 | 752 | Effect.Grow = function(element) { 753 | element = $(element); 754 | var options = Object.extend({ 755 | direction: 'center', 756 | moveTransition: Effect.Transitions.sinoidal, 757 | scaleTransition: Effect.Transitions.sinoidal, 758 | opacityTransition: Effect.Transitions.full 759 | }, arguments[1] || { }); 760 | var oldStyle = { 761 | top: element.style.top, 762 | left: element.style.left, 763 | height: element.style.height, 764 | width: element.style.width, 765 | opacity: element.getInlineOpacity() }; 766 | 767 | var dims = element.getDimensions(); 768 | var initialMoveX, initialMoveY; 769 | var moveX, moveY; 770 | 771 | switch (options.direction) { 772 | case 'top-left': 773 | initialMoveX = initialMoveY = moveX = moveY = 0; 774 | break; 775 | case 'top-right': 776 | initialMoveX = dims.width; 777 | initialMoveY = moveY = 0; 778 | moveX = -dims.width; 779 | break; 780 | case 'bottom-left': 781 | initialMoveX = moveX = 0; 782 | initialMoveY = dims.height; 783 | moveY = -dims.height; 784 | break; 785 | case 'bottom-right': 786 | initialMoveX = dims.width; 787 | initialMoveY = dims.height; 788 | moveX = -dims.width; 789 | moveY = -dims.height; 790 | break; 791 | case 'center': 792 | initialMoveX = dims.width / 2; 793 | initialMoveY = dims.height / 2; 794 | moveX = -dims.width / 2; 795 | moveY = -dims.height / 2; 796 | break; 797 | } 798 | 799 | return new Effect.Move(element, { 800 | x: initialMoveX, 801 | y: initialMoveY, 802 | duration: 0.01, 803 | beforeSetup: function(effect) { 804 | effect.element.hide().makeClipping().makePositioned(); 805 | }, 806 | afterFinishInternal: function(effect) { 807 | new Effect.Parallel( 808 | [ new Effect.Opacity(effect.element, { sync: true, to: 1.0, from: 0.0, transition: options.opacityTransition }), 809 | new Effect.Move(effect.element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }), 810 | new Effect.Scale(effect.element, 100, { 811 | scaleMode: { originalHeight: dims.height, originalWidth: dims.width }, 812 | sync: true, scaleFrom: window.opera ? 1 : 0, transition: options.scaleTransition, restoreAfterFinish: true}) 813 | ], Object.extend({ 814 | beforeSetup: function(effect) { 815 | effect.effects[0].element.setStyle({height: '0px'}).show(); 816 | }, 817 | afterFinishInternal: function(effect) { 818 | effect.effects[0].element.undoClipping().undoPositioned().setStyle(oldStyle); 819 | } 820 | }, options) 821 | ) 822 | } 823 | }); 824 | }; 825 | 826 | Effect.Shrink = function(element) { 827 | element = $(element); 828 | var options = Object.extend({ 829 | direction: 'center', 830 | moveTransition: Effect.Transitions.sinoidal, 831 | scaleTransition: Effect.Transitions.sinoidal, 832 | opacityTransition: Effect.Transitions.none 833 | }, arguments[1] || { }); 834 | var oldStyle = { 835 | top: element.style.top, 836 | left: element.style.left, 837 | height: element.style.height, 838 | width: element.style.width, 839 | opacity: element.getInlineOpacity() }; 840 | 841 | var dims = element.getDimensions(); 842 | var moveX, moveY; 843 | 844 | switch (options.direction) { 845 | case 'top-left': 846 | moveX = moveY = 0; 847 | break; 848 | case 'top-right': 849 | moveX = dims.width; 850 | moveY = 0; 851 | break; 852 | case 'bottom-left': 853 | moveX = 0; 854 | moveY = dims.height; 855 | break; 856 | case 'bottom-right': 857 | moveX = dims.width; 858 | moveY = dims.height; 859 | break; 860 | case 'center': 861 | moveX = dims.width / 2; 862 | moveY = dims.height / 2; 863 | break; 864 | } 865 | 866 | return new Effect.Parallel( 867 | [ new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0, transition: options.opacityTransition }), 868 | new Effect.Scale(element, window.opera ? 1 : 0, { sync: true, transition: options.scaleTransition, restoreAfterFinish: true}), 869 | new Effect.Move(element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }) 870 | ], Object.extend({ 871 | beforeStartInternal: function(effect) { 872 | effect.effects[0].element.makePositioned().makeClipping(); 873 | }, 874 | afterFinishInternal: function(effect) { 875 | effect.effects[0].element.hide().undoClipping().undoPositioned().setStyle(oldStyle); } 876 | }, options) 877 | ); 878 | }; 879 | 880 | Effect.Pulsate = function(element) { 881 | element = $(element); 882 | var options = arguments[1] || { }; 883 | var oldOpacity = element.getInlineOpacity(); 884 | var transition = options.transition || Effect.Transitions.sinoidal; 885 | var reverser = function(pos){ return transition(1-Effect.Transitions.pulse(pos, options.pulses)) }; 886 | reverser.bind(transition); 887 | return new Effect.Opacity(element, 888 | Object.extend(Object.extend({ duration: 2.0, from: 0, 889 | afterFinishInternal: function(effect) { effect.element.setStyle({opacity: oldOpacity}); } 890 | }, options), {transition: reverser})); 891 | }; 892 | 893 | Effect.Fold = function(element) { 894 | element = $(element); 895 | var oldStyle = { 896 | top: element.style.top, 897 | left: element.style.left, 898 | width: element.style.width, 899 | height: element.style.height }; 900 | element.makeClipping(); 901 | return new Effect.Scale(element, 5, Object.extend({ 902 | scaleContent: false, 903 | scaleX: false, 904 | afterFinishInternal: function(effect) { 905 | new Effect.Scale(element, 1, { 906 | scaleContent: false, 907 | scaleY: false, 908 | afterFinishInternal: function(effect) { 909 | effect.element.hide().undoClipping().setStyle(oldStyle); 910 | } }); 911 | }}, arguments[1] || { })); 912 | }; 913 | 914 | Effect.Morph = Class.create(Effect.Base, { 915 | initialize: function(element) { 916 | this.element = $(element); 917 | if (!this.element) throw(Effect._elementDoesNotExistError); 918 | var options = Object.extend({ 919 | style: { } 920 | }, arguments[1] || { }); 921 | 922 | if (!Object.isString(options.style)) this.style = $H(options.style); 923 | else { 924 | if (options.style.include(':')) 925 | this.style = options.style.parseStyle(); 926 | else { 927 | this.element.addClassName(options.style); 928 | this.style = $H(this.element.getStyles()); 929 | this.element.removeClassName(options.style); 930 | var css = this.element.getStyles(); 931 | this.style = this.style.reject(function(style) { 932 | return style.value == css[style.key]; 933 | }); 934 | options.afterFinishInternal = function(effect) { 935 | effect.element.addClassName(effect.options.style); 936 | effect.transforms.each(function(transform) { 937 | effect.element.style[transform.style] = ''; 938 | }); 939 | } 940 | } 941 | } 942 | this.start(options); 943 | }, 944 | 945 | setup: function(){ 946 | function parseColor(color){ 947 | if (!color || ['rgba(0, 0, 0, 0)','transparent'].include(color)) color = '#ffffff'; 948 | color = color.parseColor(); 949 | return $R(0,2).map(function(i){ 950 | return parseInt( color.slice(i*2+1,i*2+3), 16 ) 951 | }); 952 | } 953 | this.transforms = this.style.map(function(pair){ 954 | var property = pair[0], value = pair[1], unit = null; 955 | 956 | if (value.parseColor('#zzzzzz') != '#zzzzzz') { 957 | value = value.parseColor(); 958 | unit = 'color'; 959 | } else if (property == 'opacity') { 960 | value = parseFloat(value); 961 | if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout)) 962 | this.element.setStyle({zoom: 1}); 963 | } else if (Element.CSS_LENGTH.test(value)) { 964 | var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/); 965 | value = parseFloat(components[1]); 966 | unit = (components.length == 3) ? components[2] : null; 967 | } 968 | 969 | var originalValue = this.element.getStyle(property); 970 | return { 971 | style: property.camelize(), 972 | originalValue: unit=='color' ? parseColor(originalValue) : parseFloat(originalValue || 0), 973 | targetValue: unit=='color' ? parseColor(value) : value, 974 | unit: unit 975 | }; 976 | }.bind(this)).reject(function(transform){ 977 | return ( 978 | (transform.originalValue == transform.targetValue) || 979 | ( 980 | transform.unit != 'color' && 981 | (isNaN(transform.originalValue) || isNaN(transform.targetValue)) 982 | ) 983 | ) 984 | }); 985 | }, 986 | update: function(position) { 987 | var style = { }, transform, i = this.transforms.length; 988 | while(i--) 989 | style[(transform = this.transforms[i]).style] = 990 | transform.unit=='color' ? '#'+ 991 | (Math.round(transform.originalValue[0]+ 992 | (transform.targetValue[0]-transform.originalValue[0])*position)).toColorPart() + 993 | (Math.round(transform.originalValue[1]+ 994 | (transform.targetValue[1]-transform.originalValue[1])*position)).toColorPart() + 995 | (Math.round(transform.originalValue[2]+ 996 | (transform.targetValue[2]-transform.originalValue[2])*position)).toColorPart() : 997 | (transform.originalValue + 998 | (transform.targetValue - transform.originalValue) * position).toFixed(3) + 999 | (transform.unit === null ? '' : transform.unit); 1000 | this.element.setStyle(style, true); 1001 | } 1002 | }); 1003 | 1004 | Effect.Transform = Class.create({ 1005 | initialize: function(tracks){ 1006 | this.tracks = []; 1007 | this.options = arguments[1] || { }; 1008 | this.addTracks(tracks); 1009 | }, 1010 | addTracks: function(tracks){ 1011 | tracks.each(function(track){ 1012 | track = $H(track); 1013 | var data = track.values().first(); 1014 | this.tracks.push($H({ 1015 | ids: track.keys().first(), 1016 | effect: Effect.Morph, 1017 | options: { style: data } 1018 | })); 1019 | }.bind(this)); 1020 | return this; 1021 | }, 1022 | play: function(){ 1023 | return new Effect.Parallel( 1024 | this.tracks.map(function(track){ 1025 | var ids = track.get('ids'), effect = track.get('effect'), options = track.get('options'); 1026 | var elements = [$(ids) || $$(ids)].flatten(); 1027 | return elements.map(function(e){ return new effect(e, Object.extend({ sync:true }, options)) }); 1028 | }).flatten(), 1029 | this.options 1030 | ); 1031 | } 1032 | }); 1033 | 1034 | Element.CSS_PROPERTIES = $w( 1035 | 'backgroundColor backgroundPosition borderBottomColor borderBottomStyle ' + 1036 | 'borderBottomWidth borderLeftColor borderLeftStyle borderLeftWidth ' + 1037 | 'borderRightColor borderRightStyle borderRightWidth borderSpacing ' + 1038 | 'borderTopColor borderTopStyle borderTopWidth bottom clip color ' + 1039 | 'fontSize fontWeight height left letterSpacing lineHeight ' + 1040 | 'marginBottom marginLeft marginRight marginTop markerOffset maxHeight '+ 1041 | 'maxWidth minHeight minWidth opacity outlineColor outlineOffset ' + 1042 | 'outlineWidth paddingBottom paddingLeft paddingRight paddingTop ' + 1043 | 'right textIndent top width wordSpacing zIndex'); 1044 | 1045 | Element.CSS_LENGTH = /^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/; 1046 | 1047 | String.__parseStyleElement = document.createElement('div'); 1048 | String.prototype.parseStyle = function(){ 1049 | var style, styleRules = $H(); 1050 | if (Prototype.Browser.WebKit) 1051 | style = new Element('div',{style:this}).style; 1052 | else { 1053 | String.__parseStyleElement.innerHTML = '
    '; 1054 | style = String.__parseStyleElement.childNodes[0].style; 1055 | } 1056 | 1057 | Element.CSS_PROPERTIES.each(function(property){ 1058 | if (style[property]) styleRules.set(property, style[property]); 1059 | }); 1060 | 1061 | if (Prototype.Browser.IE && this.include('opacity')) 1062 | styleRules.set('opacity', this.match(/opacity:\s*((?:0|1)?(?:\.\d*)?)/)[1]); 1063 | 1064 | return styleRules; 1065 | }; 1066 | 1067 | if (document.defaultView && document.defaultView.getComputedStyle) { 1068 | Element.getStyles = function(element) { 1069 | var css = document.defaultView.getComputedStyle($(element), null); 1070 | return Element.CSS_PROPERTIES.inject({ }, function(styles, property) { 1071 | styles[property] = css[property]; 1072 | return styles; 1073 | }); 1074 | }; 1075 | } else { 1076 | Element.getStyles = function(element) { 1077 | element = $(element); 1078 | var css = element.currentStyle, styles; 1079 | styles = Element.CSS_PROPERTIES.inject({ }, function(results, property) { 1080 | results[property] = css[property]; 1081 | return results; 1082 | }); 1083 | if (!styles.opacity) styles.opacity = element.getOpacity(); 1084 | return styles; 1085 | }; 1086 | }; 1087 | 1088 | Effect.Methods = { 1089 | morph: function(element, style) { 1090 | element = $(element); 1091 | new Effect.Morph(element, Object.extend({ style: style }, arguments[2] || { })); 1092 | return element; 1093 | }, 1094 | visualEffect: function(element, effect, options) { 1095 | element = $(element) 1096 | var s = effect.dasherize().camelize(), klass = s.charAt(0).toUpperCase() + s.substring(1); 1097 | new Effect[klass](element, options); 1098 | return element; 1099 | }, 1100 | highlight: function(element, options) { 1101 | element = $(element); 1102 | new Effect.Highlight(element, options); 1103 | return element; 1104 | } 1105 | }; 1106 | 1107 | $w('fade appear grow shrink fold blindUp blindDown slideUp slideDown '+ 1108 | 'pulsate shake puff squish switchOff dropOut').each( 1109 | function(effect) { 1110 | Effect.Methods[effect] = function(element, options){ 1111 | element = $(element); 1112 | Effect[effect.charAt(0).toUpperCase() + effect.substring(1)](element, options); 1113 | return element; 1114 | } 1115 | } 1116 | ); 1117 | 1118 | $w('getInlineOpacity forceRerendering setContentZoom collectTextNodes collectTextNodesIgnoreClass getStyles').each( 1119 | function(f) { Effect.Methods[f] = Element[f]; } 1120 | ); 1121 | 1122 | Element.addMethods(Effect.Methods); 1123 | -------------------------------------------------------------------------------- /snorql/scriptaculous/scriptaculous.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us scriptaculous.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008 2 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining 6 | // a copy of this software and associated documentation files (the 7 | // "Software"), to deal in the Software without restriction, including 8 | // without limitation the rights to use, copy, modify, merge, publish, 9 | // distribute, sublicense, and/or sell copies of the Software, and to 10 | // permit persons to whom the Software is furnished to do so, subject to 11 | // the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | // 24 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 25 | 26 | var Scriptaculous = { 27 | Version: '1.8.1', 28 | require: function(libraryName) { 29 | // inserting via DOM fails in Safari 2.0, so brute force approach 30 | document.write('