fix _instantiate_selector() mini bug (make sure obj is a class before calling issubclass)
CubicWeb.require('python.js');/* returns the document's baseURI. (baseuri() uses document.baseURI if * available and inspects the <base> tag manually otherwise.)*/functionbaseuri(){varuri=document.baseURI;if(uri){// some browsers don't define baseURIreturnuri;}varbasetags=document.getElementsByTagName('base');if(basetags.length){returngetNodeAttribute(basetags[0],'href');}return'';}functioninsertText(text,areaId){vartextarea=jQuery('#'+areaId);if(document.selection){// IEvarselLength;textarea.focus();sel=document.selection.createRange();selLength=sel.text.length;sel.text=text;sel.moveStart('character',selLength-text.length);sel.select();}elseif(textarea.selectionStart||textarea.selectionStart=='0'){// mozillavarstartPos=textarea.selectionStart;varendPos=textarea.selectionEnd;// insert text so that it replaces the [startPos, endPos] parttextarea.value=textarea.value.substring(0,startPos)+text+textarea.value.substring(endPos,textarea.value.length);// set cursor pos at the end of the inserted texttextarea.selectionStart=textarea.selectionEnd=startPos+text.length;textarea.focus();}else{// safety belt for other browserstextarea.value+=text;}}/* taken from dojo toolkit */functionsetCaretPos(element,start,end){if(!end){end=element.value.length;}// NOTE: Strange - should be able to put caret at start of text?// Mozilla// parts borrowed from http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130if(element.setSelectionRange){element.focus();element.setSelectionRange(start,end);}elseif(element.createTextRange){// IEvarrange=element.createTextRange();with(range){collapse(true);moveEnd('character',end);moveStart('character',start);select();}}else{//otherwise try the event-creation hack (our own invention)// do we need these?element.value=element.value;element.blur();element.focus();// figure out how far back to govardist=parseInt(element.value.length)-end;vartchar=String.fromCharCode(37);vartcc=tchar.charCodeAt(0);for(varx=0;x<dist;x++){varte=document.createEvent("KeyEvents");te.initKeyEvent("keypress",true,true,null,false,false,false,false,tcc,tcc);element.dispatchEvent(te);}}}functionsetProgressMessage(label){varbody=document.getElementsByTagName('body')[0];body.appendChild(DIV({id:'progress'},label));jQuery('#progress').show();}functionresetProgressMessage(){varbody=document.getElementsByTagName('body')[0];jQuery('#progress').hide();}/* set body's cursor to 'progress' */functionsetProgressCursor(){varbody=document.getElementsByTagName('body')[0];body.style.cursor='progress';}/* * reset body's cursor to default (mouse cursor). The main * purpose of this function is to be used as a callback in the * deferreds' callbacks chain. */functionresetCursor(result){varbody=document.getElementsByTagName('body')[0];body.style.cursor='default';// pass result to next callback in the callback chainreturnresult;}functionupdateMessage(msg){varmsgdiv=DIV({'class':'message'});// don't pass msg to DIV() directly because DIV will html escape it// and msg should alreay be html escaped at this point.msgdiv.innerHTML=msg;jQuery('#appMsg').removeClass('hidden').empty().append(msgdiv);}/* builds an url from an object (used as a dictionnary) * Notable difference with MochiKit's queryString: as_url does not * *url_quote* each value found in the dictionnary * * >>> as_url({'rql' : "RQL", 'x': [1, 2], 'itemvid' : "oneline"}) * rql=RQL&vid=list&itemvid=oneline&x=1&x=2 */functionas_url(props){varchunks=[];for(keyinprops){varvalue=props[key];// generate a list of couple key=value if key is multivaluedif(isArrayLike(value)){for(vari=0;i<value.length;i++){chunks.push(key+'='+value[i]);}}else{chunks.push(key+'='+value);}}returnchunks.join('&');}/* return selected value of a combo box if any */functionfirstSelected(selectNode){varselection=filter(attrgetter('selected'),selectNode.options);return(selection.length>0)?getNodeAttribute(selection[0],'value'):null;}/* toggle visibility of an element by its id */functiontoggleVisibility(elemId){jqNode(elemId).toggleClass('hidden');}/* toggles visibility of login popup div */functionpopupLoginBox(){toggleVisibility('popupLoginBox');jQuery('#__login:visible').focus();}/* * return true (resp. false) if <element> (resp. doesn't) matches <properties> */functionelementMatches(properties,element){for(propinproperties){if(getNodeAttribute(element,prop)!=properties[prop]){returnfalse;}}returntrue;}/* returns the list of elements in the document matching the tag name * and the properties provided * * @param tagName the tag's name * @param properties a js Object used as a dict * @return an iterator (if a *real* array is needed, you can use the * list() function) */functiongetElementsMatching(tagName,properties,/* optional */parent){varfilterfunc=partial(elementMatches,properties);parent=parent||document;returnfilter(filterfunc,parent.getElementsByTagName(tagName));}/* * sets checked/unchecked status of checkboxes */functionsetCheckboxesState(nameprefix,checked){// XXX: this looks in *all* the document for inputsvarelements=getElementsMatching('input',{'type':"checkbox"});filterfunc=function(cb){returnnameprefix&&cb.name.startsWith(nameprefix);};forEach(filter(filterfunc,elements),function(cb){cb.checked=checked;});}functionsetCheckboxesState2(nameprefix,value,checked){// XXX: this looks in *all* the document for inputsvarelements=getElementsMatching('input',{'type':"checkbox"});filterfunc=function(cb){returnnameprefix&&cb.name.startsWith(nameprefix)&&cb.value==value;};forEach(filter(filterfunc,elements),function(cb){cb.checked=checked;});}/* * centers an HTML element on the screen */functioncenterElement(obj){varvpDim=getViewportDimensions();varelemDim=getElementDimensions(obj);setElementPosition(obj,{'x':((vpDim.w-elemDim.w)/2),'y':((vpDim.h-elemDim.h)/2)});}/* this function is a hack to build a dom node from html source */functionhtml2dom(source){vartmpNode=SPAN();tmpNode.innerHTML=source;if(tmpNode.childNodes.length==1){returntmpNode.firstChild;}else{// we leave the span node when `source` has no root node// XXX This is cleary not the best solution, but css/html-wise,/// a span not should not be too much disturbingreturntmpNode;}}// *** HELPERS **************************************************** //functionrql_for_eid(eid){return'Any X WHERE X eid '+eid;}functionisTextNode(domNode){returndomNode.nodeType==3;}functionisElementNode(domNode){returndomNode.nodeType==1;}functionchangeLinkText(link,newText){jQuery(link).text(newText);// for (var i=0; i<link.childNodes.length; i++) {// var node = link.childNodes[i];// if (isTextNode(node)) {// swapDOM(node, document.createTextNode(newText));// break;// }// }}functionautogrow(area){if(area.scrollHeight>area.clientHeight&&!window.opera){if(area.rows<20){area.rows+=2;}}}//============= page loading events ==========================================//functionroundedCornersOnLoad(){jQuery('div.sideBox').corner('bottom 6px');jQuery('div.boxTitle, div.boxPrefTitle, div.sideBoxTitle, th.month').corner('top 6px');}jQuery(document).ready(roundedCornersOnLoad);CubicWeb.provide('htmlhelpers.js');