dex.widget = { /** * Initializes a list object */ list :function (ul,scroll,allow_edit){ ul = document.getElementById(ul); var parent = ul.parentNode; ul.items = new Array; this.scroll = scroll; this.allow_edit = allow_edit; ul.add_row = function(li){ // If not given create new if (!li){ var li = document.createElement("li"); this.insertBefore(li,this.add); } li.is_todo = true; // add to pointer var a = dex.utils.getElementsByClass('todo',li); if (a){ li.a = a }else{ li.a = document.createElement("span"); li.appendChild(li.a); } li.a.onclick = function() { this.parentNode.edit(); return false; }; var remove = document.createElement("span"); remove.href = 'javascript://'; remove.className = "doremove"; remove.onclick = function() { this.parentNode.remove(); } li.insertBefore(remove,li.a); var add_url = document.createElement("span"); add_url.className = "doedit"; add_url.onclick = function() { this.parentNode.edit_url() } li.insertBefore(add_url,li.a); var strike = document.createElement("input"); strike.type = 'checkbox'; strike.className = "checkbox"; if (li.a.className.indexOf('strike')!=-1){ strike.checked = true; } strike.onclick = function() { var li_elm = this.parentNode; if (li_elm.a.className.indexOf('strike') !=-1 ) li_elm.a.className = 'todo'; else li_elm.a.className = 'todo strike'; li_elm.parentNode.save(); }; li.insertBefore(strike,li.a); li.remove = function() { var ul = this.parentNode; ul.removeChild(this) ul.items.splice(this.index,1) ul.save(); }; li.edit = function() { var text_val; text_val = document.createElement("input"); text_val.name = 'text_val'; text_val.type = 'text'; if (this.a){ text_val.value = this.a.innerHTML.replace('&', '&'); } this.a.style.display='none'; text_val.li = this; this.insertBefore(text_val,this.a) text_val.select(); text_val.focus(); // Update li text_val.onkeyup = function (e) { var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; if ((keycode == 13)) { var ul = this.li.parentNode; this.onblur(); var next = this.li.get_nextSibling(); if (next){ next.edit(); } else{ var row = ul.add_row() row.edit(); } } return false; }, text_val.onblur = function() { this.parentNode.save(this.value.trim()) this.parentNode.removeChild(this); return false; } }; li.edit_url = function() { var url_val = document.createElement("input"); url_val.name = 'url_val'; url_val.type = 'text'; if (this.a && this.a.href){ url_val.value = decodeURIComponent(this.a.href); } else { url_val.value = 'http://' } url_val.li = this; this.insertBefore(url_val,this.a.nextSibling); url_val.select(); // Update li url_val.onkeyup = function (e) { var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; if ((keycode == 13)) { var ul = this.li.parentNode; this.onblur(); var next = this.li.get_nextSibling(); if (next){ next.edit(); } else{ var row = ul.add_row(); row.edit(); } } return false; }, url_val.onblur = function() { this.parentNode.save_url(this.value); this.parentNode.removeChild(this); return false; }; }; li.save = function(value) { var ul = this.parentNode; if (!this.a){ this.a = document.createElement("a"); this.appendChild(this.a); } // Check value if (value){ this.a.innerHTML = value; this.a.style.display = 'inline'; } // remove node else { this.remove(); } ul.save(); return false; }; li.save_url = function(url) { if (url == 'http://') return false; var ul = this.parentNode; // Create A element if (this.a.tagName.toLowerCase() != 'a'){ var new_a = document.createElement("a"); new_a.innerHTML = this.a.innerHTML; this.replaceChild(new_a,this.a); // delete this.a; // this.a.parentNode.removeChild(this.a); this.a = new_a; } // Remove A element else if (!url.trim()){ var new_a = document.createElement("span"); new_a.innerHTML = this.a.innerHTML; this.replaceChild(new_a,this.a); this.a = new_a; } this.a.href = url; ul.save(); return false; }; li.get_nextSibling = function() { var next,i; next = this; while (next = next.nextSibling) { if (next.is_todo ) return next; } return false; }; return li; } ul.save = function () { var raw = this.getElementsByTagName('LI'); var items = new Array(); for (var i=0,k=0,j=raw.length;i this.data.length) { this.limit = this.data.length-1; } // Build from template var html = '', i , len; if (this.scroll){ html+=''; } if (this.meta_template_obj && this.data) { var meta_template = new dex.template(this.meta_template_obj) html+= meta_template.render(this.data); } if (this.template_obj && this.data && this.data.item){ var template = new dex.template(this.template_obj) html+='
'; for (i =0; i2){ html+= ' style="float:left;clear:none"'; } html+= '>'; if (this.data.item[i].media_thumbnail) { html+=''; } html+= ''+this.data.item[i].title+''; if (this.description > 0) { html+= '

'+this.data.item[i].description+'

'; } html+= '' } html+=''; } if (this.scroll){ html+='
'; } var pointer = document.getElementById(divid); pointer.innerHTML = html; } // if (dex.page) dex.page.fix(); }, scope: this } dex.css.overlay_ajaxon(document.getElementById(this.divid)); YAHOO.util.Connect.asyncRequest('GET', this.proxy, callback); } } dex.template = function(template){ this.template = document.getElementById(template).innerHTML; this.match = this.template.match(new RegExp("/null/([^#]*)#", 'gi')); this.render = function(data){ var var_name, i, value; var buffer = this.template; if (this.match) { for (i=0 ; this.match[i] ; i++){ var_name = this.match[i].replace(new RegExp("/null/", 'gi'),''); var_name = var_name.replace(new RegExp("#", 'gi'),''); try{ if (value = eval("data."+var_name)) buffer = buffer.replace(new RegExp(this.match[i], 'gi'), value); else buffer = buffer.replace(new RegExp(this.match[i], 'gi'), ''); } catch(e) { buffer = buffer.replace(new RegExp(this.match[i], 'gi'), ''); } } } return buffer; } } YAHOO.register("dex.widget", dex.forms, { version: "1", build: "1" });