]> dev.renevier.net Git - syj.git/commitdiff
assemble all utils scripts in a utils.js file
authorarno <arno@renevier.net>
Wed, 28 Jul 2010 13:15:10 +0000 (15:15 +0200)
committerarno <arno@renevier.net>
Fri, 6 Aug 2010 22:09:40 +0000 (00:09 +0200)
12 files changed:
application/controllers/AccountController.php
application/controllers/ContactController.php
application/controllers/IdxController.php
application/controllers/LoginController.php
application/controllers/NewpwdController.php
public/js/ajaxize.js [deleted file]
public/js/closebtn.js [deleted file]
public/js/deck.js [deleted file]
public/js/forms.js [deleted file]
public/js/highlight.js [deleted file]
public/js/message.js [deleted file]
public/js/utils.js [new file with mode: 0644]

index 00de24e14940b121fbea0ec7529e00443696673f..30daa5bc3eead3ad461c261e215358705c130a8c 100644 (file)
@@ -7,8 +7,7 @@ class AccountController extends Zend_Controller_Action
 
     public function init() {
         $this->view->headScript()->appendFile('js/prototype.js');
-        $this->view->headScript()->appendFile('js/forms.js');
-        $this->view->headScript()->appendFile('js/highlight.js');
+        $this->view->headScript()->appendFile('js/utils.js');
         $this->view->headScript()->appendFile('js/account.js');
         $this->view->headLink()->appendStylesheet('css/generic.css');
         $this->view->headLink()->appendStylesheet('css/account.css');
index 03dd4a6b645436290fcf7fbc60c2dbb5c7d9edc6..9a7ade195d7a3e883f5d415471c83ec2fa24fa2f 100644 (file)
@@ -7,8 +7,7 @@ class ContactController extends Zend_Controller_Action
 
     public function init() {
         $this->view->headScript()->appendFile('js/prototype.js');
-        $this->view->headScript()->appendFile('js/forms.js');
-        $this->view->headScript()->appendFile('js/highlight.js');
+        $this->view->headScript()->appendFile('js/utils.js');
         $this->view->headScript()->appendFile('js/contact.js');
         $this->view->headLink()->appendStylesheet('css/generic.css');
         $this->view->headLink()->appendStylesheet('css/contact.css');
index 1e149fd429949f0c7a06f4ec9b314c99e408d2e1..e606ebc260efd54f53422dd57c73c4fb5e08f1e5 100644 (file)
@@ -10,11 +10,7 @@ class IdxController extends Zend_Controller_Action
         $this->view->headScript()->appendFile('js/ModifiablePath.js');
         $this->view->headScript()->appendFile('js/prototype.js');
         $this->view->headScript()->appendFile('js/simplebox.js');
-        $this->view->headScript()->appendFile('js/closebtn.js');
-        $this->view->headScript()->appendFile('js/highlight.js');
-        $this->view->headScript()->appendFile('js/deck.js');
-        $this->view->headScript()->appendFile('js/ajaxize.js');
-        $this->view->headScript()->appendFile('js/message.js');
+        $this->view->headScript()->appendFile('js/utils.js');
         $this->view->headScript()->appendFile('js/syj.js');
         $this->view->headLink()->appendStylesheet('css/openlayers/style.css');
         $this->view->headLink()->appendStylesheet('css/generic.css');
index 07bb40b874b484c90a20e239eb0b59ccf7127210..48636214855fbcd672d941ab275c2201ed325565 100644 (file)
@@ -7,8 +7,7 @@ class LoginController extends Zend_Controller_Action
     public function init() {
         $this->view->headTitle($this->view->translate("login"));
         $this->view->headScript()->appendFile('js/prototype.js');
-        $this->view->headScript()->appendFile('js/forms.js');
-        $this->view->headScript()->appendFile('js/highlight.js');
+        $this->view->headScript()->appendFile('js/utils.js');
         $this->view->headScript()->appendFile('js/login.js');
         $this->view->headLink()->appendStylesheet('css/generic.css');
         $this->view->headLink()->appendStylesheet('css/login.css');
index 5facb89771110c78a40a6712c28fe8108ee089fc..93d7f9fc5ffddc4a3f3f850d6d569dfc94940780 100644 (file)
@@ -8,7 +8,7 @@ class NewpwdController extends Zend_Controller_Action
     public function init() {
         $this->view->headScript()->appendFile('js/prototype.js');
         $this->view->headScript()->appendFile('js/newpwd.js');
-        $this->view->headScript()->appendFile('js/highlight.js');
+        $this->view->headScript()->appendFile('js/utils.js');
         $this->view->headLink()->appendStylesheet('css/generic.css');
         $this->view->headLink()->appendStylesheet('css/newpwd.css');
     }
diff --git a/public/js/ajaxize.js b/public/js/ajaxize.js
deleted file mode 100644 (file)
index 6680110..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
-    and is published under the AGPL license. */
-
-// wrapper around Form.request that sets up the submit listener, stops the
-// submit event, calls presubmit function, calls Form.request and calls a
-// postsubmit function
-Element.addMethods('form', {ajaxize : function(form, options) {
-    var reqoptions, timeout;
-
-    options = Object.clone(options);
-    reqoptions = Object.clone(options);
-    timeout = null;
-
-    function onSuccess(transport, json) {
-        if (timeout) {
-            window.clearTimeout(timeout);
-            timeout = null;
-        }
-        if (transport.getStatus() === 0) {
-            options.onFailure(transport, json);
-        } else {
-            options.onSuccess(transport, json);
-        }
-    }
-
-    function onFailure(transport, json) {
-        if (timeout) {
-            window.clearTimeout(timeout);
-            timeout = null;
-        }
-        options.onFailure(transport, json);
-    }
-
-    delete(reqoptions.presubmit);
-    delete(reqoptions.postsubmit);
-
-    $(form).observe('submit', function(evt) {
-        var req;
-
-        evt.stop(); // cancel form submission
-        if (Object.isFunction(options.presubmit)) {
-            if (options.presubmit(this) === false) {
-                return;
-            }
-        }
-        req = this.request(Object.extend(reqoptions, {
-            onSuccess: onSuccess,
-            onFailure: onFailure
-        }));
-        timeout = (function() {
-            options.onFailure(null);
-            req.abort();
-        }).delay(options.timeout || 20);
-        if (Object.isFunction(options.postsubmit)) {
-            options.postsubmit(this);
-        }
-    });
-}});
diff --git a/public/js/closebtn.js b/public/js/closebtn.js
deleted file mode 100644 (file)
index 84be90a..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Copyright (c) 2010 Arnaud Renevier, Inc, published under the modified BSD
- * license. */
-
-var CloseBtn = Class.create({
-    initialize: function(elt, options) {
-        var btn, imgsrc, style;
-
-        elt = $(elt);
-        if (!elt) {
-            return;
-        }
-
-        style = Object.extend({
-            float: "right",
-            margin: "2px",
-            fontWeight: "bold",
-            padding: "0px"
-        }, typeof options === "object" ? options.style: {});
-
-        imgsrc = (options && options.closeBtnSrc) || "icons/close.png";
-        btn = new Element("input", { type: "image", src: imgsrc, alt: "X"}).setStyle(style);
-        elt.insert({top: btn});
-        btn.observe("click", function(evt) {
-            elt.hide();
-        });
-    }
-});
diff --git a/public/js/deck.js b/public/js/deck.js
deleted file mode 100644 (file)
index 73bc3d2..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
-    and is published under the AGPL license. */
-var Deck = Class.create();
-Deck.prototype = {
-    initialize: function(elt, options) {
-        this.element = $(elt);
-        this.index = null;
-        this.setIndex(parseInt(this.element.readAttribute("selectedindex") || 0, 10));
-    },
-    setIndex: function(idx) {
-        if (idx === this.index) {
-            return;
-        }
-
-        var childs = this.element.childElements();
-        if (childs.length === 0) {
-            this.index = -1;
-            return;
-        }
-        idx = Math.max(0, idx);
-        idx = Math.min(childs.length - 1, idx);
-
-        childs.each(function(item, i) {
-            if (idx === i) {
-                item.show();
-            } else {
-                item.hide();
-            }
-        });
-        this.index = idx;
-    },
-    getIndex: function() {
-        return this.index;
-    }
-};
diff --git a/public/js/forms.js b/public/js/forms.js
deleted file mode 100644 (file)
index 738b056..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
-    and is published under the AGPL license. */
-Element.addMethods(['input', 'textarea'], {
-    check: function(control, callback, errorMessage) {
-        if (callback.call(control)) {
-            return true;
-        }
-        control.insert({
-            after: new Element("div", {className: 'error'}).update(errorMessage)
-        });
-        return false;
-    }
-});
-
-Element.addMethods('form', {
-    focus: function(form) {
-        var tofocus, error;
-
-        tofocus = null;
-        error = form.down('.error');
-        if (error) {
-            tofocus = error.previous('input,textarea');
-        } else {
-            tofocus = form.down('input:not([readonly],[disabled]),textarea:not([readonly][disabled])');
-        }
-        if (tofocus) {
-            if (error && (typeof tofocus.highlight === "function")) {
-                tofocus.highlight('#F08080');
-            }
-            tofocus.focus();
-            tofocus.select();
-        }
-    },
-
-    checkEmptyElements: function(form, errorMessage) {
-        var results = [];
-        form.select('.required').each(function(elt) {
-            var id = elt.getAttribute('for'), control = $(id);
-            if (!control) {
-                return;
-            }
-            if (!control.check(function() {
-                    return !this.value.strip().empty();
-                }, errorMessage)) {
-                results.push(control);
-            }
-        });
-        return results;
-    }
-
-});
diff --git a/public/js/highlight.js b/public/js/highlight.js
deleted file mode 100644 (file)
index 289cd2a..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-Element.addMethods({
-    highlight: function(element, color, timeout) {
-        var current;
-        if (typeof timeout === "undefined") {
-            timeout = 0.3;
-        }
-        current = element.getStyle('backgroundColor');
-        Element.setStyle(element, {'backgroundColor': color});
-        Element.setStyle.delay(timeout, element, {'backgroundColor': current});
-        return element;
-    }
-});
diff --git a/public/js/message.js b/public/js/message.js
deleted file mode 100644 (file)
index 795ae2b..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
-    and is published under the AGPL license. */
-Element.addMethods('div', {
-    setMessage: function(div, message, status) {
-        div.clearMessages();
-        if (status) {
-            div.setMessageStatus(status);
-        }
-        if (message) {
-            div.addMessage(message);
-        }
-        return div;
-    },
-
-    clearMessages: function(div) {
-        var node = div.firstChild;
-        while (node) {
-            var nextNode = node.nextSibling;
-            if (node.nodeType == 3 || node.tagName.toLowerCase() == 'br') {
-                div.removeChild(node);
-            }
-                node = nextNode;
-        }
-
-        return div;
-    },
-
-    addMessage: function(div, message) {
-        var node = (div.ownerDocument || document).createTextNode(message);
-        if (!div.empty()) {
-            div.insert(new Element('br'));
-        }
-        div.appendChild(node);
-        return div.show();
-    },
-
-    setMessageStatus: function(div, status) {
-        return div.removeClassName('error').
-                removeClassName('warn').
-                removeClassName('info').
-                removeClassName('success').
-                addClassName(status);
-    }
-});
diff --git a/public/js/utils.js b/public/js/utils.js
new file mode 100644 (file)
index 0000000..d8696a0
--- /dev/null
@@ -0,0 +1,222 @@
+/*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
+    and is published under the AGPL license. */
+
+var CloseBtn = Class.create({
+    initialize: function(elt, options) {
+        var btn, imgsrc, style;
+
+        elt = $(elt);
+        if (!elt) {
+            return;
+        }
+
+        style = Object.extend({
+            float: "right",
+            margin: "2px",
+            fontWeight: "bold",
+            padding: "0px"
+        }, typeof options === "object" ? options.style: {});
+
+        imgsrc = (options && options.closeBtnSrc) || "icons/close.png";
+        btn = new Element("input", { type: "image", src: imgsrc, alt: "X"}).setStyle(style);
+        elt.insert({top: btn});
+        btn.observe("click", function(evt) {
+            elt.hide();
+        });
+    }
+});
+
+var Deck = Class.create({
+    initialize: function(elt, options) {
+        this.element = $(elt);
+        this.index = null;
+        this.setIndex(parseInt(this.element.readAttribute("selectedindex") || 0, 10));
+    },
+    setIndex: function(idx) {
+        if (idx === this.index) {
+            return;
+        }
+
+        var childs = this.element.childElements();
+        if (childs.length === 0) {
+            this.index = -1;
+            return;
+        }
+        idx = Math.max(0, idx);
+        idx = Math.min(childs.length - 1, idx);
+
+        childs.each(function(item, i) {
+            if (idx === i) {
+                item.show();
+            } else {
+                item.hide();
+            }
+        });
+        this.index = idx;
+    },
+    getIndex: function() {
+        return this.index;
+    }
+});
+
+Element.addMethods({
+    highlight: function(element, color, timeout) {
+        var current;
+        if (typeof timeout === "undefined") {
+            timeout = 0.3;
+        }
+        current = element.getStyle('backgroundColor');
+        Element.setStyle(element, {'backgroundColor': color});
+        Element.setStyle.delay(timeout, element, {'backgroundColor': current});
+        return element;
+    }
+});
+
+// wrapper around Form.request that sets up the submit listener, stops the
+// submit event, calls presubmit function, calls Form.request and calls a
+// postsubmit function
+Element.addMethods('form', {
+    ajaxize : function(form, options) {
+        var reqoptions, timeout;
+
+        options = Object.clone(options);
+        reqoptions = Object.clone(options);
+        timeout = null;
+
+        function onSuccess(transport, json) {
+            if (timeout) {
+                window.clearTimeout(timeout);
+                timeout = null;
+            }
+            if (transport.getStatus() === 0) {
+                options.onFailure(transport, json);
+            } else {
+                options.onSuccess(transport, json);
+            }
+        }
+
+        function onFailure(transport, json) {
+            if (timeout) {
+                window.clearTimeout(timeout);
+                timeout = null;
+            }
+            options.onFailure(transport, json);
+        }
+
+        delete(reqoptions.presubmit);
+        delete(reqoptions.postsubmit);
+
+        $(form).observe('submit', function(evt) {
+            var req;
+
+            evt.stop(); // cancel form submission
+            if (Object.isFunction(options.presubmit)) {
+                if (options.presubmit(this) === false) {
+                    return;
+                }
+            }
+            req = this.request(Object.extend(reqoptions, {
+                onSuccess: onSuccess,
+                onFailure: onFailure
+            }));
+            timeout = (function() {
+                options.onFailure(null);
+                req.abort();
+            }).delay(options.timeout || 20);
+            if (Object.isFunction(options.postsubmit)) {
+                options.postsubmit(this);
+            }
+        });
+    },
+
+    focus: function(form) {
+        var tofocus, error;
+
+        tofocus = null;
+        error = form.down('.error');
+        if (error) {
+            tofocus = error.previous('input,textarea');
+        } else {
+            tofocus = form.down('input:not([readonly],[disabled]),textarea:not([readonly][disabled])');
+        }
+        if (tofocus) {
+            if (error && (typeof tofocus.highlight === "function")) {
+                tofocus.highlight('#F08080');
+            }
+            tofocus.focus();
+            tofocus.select();
+        }
+    },
+
+    checkEmptyElements: function(form, errorMessage) {
+        var results = [];
+        form.select('.required').each(function(elt) {
+            var id = elt.getAttribute('for'), control = $(id);
+            if (!control) {
+                return;
+            }
+            if (!control.check(function() {
+                    return !this.value.strip().empty();
+                }, errorMessage)) {
+                results.push(control);
+            }
+        });
+        return results;
+    }
+});
+
+Element.addMethods(['input', 'textarea'], {
+    check: function(control, callback, errorMessage) {
+        if (callback.call(control)) {
+            return true;
+        }
+        control.insert({
+            after: new Element("div", {className: 'error'}).update(errorMessage)
+        });
+        return false;
+    }
+});
+
+Element.addMethods('div', {
+    setMessage: function(div, message, status) {
+        div.clearMessages();
+        if (status) {
+            div.setMessageStatus(status);
+        }
+        if (message) {
+            div.addMessage(message);
+        }
+        return div;
+    },
+
+    clearMessages: function(div) {
+        var node = div.firstChild, nextNode;
+
+        while (node) {
+            nextNode = node.nextSibling;
+            if (node.nodeType === 3 || node.tagName.toLowerCase() === 'br') {
+                div.removeChild(node);
+            }
+                node = nextNode;
+        }
+
+        return div;
+    },
+
+    addMessage: function(div, message) {
+        var node = (div.ownerDocument || document).createTextNode(message);
+        if (!div.empty()) {
+            div.insert(new Element('br'));
+        }
+        div.appendChild(node);
+        return div.show();
+    },
+
+    setMessageStatus: function(div, status) {
+        return div.removeClassName('error').
+                removeClassName('warn').
+                removeClassName('info').
+                removeClassName('success').
+                addClassName(status);
+    }
+});