departr 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,176 @@
1
+ /* Greatly inspired by https://github.com/ErikDubbelboer/MooComplete */
2
+ var AutoComplete = new Class({
3
+
4
+ Implements: [Options, Events],
5
+
6
+ options: {
7
+ list: [],
8
+ size: 10,
9
+ filters: [
10
+ function(o, v) { return (o.indexOf(v) == 0); },
11
+ function(o, v) { return ((v.length > 1) && (o.indexOf(v) > 0)); }
12
+ ],
13
+ render: function(v) { return new Element('span', {'text': v}); },
14
+ get: function(v) { return v; },
15
+ set: function(v) { return v; }
16
+ },
17
+
18
+ initialize: function(element, options) {
19
+ this.setOptions(options);
20
+
21
+ // allow id and dom object selection
22
+ this.element = typeOf(element)==='string' ? $(element) : element;
23
+
24
+ // for older versions of IE this doesn't work, for those you need to set autocomplete=off in the html.
25
+ this.element.setAttribute('autocomplete', 'off');
26
+
27
+ // disable auto correct and capitalize on iPhone and iPad.
28
+ this.element.setAttribute('autocorrect', 'off');
29
+ this.element.setAttribute('autocapitalize', 'off');
30
+
31
+ this.box = new Element('div', {
32
+ 'class': 'autocomplete',
33
+ 'styles': {
34
+ 'position': 'absolute',
35
+ 'display': 'none'
36
+ }
37
+ }).inject(document.body);
38
+
39
+ // build suggestions elements
40
+ this.setList(this.options.list);
41
+
42
+ // reposition on a resize.
43
+ window.addEvent('resize', this.position.bind(this));
44
+
45
+ this.element.addEvents({
46
+ 'keydown': this.onKeydown.bind(this),
47
+ 'keyup': this.onKeyup.bind(this),
48
+ 'blur': this.onBlur.bind(this)
49
+ });
50
+
51
+ return this;
52
+ },
53
+
54
+ setList: function(list) {
55
+ this.hover = false;
56
+ this.options.list = list;
57
+ this.suggestions = [];
58
+ this.box.empty();
59
+ list.each(function(value) {
60
+ var div = new Element('div');
61
+ // don't use mouseover since that will bug when the user has the mouse below the input box while typing
62
+ div.addEvent('mousemove', function() {
63
+ this.showHover(div);
64
+ }.bind(this))
65
+ .adopt(this.options.render(value))
66
+ .store('value', value);
67
+
68
+ this.suggestions.push(div);
69
+ this.box.adopt(div);
70
+ }, this);
71
+ },
72
+
73
+ position: function() {
74
+ this.box.setStyles({
75
+ 'width': (this.element.getWidth() - 2)+'px',
76
+ 'top': (this.element.getCoordinates().top + this.element.getHeight())+'px',
77
+ 'left': this.element.getCoordinates().left +'px'
78
+ });
79
+ },
80
+
81
+ showHover: function(div) {
82
+ if (!div || div == this.hover) return;
83
+ if (this.hover) this.hover.removeClass('hovered');
84
+ this.hover = div.addClass('hovered');
85
+ this.element.set('value', this.options.set(div.retrieve('value')));
86
+ },
87
+
88
+ isHidden: function() {
89
+ return this.box.getStyle('display') == 'none';
90
+ },
91
+
92
+ hide: function() {
93
+ this.box.setStyle('display', 'none');
94
+ },
95
+
96
+ onKeydown: function(e) {
97
+ switch(e.key) {
98
+ case 'up':
99
+ e.stop();
100
+ if (this.hover) this.showHover(this.hover.getPrevious('.match'));
101
+ break;
102
+
103
+ case 'down':
104
+ e.stop();
105
+ if (this.hover) {
106
+ this.showHover(this.hover.getNext('.match'));
107
+ } else {
108
+ this.showHover(this.box.getFirst('.match'))
109
+ }
110
+ break;
111
+
112
+ case 'esc':
113
+ this.hide();
114
+ this.fireEvent('abort');
115
+ break;
116
+
117
+ case 'enter':
118
+ case 'tab':
119
+ if (!this.isHidden()) {
120
+ e.stop();
121
+ this.fireEvent('complete', [this.hover.retrieve('value')]);
122
+ this.hide();
123
+ }
124
+ break;
125
+ }
126
+ },
127
+
128
+ onKeyup: function(e) {
129
+ switch(e.key) {
130
+ case 'up':
131
+ case 'down':
132
+ case 'esc':
133
+ case 'enter':
134
+ break;
135
+
136
+ default:
137
+ var value = this.element.get('value').toLowerCase();
138
+
139
+ if (value.length == 0) {
140
+ this.hide();
141
+ return;
142
+ }
143
+
144
+ var count = 0;
145
+
146
+ this.options.filters.each(function(f) {
147
+ if (count == this.options.size) return;
148
+
149
+ this.box.getChildren().each(function(div) {
150
+ if (f(this.options.get(div.retrieve('value')).toLowerCase(), value)) {
151
+ div.addClass('match');
152
+ if (++count == this.options.size) return false;
153
+ } else {
154
+ div.removeClass('match');
155
+ }
156
+ }, this);
157
+ }, this);
158
+
159
+ // If no suggestions, no need to show the box
160
+ if (count > 0) {
161
+ this.position();
162
+ this.box.setStyle('display', 'block');
163
+ } else if (!this.isHidden()) {
164
+ this.hide();
165
+ this.fireEvent('abort');
166
+ }
167
+ };
168
+ },
169
+
170
+ onBlur: function() {
171
+ this.hover = false;
172
+ this.hide.delay(100, this);
173
+ }
174
+
175
+ });
176
+
@@ -0,0 +1,422 @@
1
+ /*
2
+ ---
3
+ description: SIMPLE MODAL is a small plugin to create modal windows. It can be used to generate alert or confirm messages with few lines of code. Confirm configuration involves the use of callbacks to be applied to affirmative action;i t can work in asynchronous mode and retrieve content from external pages or getting the inline content. SIMPLE MODAL is not a lightbox although the possibility to hide parts of its layout may partially make it similar.
4
+
5
+ license: MIT-style
6
+
7
+ authors:
8
+ - Marco Dell'Anna
9
+
10
+ requires:
11
+ - core/1.3: '*'
12
+
13
+ provides:
14
+ - SimpleModal
15
+ ...
16
+
17
+ * Mootools Simple Modal
18
+ * Version 1.0
19
+ * Copyright (c) 2011 Marco Dell'Anna - http://www.plasm.it
20
+ *
21
+ * Requires:
22
+ * MooTools http://mootools.net
23
+ *
24
+ * Permission is hereby granted, free of charge, to any person
25
+ * obtaining a copy of this software and associated documentation
26
+ * files (the "Software"), to deal in the Software without
27
+ * restriction, including without limitation the rights to use,
28
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
29
+ * copies of the Software, and to permit persons to whom the
30
+ * Software is furnished to do so, subject to the following
31
+ * conditions:
32
+ *
33
+ * The above copyright notice and this permission notice shall be
34
+ * included in all copies or substantial portions of the Software.
35
+ *
36
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
38
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
39
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
40
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
41
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
42
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
43
+ * OTHER DEALINGS IN THE SOFTWARE.
44
+ *
45
+ * Log:
46
+ * 1.0 - Inizio implementazione release stabile [Tested on: ie7/ie8/ie9/Chrome/Firefox7/Safari]
47
+ */
48
+ var SimpleModal = new Class({
49
+ // Implements
50
+ Implements: [Options],
51
+ request:null,
52
+ buttons:[],
53
+ // Options
54
+ options: {
55
+ onAppend: Function, // callback inject in DOM
56
+ offsetTop: null,
57
+ overlayOpacity:.3,
58
+ overlayColor: "#000000",
59
+ width: 400,
60
+ draggable: true,
61
+ keyEsc: true,
62
+ overlayClick: true,
63
+ closeButton: true, // X close button
64
+ hideHeader: false,
65
+ hideFooter: false,
66
+ btn_ok: "OK", // Label
67
+ btn_cancel: "Cancel", // Label
68
+ template:"<div class=\"simple-modal-header\"><h1>{_TITLE_}</h1></div><div class=\"simple-modal-body\"><div class=\"contents\">{_CONTENTS_}</div></div><div class=\"simple-modal-footer\"></div>"
69
+ },
70
+
71
+ /**
72
+ * Initialization
73
+ */
74
+ initialize: function(options) {
75
+ //set options
76
+ this.setOptions(options);
77
+ },
78
+
79
+ /**
80
+ * public method show
81
+ * Open Modal
82
+ * @options: param to rewrite
83
+ * @return node HTML
84
+ */
85
+ show: function(options){
86
+ if(!options) options = {};
87
+ // Inserisce Overlay
88
+ this._overlay("show");
89
+ // Switch different modal
90
+ switch( options.model ){
91
+ // Require title && contents && callback
92
+ case "confirm":
93
+ // Add button confirm
94
+ this.addButton(this.options.btn_ok, "btn primary btn-margin", function(){
95
+ try{ options.callback() } catch(err){};
96
+ this.hide();
97
+ })
98
+ // Add button cancel
99
+ this.addButton(this.options.btn_cancel, "btn secondary");
100
+ // Rendering
101
+ var node = this._drawWindow(options);
102
+ // Add Esc Behaviour
103
+ this._addEscBehaviour();
104
+ break;
105
+ // Require title && contents (define the action buttons externally)
106
+ case "modal":
107
+ // Rendering
108
+ var node = this._drawWindow(options);
109
+ // Add Esc Behaviour
110
+ this._addEscBehaviour();
111
+ break;
112
+ // Require title && url contents (define the action buttons externally)
113
+ case "modal-ajax":
114
+ // Rendering
115
+ var node = this._drawWindow(options);
116
+ this._loadContents({
117
+ "url":options.param.url || "",
118
+ "onRequestComplete":options.param.onRequestComplete||Function
119
+ })
120
+ break;
121
+ // Require title && contents
122
+ default:
123
+ // Alert
124
+ // Add button
125
+ this.addButton(this.options.btn_ok, "btn primary");
126
+ // Rendering
127
+ var node = this._drawWindow(options);
128
+ // Add Esc Behaviour
129
+ this._addEscBehaviour();
130
+ break;
131
+ }
132
+
133
+ // Custom size Modal
134
+ node.setStyles({width:this.options.width});
135
+
136
+ // Hide Header &&/|| Footer
137
+ if( this.options.hideHeader ) node.addClass("hide-header");
138
+ if( this.options.hideFooter ) node.addClass("hide-footer");
139
+
140
+ // Add Button X
141
+ if( this.options.closeButton ) this._addCloseButton();
142
+
143
+ // Enabled Drag Window
144
+ if( this.options.draggable ){
145
+ var headDrag = node.getElement(".simple-modal-header");
146
+ new Drag(node, { handle:headDrag });
147
+ // Set handle cursor
148
+ headDrag.setStyle("cursor", "move")
149
+ node.addClass("draggable");
150
+ }
151
+ // Resize Stage
152
+ this._display();
153
+ },
154
+
155
+ /**
156
+ * public method hide
157
+ * Close model window
158
+ * return
159
+ */
160
+ hide: function(){
161
+ try{
162
+ if( typeof(this.request) == "object" ) this.request.cancel();
163
+ }catch(err){}
164
+ this._overlay('hide');
165
+ return;
166
+ },
167
+
168
+ /**
169
+ * private method _drawWindow
170
+ * Rendering window
171
+ * return node SM
172
+ */
173
+ _drawWindow:function(options){
174
+ // Add Node in DOM
175
+ var node = new Element("div#simple-modal", {"class":"simple-modal"});
176
+ node.inject( $$("body")[0] );
177
+ // Set Contents
178
+ var html = this._template(this.options.template, {"_TITLE_":options.title || "Untitled", "_CONTENTS_":options.contents || ""});
179
+ node.set("html", html);
180
+ // Add all buttons
181
+ this._injectAllButtons();
182
+ // Callback append
183
+ this.options.onAppend();
184
+ return node;
185
+ },
186
+
187
+ /**
188
+ * public method addButton
189
+ * Add button to Modal button array
190
+ * require @label:string, @classe:string, @clickEvent:event
191
+ * @return node HTML
192
+ */
193
+ addButton: function(label, classe, clickEvent){
194
+ var bt = new Element('a',{
195
+ "title" : label,
196
+ "text" : label,
197
+ "class" : classe,
198
+ "events": {
199
+ click: (clickEvent || this.hide).bind(this)
200
+ }
201
+ });
202
+ this.buttons.push(bt);
203
+ return bt;
204
+ },
205
+
206
+ /**
207
+ * private method _injectAllButtons
208
+ * Inject all buttons in simple-modal-footer
209
+ * @return
210
+ */
211
+ _injectAllButtons: function(){
212
+ this.buttons.each( function(e, i){
213
+ e.inject( $("simple-modal").getElement(".simple-modal-footer") );
214
+ });
215
+ return;
216
+ },
217
+
218
+ /**
219
+ * private method _addCloseButton
220
+ * Inject Close botton (X button)
221
+ * @return node HTML
222
+ */
223
+ _addCloseButton: function(){
224
+ var b = new Element("a", {"class":"close", "href":"#", "html":"x"});
225
+ b.inject($("simple-modal"), "top");
226
+ // Aggiunge bottome X Close
227
+ b.addEvent("click", function(e){
228
+ if(e) e.stop();
229
+ this.hide();
230
+ }.bind( this ))
231
+ return b;
232
+ },
233
+
234
+ /**
235
+ * private method _overlay
236
+ * Create/Destroy overlay and Modal
237
+ * @return
238
+ */
239
+ _overlay: function(status) {
240
+ switch( status ) {
241
+ case 'show':
242
+ this._overlay('hide');
243
+ var overlay = new Element("div", {"id":"simple-modal-overlay"});
244
+ overlay.inject( $$("body")[0] );
245
+ overlay.setStyle("background-color", this.options.overlayColor);
246
+ overlay.fade("hide").fade(this.options.overlayOpacity);
247
+ // Behaviour
248
+ if( this.options.overlayClick){
249
+ overlay.addEvent("click", function(e){
250
+ if(e) e.stop();
251
+ this.hide();
252
+ }.bind(this))
253
+ }
254
+ // Add Control Resize
255
+ this.__resize = this._display.bind(this);
256
+ window.addEvent("resize", this.__resize );
257
+ break;
258
+ case 'hide':
259
+ // Remove Event Resize
260
+ window.removeEvent("resize", this._display);
261
+ // Remove Event Resize
262
+ if(this.options.keyEsc){
263
+ var fixEV = Browser.name != 'ie' ? "keydown" : "onkeydown";
264
+ window.removeEvent(fixEV, this._removeSM);
265
+ }
266
+
267
+ // Remove Overlay
268
+ try{
269
+ $('simple-modal-overlay').destroy();
270
+ }
271
+ catch(err){}
272
+ // Remove Modal
273
+ try{
274
+ $('simple-modal').destroy();
275
+ }
276
+ catch(err){}
277
+ break;
278
+ }
279
+ return;
280
+ },
281
+
282
+ /**
283
+ * private method _loadContents
284
+ * Async request for modal ajax
285
+ * @return
286
+ */
287
+ _loadContents: function(param){
288
+ // Set Loading
289
+ $('simple-modal').addClass("loading");
290
+ // Match image file
291
+ var re = new RegExp( /([^\/\\]+)\.(jpg|png|gif)$/i );
292
+ if( param.url.match(re) ){
293
+ // Hide Header/Footer
294
+ $('simple-modal').addClass("hide-footer");
295
+ // Remove All Event on Overlay
296
+ $("simple-modal-overlay").removeEvents(); // Prevent Abort
297
+ // Immagine
298
+ var images = [param.url];
299
+ new Asset.images(images, {
300
+ onProgress: function(i) {
301
+ immagine = this;
302
+ },
303
+ onComplete: function() {
304
+ try{
305
+ // Remove loading
306
+ $('simple-modal').removeClass("loading");
307
+ // Imposta dimensioni
308
+ var content = $('simple-modal').getElement(".contents");
309
+ var padding = content.getStyle("padding").split(" ");
310
+ var width = (immagine.get("width").toInt()) + (padding[1].toInt()+padding[3].toInt())
311
+ var height = immagine.get("height").toInt();
312
+ // Width
313
+ var myFx1 = new Fx.Tween($("simple-modal"), {
314
+ duration: 'normal',
315
+ transition: 'sine:out',
316
+ link: 'cancel',
317
+ property: 'width'
318
+ }).start($("simple-modal").getCoordinates().width, width);
319
+ // Height
320
+ var myFx2 = new Fx.Tween(content, {
321
+ duration: 'normal',
322
+ transition: 'sine:out',
323
+ link: 'cancel',
324
+ property: 'height'
325
+ }).start(content.getCoordinates().height, height).chain(function(){
326
+ // Inject
327
+ immagine.inject( $('simple-modal').getElement(".contents").empty() ).fade("hide").fade("in");
328
+ this._display();
329
+ // Add Esc Behaviour
330
+ this._addEscBehaviour();
331
+ }.bind(this));
332
+ // Left
333
+ var myFx3 = new Fx.Tween($("simple-modal"), {
334
+ duration: 'normal',
335
+ transition: 'sine:out',
336
+ link: 'cancel',
337
+ property: 'left'
338
+ }).start($("simple-modal").getCoordinates().left, (window.getCoordinates().width - width)/2);
339
+ }catch(err){}
340
+ }.bind(this)
341
+ });
342
+
343
+ }else{
344
+ // Request HTML
345
+ this.request = new Request.HTML({
346
+ evalScripts:false,
347
+ url: param.url,
348
+ method: 'get',
349
+ onRequest: function(){
350
+ },
351
+ onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
352
+ $('simple-modal').removeClass("loading");
353
+ $('simple-modal').getElement(".contents").set("html", responseHTML);
354
+ param.onRequestComplete();
355
+ // Execute script page loaded
356
+ eval(responseJavaScript)
357
+ // Resize
358
+ this._display();
359
+ // Add Esc Behaviour
360
+ this._addEscBehaviour();
361
+ }.bind(this),
362
+ onFailure: function(){
363
+ $('simple-modal').removeClass("loading");
364
+ $('simple-modal').getElement(".contents").set("html", "loading failed")
365
+ }
366
+ }).send();
367
+ }
368
+ },
369
+
370
+ /**
371
+ * private method _display
372
+ * Move interface
373
+ * @return
374
+ */
375
+ _display: function(){
376
+ // Update overlay
377
+ try{
378
+ $("simple-modal-overlay").setStyles({
379
+ height: window.getCoordinates().height //$$("body")[0].getScrollSize().y
380
+ });
381
+ } catch(err){}
382
+
383
+ // Update position popup
384
+ try{
385
+ var offsetTop = this.options.offsetTop || 40; //this.options.offsetTop != null ? this.options.offsetTop : window.getScroll().y + 40;
386
+ $("simple-modal").setStyles({
387
+ top: offsetTop,
388
+ left: ((window.getCoordinates().width - $("simple-modal").getCoordinates().width)/2 )
389
+ });
390
+ } catch(err){}
391
+ return;
392
+ },
393
+
394
+ /**
395
+ * private method _addEscBehaviour
396
+ * add Event ESC
397
+ * @return
398
+ */
399
+ _addEscBehaviour: function(){
400
+ if(this.options.keyEsc){
401
+ this._removeSM = function(e){
402
+ if( e.key == "esc" ) this.hide();
403
+ }.bind(this)
404
+ // Remove Event Resize
405
+ if(this.options.keyEsc){
406
+ var fixEV = Browser.name != 'ie' ? "keydown" : "onkeydown";
407
+ window.addEvent(fixEV, this._removeSM );
408
+ }
409
+ }
410
+ },
411
+
412
+ /**
413
+ * private method _template
414
+ * simple template by Thomas Fuchs
415
+ * @return
416
+ */
417
+ _template:function(s,d){
418
+ for(var p in d)
419
+ s=s.replace(new RegExp('{'+p+'}','g'), d[p]);
420
+ return s;
421
+ }
422
+ });