]> dev.renevier.net Git - syj.git/blobdiff - public/js/utils.js
fixes: ui is not correctly refreshed after account creation
[syj.git] / public / js / utils.js
index 348e3a70425033b7859c767cddac9d2929f7e9e8..b16a9c2ec4206c1ec83bba7ca38e20f425585a60 100644 (file)
@@ -15,7 +15,7 @@ var CloseBtn = Class.create({
         }
 
         style = Object.extend({
-            float: "right",
+            'float': "right",
             margin: "2px",
             fontWeight: "bold",
             padding: "0px"
@@ -26,6 +26,9 @@ var CloseBtn = Class.create({
         elt.insert({top: btn});
         btn.observe("click", function(evt) {
             evt.stop();
+            if (evt.detail === 0) { // it's not a real click, possibly a submit event
+                return;
+            }
             if (typeof options.callback === "function") {
                 options.callback.call(elt);
             }
@@ -122,6 +125,23 @@ Element.addMethods({
         Element.setStyle(element, {'backgroundColor': color});
         Element.setStyle.delay(timeout, element, {'backgroundColor': current});
         return element;
+    },
+    text: function(element, content) {
+        if (typeof content === "undefined") { // getter
+            if (element.nodeType === 8) {
+                return "";
+            } else if (element.nodeType === 3 || element.nodeType === 4)  {
+                return element.nodeValue;
+            } else {
+                return $A(element.childNodes).inject("", function(acc, el) {
+                    return acc + Element.text(el);
+                 });
+            }
+        } else { // setter
+            var node = document.createTextNode(content);
+            element.update().appendChild(node);
+            return element;
+        }
     }
 });
 
@@ -319,7 +339,7 @@ Element.addMethods(['input', 'textarea'], {
                 }
                 handler.apply(null, arguments);
             });
-            proceed(element, 'paste', handler);
+            proceed(element, 'paste', handler.defer.bind(handler));
             return proceed(element, 'change', handler);
         }
         return proceed(element, eventName, handler);
@@ -375,7 +395,7 @@ Element.addMethods('div', {
 
         while (node) {
             nextNode = node.nextSibling;
-            if (node.nodeType === 3 || node.tagName.toLowerCase() === 'br') {
+            if (node.nodeType === 3 || node.tagName.toLowerCase() === 'br' || node.textContent || node.innerText) {
                 div.removeChild(node);
             }
                 node = nextNode;
@@ -388,7 +408,7 @@ Element.addMethods('div', {
         var node = (div.ownerDocument || document).createTextNode(message);
 
         if ($A(div.childNodes).filter(function(node) {
-                return (node.nodeType === 3 || node.tagName.toLowerCase() === 'br');
+                return (node.nodeType === 3 || node.tagName.toLowerCase() === 'br' || node.textContent || node.innerText);
              }).length) {
             div.insert(new Element('br'));
         }