root/branches/2.0/wp-admin/cat-js.php

Revision 3737, 4.7 kB (checked in by ryan, 2 years ago)

Ref checks. Comment filter.

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