1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
<?php
require_once('admin.php');
header('Content-type: text/javascript; charset=' . get_settings('blog_charset'), true);
?>
var ajaxCat = new sack();
var newcat;
function newCatAddIn() {
if ( !document.getElementById('jaxcat') ) return false;
var ajaxcat = document.createElement('span');
ajaxcat.id = 'ajaxcat';
newcat = document.createElement('input');
newcat.type = 'text';
newcat.name = 'newcat';
newcat.id = 'newcat';
newcat.size = '16';
newcat.setAttribute('autocomplete', 'off');
newcat.onkeypress = ajaxNewCatKeyPress;
var newcatSub = document.createElement('input');
newcatSub.type = 'button';
newcatSub.name = 'Button';
newcatSub.id = 'catadd';
newcatSub.value = '<?php echo addslashes(__('Add')); ?>';
newcatSub.onclick = ajaxNewCat;
ajaxcat.appendChild(newcat);
ajaxcat.appendChild(newcatSub);
document.getElementById('jaxcat').appendChild(ajaxcat);
howto = document.createElement('span');
howto.innerHTML = '<?php echo addslashes(__('Separate multiple categories with commas.')); ?>';
howto.id = 'howto';
ajaxcat.appendChild(howto);
}
addLoadEvent(newCatAddIn);
function getResponseElement() {
var p = document.getElementById('ajaxcatresponse');
if (!p) {
p = document.createElement('span');
document.getElementById('jaxcat').appendChild(p);
p.id = 'ajaxcatresponse';
}
return p;
}
function newCatLoading() {
var p = getResponseElement();
p.innerHTML = '<?php echo addslashes(__('Sending Data...')); ?>';
}
function newCatLoaded() {
var p = getResponseElement();
p.innerHTML = '<?php echo addslashes(__('Data Sent...')); ?>';
}
function newCatInteractive() {
var p = getResponseElement();
p.innerHTML = '<?php echo addslashes(__('Processing Request...')); ?>';
}
function newCatCompletion() {
var p = getResponseElement();
var id = 0;
var ids = new Array();
var names = new Array();
ids = myPload( ajaxCat.response );
names = myPload( newcat.value );
for ( i = 0; i < ids.length; i++ ) {
id = ids[i].replace(/[\n\r]+/g, "");
if ( id == '-1' ) {
p.innerHTML = "<?php echo addslashes(__("You don't have permission to do that.")); ?>";
return;
}
if ( id == '0' ) {
p.innerHTML = "<?php echo addslashes(__('That category name is invalid. Try something else.')); ?>";
return;
}
var exists = document.getElementById('category-' + id);
if (exists) {
var moveIt = exists.parentNode;
var container = moveIt.parentNode;
container.removeChild(moveIt);
container.insertBefore(moveIt, container.firstChild);
moveIt.id = 'new-category-' + id;
exists.checked = 'checked';
var nowClass = moveIt.className;
moveIt.className = nowClass + ' fade';
Fat.fade_all();
moveIt.className = nowClass;
} else {
var catDiv = document.getElementById('categorychecklist');
var newLabel = document.createElement('label');
newLabel.setAttribute('for', 'category-' + id);
newLabel.id = 'new-category-' + id;
newLabel.className = 'selectit fade';
var newCheck = document.createElement('input');
newCheck.type = 'checkbox';
newCheck.value = id;
newCheck.name = 'post_category[]';
newCheck.id = 'category-' + id;
newLabel.appendChild(newCheck);
var newLabelText = document.createTextNode(' ' + names[i]);
newLabel.appendChild(newLabelText);
catDiv.insertBefore(newLabel, catDiv.firstChild);
newCheck.checked = 'checked';
Fat.fade_all();
newLabel.className = 'selectit';
}
newcat.value = '';
}
p.parentNode.removeChild(p);
// var id = parseInt(ajaxCat.response, 10);
}
function ajaxNewCatKeyPress(e) {
if (!e) {
if (window.event) {
e = window.event;
} else {
return;
}
}
if (e.keyCode == 13) {
ajaxNewCat();
e.returnValue = false;
e.cancelBubble = true;
return false;
}
}
function ajaxNewCat() {
var newcat = document.getElementById('newcat');
var split_cats = new Array(1);
var catString = '';
catString = ajaxCat.encVar('ajaxnewcat', newcat.value) + '&' + ajaxCat.encVar('cookie', document.cookie);
ajaxCat.requestFile = 'edit-form-ajax-cat.php';
ajaxCat.method = 'POST';
ajaxCat.onLoading = newCatLoading;
ajaxCat.onLoaded = newCatLoaded;
ajaxCat.onInteractive = newCatInteractive;
ajaxCat.onCompletion = newCatCompletion;
ajaxCat.runAJAX(catString);
}
function myPload( str ) {
var fixedExplode = new Array();
var comma = new String(',');
var count = 0;
var currentElement = '';
for( x=0; x < str.length; x++) {
andy = str.charAt(x);
if ( comma.indexOf(andy) != -1 ) {
currentElement = currentElement.replace(new RegExp('^\\s*(.*?)\\s*$', ''), '$1'); // trim
fixedExplode[count] = currentElement;
currentElement = "";
count++;
} else {
currentElement += andy;
}
}
if ( currentElement != "" )
fixedExplode[count] = currentElement;
return fixedExplode;
}
|