Add to bottom support in list manipulation. Props mdawaffe. fixes #2611
git-svn-id: https://develop.svn.wordpress.org/trunk@3669 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3f23e768fe
commit
928a9517ae
@ -2,7 +2,7 @@
|
|||||||
require_once('../wp-config.php');
|
require_once('../wp-config.php');
|
||||||
header('Content-type: text/javascript; charset=' . get_settings('blog_charset'), true);
|
header('Content-type: text/javascript; charset=' . get_settings('blog_charset'), true);
|
||||||
?>
|
?>
|
||||||
addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.clearInputs.push('newcat');});
|
addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.clearInputs.push('newcat');catList.topAdder=1;catList.alt=0});
|
||||||
addLoadEvent(newCatAddIn);
|
addLoadEvent(newCatAddIn);
|
||||||
function newCatAddIn() {
|
function newCatAddIn() {
|
||||||
if ( !document.getElementById('jaxcat') ) return false;
|
if ( !document.getElementById('jaxcat') ) return false;
|
||||||
|
@ -36,12 +36,9 @@ function WPAjax(file, responseEl){//class WPAjax extends sack
|
|||||||
function listMan(theListId){
|
function listMan(theListId){
|
||||||
this.theList=null;
|
this.theList=null;
|
||||||
this.ajaxRespEl=null;
|
this.ajaxRespEl=null;
|
||||||
this.inputData='';
|
this.inputData='';this.clearInputs=new Array();
|
||||||
this.clearInputs=new Array();
|
this.topAdder=0;this.alt='alternate';this.recolorPos;this.reg_color='#FFFFFF';this.alt_color='#F1F1F1';
|
||||||
var reg_color='#FFFFFF';
|
var listType;var listItems;
|
||||||
var alt_color='#F1F1F1';
|
|
||||||
var listItems;
|
|
||||||
var listType;
|
|
||||||
self.aTrap=0;
|
self.aTrap=0;
|
||||||
|
|
||||||
this.ajaxAdder=function(what,where,onComplete,update){//for TR, server must wrap TR in TABLE TBODY. this.makeEl cleans it
|
this.ajaxAdder=function(what,where,onComplete,update){//for TR, server must wrap TR in TABLE TBODY. this.makeEl cleans it
|
||||||
@ -53,15 +50,17 @@ function listMan(theListId){
|
|||||||
this.ajaxAdd.onCompletion=function(){
|
this.ajaxAdd.onCompletion=function(){
|
||||||
if(!this.parseAjaxResponseXML())return;
|
if(!this.parseAjaxResponseXML())return;
|
||||||
var newItems=this.responseXML.getElementsByTagName(what);
|
var newItems=this.responseXML.getElementsByTagName(what);
|
||||||
|
if(tempObj.topAdder)tempObj.recolorPos=0;
|
||||||
if(newItems){for (c=0;c<newItems.length;c++){
|
if(newItems){for (c=0;c<newItems.length;c++){
|
||||||
var id=parseInt(getNodeValue(newItems[c],'id'),10);
|
var id=parseInt(getNodeValue(newItems[c],'id'),10);
|
||||||
var exists=document.getElementById(what+'-'+id);
|
var exists=document.getElementById(what+'-'+id);
|
||||||
if(exists)tempObj.replaceListItem(exists.id,getNodeValue(newItems[c],'newitem'),update);
|
if(exists)tempObj.replaceListItem(exists.id,getNodeValue(newItems[c],'newitem'),newItems.length,update);
|
||||||
else tempObj.addListItem(getNodeValue(newItems[c],'newitem'));
|
else tempObj.addListItem(getNodeValue(newItems[c],'newitem'),newItems.length);
|
||||||
}}
|
}}
|
||||||
this.myResponseElement.innerHTML='';tempObj.inputData='';
|
this.myResponseElement.innerHTML='';tempObj.inputData='';
|
||||||
for(var i=0;i<tempObj.clearInputs.length;i++){try{var theI=document.getElementById(tempObj.clearInputs[i]);if(theI.tagName.match(/select/i))theI.selectedIndex=0;else theI.value='';}catch(e){}}
|
for(var i=0;i<tempObj.clearInputs.length;i++){try{var theI=document.getElementById(tempObj.clearInputs[i]);if(theI.tagName.match(/select/i))theI.selectedIndex=0;else theI.value='';}catch(e){}}
|
||||||
if(onComplete&&typeof onComplete=='function')onComplete();
|
if(onComplete&&typeof onComplete=='function')onComplete();
|
||||||
|
tempObj.recolorList(tempObj.recolorPos,1000)
|
||||||
}
|
}
|
||||||
this.ajaxAdd.runAJAX('action='+(update?'update-':'add-')+what+this.inputData);
|
this.ajaxAdd.runAJAX('action='+(update?'update-':'add-')+what+this.inputData);
|
||||||
return false;
|
return false;
|
||||||
@ -72,7 +71,7 @@ function listMan(theListId){
|
|||||||
this.ajaxDel=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');
|
this.ajaxDel=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');
|
||||||
if(this.ajaxDel.failed)return true;
|
if(this.ajaxDel.failed)return true;
|
||||||
var tempObj=this;
|
var tempObj=this;
|
||||||
this.ajaxDel.onCompletion=function(){if(this.parseAjaxResponse()){tempObj.removeListItem(what.replace('-as-spam','')+'-'+id,tempObj);this.myResponseElement.innerHTML='';if(onComplete&&typeof onComplete=='function')onComplete();}};
|
this.ajaxDel.onCompletion=function(){if(this.parseAjaxResponse()){tempObj.removeListItem(what.replace('-as-spam','')+'-'+id);this.myResponseElement.innerHTML='';if(onComplete&&typeof onComplete=='function')onComplete();tempObj.recolorList(tempObj.recolorPos,1000)}};
|
||||||
this.ajaxDel.runAJAX('action=delete-'+what+'&id='+id);
|
this.ajaxDel.runAJAX('action=delete-'+what+'&id='+id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -86,28 +85,28 @@ function listMan(theListId){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.makeEl=function(h){var fakeItem=document.createElement('div');fakeItem.innerHTML=h;var r=fakeItem.firstChild;while(r.tagName.match(/(table|tbody)/i)){r=r.firstChild;}return r;}
|
this.makeEl=function(h){var fakeItem=document.createElement('div');fakeItem.innerHTML=h;var r=fakeItem.firstChild;while(r.tagName.match(/(table|tbody)/i)){r=r.firstChild;}return r;}
|
||||||
this.addListItem=function(h){
|
this.addListItem=function(h,tot){
|
||||||
newItem=this.makeEl(h);
|
newItem=this.makeEl(h);
|
||||||
var firstItem=this.theList.getElementsByTagName('table'==listType?'tr':'li')[0];
|
if(this.topAdder){var firstItem=this.theList.getElementsByTagName('table'==listType?'tr':'li')[0];listItems.unshift(newItem.id);this.recolorPos++}
|
||||||
|
else{listItems.push(newItem.id);this.recolorPos=listItems.length;}
|
||||||
|
if(this.alt&&!((tot-this.recolorPos)%2))newItem.className+=' '+this.alt;
|
||||||
if(firstItem)firstItem.parentNode.insertBefore(newItem,firstItem);
|
if(firstItem)firstItem.parentNode.insertBefore(newItem,firstItem);
|
||||||
else this.theList.appendChild(newItem);
|
else this.theList.appendChild(newItem);
|
||||||
listItems.unshift(newItem.id);
|
|
||||||
Fat.fade_element(newItem.id);
|
Fat.fade_element(newItem.id);
|
||||||
}
|
}
|
||||||
this.removeListItem=function(id,listObj,noFade){
|
this.removeListItem=function(id,noFade){
|
||||||
if(!listObj)listObj=this;
|
|
||||||
if(!noFade)Fat.fade_element(id,null,700,'#FF3333');
|
if(!noFade)Fat.fade_element(id,null,700,'#FF3333');
|
||||||
var theItem=document.getElementById(id);
|
var theItem=document.getElementById(id);
|
||||||
if(!noFade){var func=encloseFunc(function(a){a.parentNode.removeChild(a);},theItem);setTimeout(func,705);}
|
if(!noFade){var func=encloseFunc(function(a){a.parentNode.removeChild(a);},theItem);setTimeout(func,705);}
|
||||||
else{theItem.parentNode.removeChild(theItem);}
|
else{theItem.parentNode.removeChild(theItem);}
|
||||||
var pos=listObj.getListPos(id);
|
var pos=this.getListPos(id);
|
||||||
listItems.splice(pos,1);
|
listItems.splice(pos,1);
|
||||||
if(!noFade)listObj.recolorList(pos,1000);
|
|
||||||
}
|
}
|
||||||
this.replaceListItem=function(id,h,update){
|
this.replaceListItem=function(id,h,tot,update){
|
||||||
if(!update){this.removeListItem(id,false,true);this.addListItem(h);return;}
|
if(!update){this.removeListItem(id,true);this.addListItem(h,tot);return;}
|
||||||
var newItem=this.makeEl(h);
|
var newItem=this.makeEl(h);
|
||||||
var oldItem=document.getElementById(id);
|
var oldItem=document.getElementById(id);
|
||||||
|
var pos=this.getListPos(oldItem.id);if(this.alt&&!(pos%2))newItem.className+=' '+this.alt;
|
||||||
oldItem.parentNode.replaceChild(newItem,oldItem);
|
oldItem.parentNode.replaceChild(newItem,oldItem);
|
||||||
Fat.fade_element(newItem.id);
|
Fat.fade_element(newItem.id);
|
||||||
}
|
}
|
||||||
@ -131,21 +130,22 @@ function listMan(theListId){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.getListPos=function(id){for(var i=0;i<listItems.length;i++){if(id==listItems[i]){var pos=i;break;}}return pos;}
|
this.getListPos=function(id,n){for(var i=0;i<listItems.length;i++){if(id==listItems[i]){var pos=i;break;}}if(!n){if(pos<this.recolorPos)this.recolorPos=pos;}return pos;}
|
||||||
this.getListItems=function(){
|
this.getListItems=function(){
|
||||||
if(this.theList)return;
|
if(this.theList)return;
|
||||||
listItems=new Array();
|
listItems=new Array();
|
||||||
if(theListId){this.theList=document.getElementById(theListId);if(!this.theList)return false;}
|
if(theListId){this.theList=document.getElementById(theListId);if(!this.theList)return false;}
|
||||||
else{this.theList=document.getElementById('the-list');if(this.theList)theListId='the-list';}
|
else{this.theList=document.getElementById('the-list');if(this.theList)theListId='the-list';}
|
||||||
if(this.theList){
|
if(this.theList){
|
||||||
var items=this.theList.getElementsByTagName('tr');listType='table'
|
var items=this.theList.getElementsByTagName('tr');listType='table';
|
||||||
if(!items[0]){items=this.theList.getElementsByTagName('li');listType='list'}
|
if(!items[0]){items=this.theList.getElementsByTagName('li');listType='list';}
|
||||||
for(var i=0;i<items.length;i++){listItems.push(items[i].id);}
|
for(var i=0;i<items.length;i++){listItems.push(items[i].id);}
|
||||||
|
this.recolorPos=listItems.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.recolorList=function(pos,dur){
|
this.recolorList=function(pos,dur){
|
||||||
if(!pos)pos=0;
|
if(!this.alt)return;if(!pos)pos=0;this.recolorPos=listItems.length;
|
||||||
for(var i=pos;i<listItems.length;i++){var e=document.getElementById(listItems[i]);if(i%2)e.className=e.className.replace('alternate','fade-'+alt_color.slice(1));else e.className+=' alternate fade-'+reg_color.slice(1);e.style.backgroundColor='';}
|
for(var i=pos;i<listItems.length;i++){var e=document.getElementById(listItems[i]);if(i%2)e.className=e.className.replace(this.alt,'fade-'+this.alt_color.slice(1));else e.className+=' '+this.alt+' fade-'+this.reg_color.slice(1);e.style.backgroundColor='';}
|
||||||
Fat.fade_all(dur);
|
Fat.fade_all(dur);
|
||||||
var func=encloseFunc(function(l){for(var i=0;i<l.length;i++){var e=document.getElementById(l[i]);e.className=e.className.replace(/fade-[a-f0-9]{6}/i,'');}},listItems);
|
var func=encloseFunc(function(l){for(var i=0;i<l.length;i++){var e=document.getElementById(l[i]);e.className=e.className.replace(/fade-[a-f0-9]{6}/i,'');}},listItems);
|
||||||
setTimeout(func,dur+5);
|
setTimeout(func,dur+5);
|
||||||
|
Loading…
Reference in New Issue
Block a user