web/data/cubicweb.js
changeset 9815 12e6d911027a
parent 9661 c170ec8a4525
child 9821 2077c8da1893
equal deleted inserted replaced
9814:faf0511ac181 9815:12e6d911027a
   205                 !(it.tagName && it.tagName.toLowerCase() == 'form') &&
   205                 !(it.tagName && it.tagName.toLowerCase() == 'form') &&
   206                 (cw.utils.isArray(it) || isFinite(it.length)));
   206                 (cw.utils.isArray(it) || isFinite(it.length)));
   207     },
   207     },
   208 
   208 
   209     /**
   209     /**
   210      * .. function:: formContents(elem \/* = document.body *\/)
   210      * .. function:: formContents(elem)
   211      *
   211      *
   212      * this implementation comes from MochiKit
   212      * cannot use jQuery.serializeArray() directly because of FCKeditor
   213      */
   213      */
   214     formContents: function (elem /* = document.body */ ) {
   214     formContents: function (elem) {
   215         var names = [];
   215         var $elem, array, names, values;
   216         var values = [];
   216         $elem = cw.jqNode(elem);
   217         if (typeof(elem) == "undefined" || elem === null) {
   217         array = $elem.serializeArray();
   218             elem = document.body;
   218 
   219         } else {
   219         if (typeof FCKeditor !== 'undefined') {
   220             elem = cw.getNode(elem);
   220             $elem.find('textarea').each(function (idx, textarea) {
   221         }
   221                 var fck = FCKeditorAPI.GetInstance(textarea.id);
   222         cw.utils.nodeWalkDepthFirst(elem, function (elem) {
   222                 if (fck) {
   223             var name = elem.name;
   223                     array = jQuery.map(array, function (dict) {
   224             if (name && name.length) {
   224                         if (dict.name === textarea.name) {
   225                 if (elem.disabled) {
   225                             // filter out the textarea's - likely empty - value ...
   226                     return null;
       
   227                 }
       
   228                 var tagName = elem.tagName.toUpperCase();
       
   229                 if (tagName === "INPUT" && (elem.type == "radio" || elem.type == "checkbox") && !elem.checked) {
       
   230                     return null;
       
   231                 }
       
   232                 if (tagName === "SELECT") {
       
   233                     if (elem.type == "select-one") {
       
   234                         if (elem.selectedIndex >= 0) {
       
   235                             var opt = elem.options[elem.selectedIndex];
       
   236                             var v = opt.value;
       
   237                             if (!v) {
       
   238                                 var h = opt.outerHTML;
       
   239                                 // internet explorer sure does suck.
       
   240                                 if (h && !h.match(/^[^>]+\svalue\s*=/i)) {
       
   241                                     v = opt.text;
       
   242                                 }
       
   243                             }
       
   244                             names.push(name);
       
   245                             values.push(v);
       
   246                             return null;
   226                             return null;
   247                         }
   227                         }
   248                         // no form elements?
   228                         return dict;
   249                         names.push(name);
   229                     });
   250                         values.push("");
   230                     // ... so we can put the HTML coming from FCKeditor instead.
   251                         return null;
   231                     array.push({
   252                     } else {
   232                         name: textarea.name,
   253                         var opts = elem.options;
   233                         value: fck.GetHTML()
   254                         if (!opts.length) {
   234                     });
   255                             names.push(name);
       
   256                             values.push("");
       
   257                             return null;
       
   258                         }
       
   259                         for (var i = 0; i < opts.length; i++) {
       
   260                             var opt = opts[i];
       
   261                             if (!opt.selected) {
       
   262                                 continue;
       
   263                             }
       
   264                             var v = opt.value;
       
   265                             if (!v) {
       
   266                                 var h = opt.outerHTML;
       
   267                                 // internet explorer sure does suck.
       
   268                                 if (h && !h.match(/^[^>]+\svalue\s*=/i)) {
       
   269                                     v = opt.text;
       
   270                                 }
       
   271                             }
       
   272                             names.push(name);
       
   273                             values.push(v);
       
   274                         }
       
   275                         return null;
       
   276                     }
       
   277                 }
   235                 }
   278                 if (tagName === "FORM" || tagName === "P" || tagName === "SPAN" || tagName === "DIV") {
   236             });
   279                     return elem.childNodes;
   237         }
   280                 }
   238 
   281 		var value = elem.value;
   239         names = [];
   282 		if (tagName === "TEXTAREA") {
   240         values = [];
   283 		    if (typeof(FCKeditor) != 'undefined') {
   241         jQuery.each(array, function (idx, dict) {
   284 			var fck = FCKeditorAPI.GetInstance(elem.id);
   242             names.push(dict.name);
   285 			if (fck) {
   243             values.push(dict.value);
   286 			    value = fck.GetHTML();
       
   287 			}
       
   288 		    }
       
   289 		}
       
   290                 names.push(name);
       
   291                 values.push(value || '');
       
   292                 return null;
       
   293             }
       
   294             return elem.childNodes;
       
   295         });
   244         });
   296         return [names, values];
   245         return [names, values];
   297     },
   246     },
   298 
   247 
   299     /**
   248     /**