functionNamespace(name){this.__name__=name;}cw=newNamespace('cw');jQuery.extend(cw,{cubes:newNamespace('cubes'),/* provide a removeEventListener / detachEvent definition to * to bypass a jQuery 1.4.2 bug when unbind() is called on a * plain JS object and not a DOM node. * see http://dev.jquery.com/ticket/6184 for more details */removeEventListener:function(){},detachEvent:function(){},log:function(){varargs=[];for(vari=0;i<arguments.length;i++){args.push(arguments[i]);}if(typeof(window)!="undefined"&&window.console&&window.console.log){window.console.log(args.join(' '));}},//removed: getElementsByTagAndClassName, replaceChildNodes, toggleElementClass// partial, merge, isNotEmpty, update,// String.in_, String.join, list, getattr, attrgetter, methodcaller,// min, max, dict, concatjqNode:function(node){/** * .. function:: jqNode(node) * * safe version of jQuery('#nodeid') because we use ':' in nodeids * which messes with jQuery selection mechanism */if(typeof(node)=='string'){node=document.getElementById(node);}if(node){return$(node);}returnnull;},// escapes string selectors (e.g. "foo.[subject]:42" -> "foo\.\[subject\]\:42"escape:function(selector){if(typeof(selector)=='string'){returnselector.replace(/(:|\.|\[|\])/g,"\\$1");}// cw.log('non string selector', selector);return'';},getNode:function(node){if(typeof(node)=='string'){returndocument.getElementById(node);}returnnode;},evalJSON:function(json){// trust sourcetry{returneval("("+json+")");}catch(e){cw.log(e);cw.log('The faulty json source was',json);throw(e);}},urlEncode:function(str){if(typeof(encodeURIComponent)!="undefined"){returnencodeURIComponent(str).replace(/\'/g,'%27');}else{returnescape(str).replace(/\+/g,'%2B').replace(/\"/g,'%22').rval.replace(/\'/g,'%27');}},swapDOM:function(dest,src){dest=cw.getNode(dest);varparent=dest.parentNode;if(src){src=cw.getNode(src);parent.replaceChild(src,dest);}else{parent.removeChild(dest);}returnsrc;},sortValueExtraction:function(node){var$node=$(node);varsortvalue=$node.attr('cubicweb:sortvalue');// No metadata found, use cell content as sort keyif(sortvalue===undefined){return$node.text();}returncw.evalJSON(sortvalue);},});cw.utils=newNamespace('cw.utils');jQuery.extend(cw.utils,{deprecatedFunction:function(msg,newfunc){returnfunction(){cw.log(msg);returnnewfunc.apply(this,arguments);};},createDomFunction:function(tag){functionbuilddom(params,children){varnode=document.createElement(tag);for(keyinparams){varvalue=params[key];if(key.substring(0,2)=='on'){// this is an event handler definitionif(typeofvalue=='string'){// litteral definitionvalue=newFunction(value);}node[key]=value;}else{// normal node attributejQuery(node).attr(key,params[key]);}}if(children){if(!cw.utils.isArrayLike(children)){children=[children];for(vari=2;i<arguments.length;i++){vararg=arguments[i];if(cw.utils.isArray(arg)){jQuery.merge(children,arg);}else{children.push(arg);}}}for(vari=0;i<children.length;i++){varchild=children[i];if(typeofchild=="string"||typeofchild=="number"){child=document.createTextNode(child);}node.appendChild(child);}}returnnode;}returnbuilddom;},/** * .. function:: toISOTimestamp(date) * */toISOTimestamp:function(date){if(typeof(date)=="undefined"||date===null){returnnull;}function_padTwo(n){return(n>9)?n:"0"+n;}varisoTime=[_padTwo(date.getHours()),_padTwo(date.getMinutes()),_padTwo(date.getSeconds())].join(':');varisoDate=[date.getFullYear(),_padTwo(date.getMonth()+1),_padTwo(date.getDate())].join("-");returnisoDate+" "+isoTime;},/** * .. function:: nodeWalkDepthFirst(node, visitor) * * depth-first implementation of the nodeWalk function found * in `MochiKit.Base <http://mochikit.com/doc/html/MochiKit/Base.html#fn-nodewalk>`_ */nodeWalkDepthFirst:function(node,visitor){varchildren=visitor(node);if(children){for(vari=0;i<children.length;i++){cw.utils.nodeWalkDepthFirst(children[i],visitor);}}},isArray:function(it){// taken from dojoreturnit&&(itinstanceofArray||typeofit=="array");},isString:function(it){// taken from dojoreturn!!arguments.length&&it!=null&&(typeofit=="string"||itinstanceofString);},isArrayLike:function(it){// taken from dojoreturn(it&&it!==undefined&&// keep out built-in constructors (Number, String, ...)// which have length properties!cw.utils.isString(it)&&!jQuery.isFunction(it)&&!(it.tagName&&it.tagName.toLowerCase()=='form')&&(cw.utils.isArray(it)||isFinite(it.length)));},/** * .. function:: formContents(elem) * * cannot use jQuery.serializeArray() directly because of FCKeditor */formContents:function(elem){var$elem,array,names,values;$elem=cw.jqNode(elem);array=$elem.serializeArray();if(typeofFCKeditor!=='undefined'){$elem.find('textarea').each(function(idx,textarea){varfck=FCKeditorAPI.GetInstance(textarea.id);if(fck){array=jQuery.map(array,function(dict){if(dict.name===textarea.name){// filter out the textarea's - likely empty - value ...returnnull;}returndict;});// ... so we can put the HTML coming from FCKeditor instead.array.push({name:textarea.name,value:fck.GetHTML()});}});}names=[];values=[];jQuery.each(array,function(idx,dict){names.push(dict.name);values.push(dict.value);});return[names,values];},/** * .. function:: sliceList(lst, start, stop, step) * * returns a subslice of `lst` using `start`/`stop`/`step` * start, stop might be negative * * >>> sliceList(['a', 'b', 'c', 'd', 'e', 'f'], 2) * ['c', 'd', 'e', 'f'] * >>> sliceList(['a', 'b', 'c', 'd', 'e', 'f'], 2, -2) * ['c', 'd'] * >>> sliceList(['a', 'b', 'c', 'd', 'e', 'f'], -3) * ['d', 'e', 'f'] */sliceList:function(lst,start,stop,step){start=start||0;stop=stop||lst.length;step=step||1;if(stop<0){stop=Math.max(lst.length+stop,0);}if(start<0){start=Math.min(lst.length+start,lst.length);}varresult=[];for(vari=start;i<stop;i+=step){result.push(lst[i]);}returnresult;},/** * returns the last element of an array-like object or undefined if empty */lastOf:function(array){if(array.length){returnarray[array.length-1];}else{returnundefined;}},/** * .. function:: extend(array1, array2) * * equivalent of python ``+=`` statement on lists (array1 += array2) */extend:function(array1,array2){array1.push.apply(array1,array2);returnarray1;// return array1 for convenience},/** * .. function:: difference(lst1, lst2) * * returns a list containing all elements in `lst1` that are not * in `lst2`. */difference:function(lst1,lst2){returnjQuery.grep(lst1,function(elt,i){returnjQuery.inArray(elt,lst2)==-1;});},/** * .. function:: domid(string) * * return a valid DOM id from a string (should also be usable in jQuery * search expression...). This is the javascript implementation of * :func:`cubicweb.uilib.domid`. */domid:function(string){varnewstring=string.replace(".","_").replace("-","_");while(newstring!=string){string=newstring;newstring=newstring.replace(".","_").replace("-","_");}returnnewstring;// XXX},/** * .. function:: strFuncCall(fname, *args) * * return a string suitable to call the `fname` javascript function with the * given arguments (which should be correctly typed).. This is providing * javascript implementation equivalent to :func:`cubicweb.uilib.js`. */strFuncCall:function(fname/* ...*/){return(fname+'('+$.map(cw.utils.sliceList(arguments,1),JSON.stringify).join(',')+')');},callAjaxFuncThenReload:functioncallAjaxFuncThenReload(/*...*/){vard=asyncRemoteExec.apply(null,arguments);d.addCallback(function(msg){window.location.reload();if(msg)updateMessage(msg);});}});/** DOM factories ************************************************************/A=cw.utils.createDomFunction('a');BUTTON=cw.utils.createDomFunction('button');BR=cw.utils.createDomFunction('br');CANVAS=cw.utils.createDomFunction('canvas');DD=cw.utils.createDomFunction('dd');DIV=cw.utils.createDomFunction('div');DL=cw.utils.createDomFunction('dl');DT=cw.utils.createDomFunction('dt');FIELDSET=cw.utils.createDomFunction('fieldset');FORM=cw.utils.createDomFunction('form');H1=cw.utils.createDomFunction('H1');H2=cw.utils.createDomFunction('H2');H3=cw.utils.createDomFunction('H3');H4=cw.utils.createDomFunction('H4');H5=cw.utils.createDomFunction('H5');H6=cw.utils.createDomFunction('H6');HR=cw.utils.createDomFunction('hr');IMG=cw.utils.createDomFunction('img');INPUT=cw.utils.createDomFunction('input');LABEL=cw.utils.createDomFunction('label');LEGEND=cw.utils.createDomFunction('legend');LI=cw.utils.createDomFunction('li');OL=cw.utils.createDomFunction('ol');OPTGROUP=cw.utils.createDomFunction('optgroup');OPTION=cw.utils.createDomFunction('option');P=cw.utils.createDomFunction('p');PRE=cw.utils.createDomFunction('pre');SELECT=cw.utils.createDomFunction('select');SPAN=cw.utils.createDomFunction('span');STRONG=cw.utils.createDomFunction('strong');TABLE=cw.utils.createDomFunction('table');TBODY=cw.utils.createDomFunction('tbody');TD=cw.utils.createDomFunction('td');TEXTAREA=cw.utils.createDomFunction('textarea');TFOOT=cw.utils.createDomFunction('tfoot');TH=cw.utils.createDomFunction('th');THEAD=cw.utils.createDomFunction('thead');TR=cw.utils.createDomFunction('tr');TT=cw.utils.createDomFunction('tt');UL=cw.utils.createDomFunction('ul');// cubicweb specific//IFRAME = cw.utils.createDomFunction('iframe');functionIFRAME(params){if('name'inparams){try{varnode=document.createElement('<iframe name="'+params['name']+'">');}catch(ex){varnode=document.createElement('iframe');node.id=node.name=params.name;}}else{varnode=document.createElement('iframe');}for(keyinparams){if(key!='name'){varvalue=params[key];if(key.substring(0,2)=='on'){// this is an event handler definitionif(typeofvalue=='string'){// litteral definitionvalue=newFunction(value);}node[key]=value;}else{// normal node attributenode.setAttribute(key,params[key]);}}}returnnode;}// cubes: tag, keyword and apycot seem to use this, including require/provide// backward compatCubicWeb=cw;jQuery.extend(cw,{require:cw.utils.deprecatedFunction('[3.9] CubicWeb.require() is not used anymore',function(module){}),provide:cw.utils.deprecatedFunction('[3.9] CubicWeb.provide() is not used anymore',function(module){})});jQuery(document).ready(function(){$(cw).trigger('server-response',[false,document]);});