PluginProbe
WPIDE – File Manager & Code Editor / 2.0.14
WPIDE – File Manager & Code Editor v2.0.14
3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 3.4 All 54 releases
wpide / js / load-editor.js

load-editor.js in WPIDE – File Manager & Code Editor 2.0.14, at js/load-editor.js

798 lines 23.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var autocompleting = false;
2 var autocompletelength = 2;
3 var editor = '';
4
5 var saved_editor_sessions = [];
6 var saved_undo_manager = [];
7 var last_added_editor_session = 0;
8 var current_editor_session = 0;
9
10 var EditSession = require('ace/edit_session').EditSession;
11 var UndoManager = require('ace/undomanager').UndoManager;
12 var Search = require("ace/search").Search;
13 var TokenIterator = require("ace/token_iterator").TokenIterator;
14
15 var oHandler;
16
17 function onSessionChange(e) {
18
19 if( editor.getSession().enable_autocomplete === false){
20 return;
21 }
22
23 //don't continue with autocomplete if /n entered
24 try {
25 if ( e.data.text.charCodeAt(0) === 10 ){
26 return;
27 }
28 }catch(error){}
29
30 try {
31 if ( e.data.action == 'removeText' ){
32
33 if (autocompleting) {
34 autocompletelength = (autocompletelength - 1) ;
35 }else{
36 return;
37 }
38 }
39 }catch(error){}
40
41
42 //get current cursor position
43 range = editor.getSelectionRange();
44 //take note of selection row to compare with search
45 cursor_row = range.start.row;
46
47 try{
48 //quit autocomplete if we are writing a "string"
49 var iterator = new TokenIterator(editor.getSession(), range.start.row, range.start.column);
50 var current_token_type = iterator.getCurrentToken().type;
51 if(current_token_type == "string" || current_token_type == "comment"){
52 return;
53 }
54 }catch(error){}
55
56 if (range.start.column > 0){
57
58 //search for command text user has entered that we need to try match functions against
59 var search = new Search().set({
60 needle: "[\\n \.\)\(]",
61 backwards: true,
62 wrap: false,
63 caseSensitive: false,
64 wholeWord: false,
65 regExp: true
66 });
67 //console.log(search.find(editor.getSession()));
68
69 range = search.find(editor.getSession());
70
71 if (range) range.start.column++;
72
73 }else{ //change this to look char position, if it's starting at 0 then do this
74
75 range.start.column = 0;
76 }
77
78 if (! range || range.start.row < cursor_row ){
79 //forse the autocomplete check on this row starting at column 0
80 range = editor.getSelectionRange();
81 range.start.column = 0;
82 }
83
84
85 //console.log("search result - start row " + range.start.row + "-" + range.end.row + ", column " + range.start.column+ "-" + range.end.column);
86 //console.log(editor.getSelection().getRange());
87
88 range.end.column = editor.getSession().getSelection().getCursor().column +1;//set end column as cursor pos
89
90 //console.log("[ \.] based: " + editor.getSession().doc.getTextRange(range));
91
92 //no column lower than 1 thanks
93 if (range.start.column < 1) {
94 range.start.column = 0;
95 }
96
97 //console.log("after row " + range.start.row + "-" + range.end.row + ", column " + range.start.column+ "-" + range.end.column);
98 //get the editor text based on that range
99 var text = editor.getSession().doc.getTextRange(range);
100 $quit_onchange = false;
101
102 //console.log(text);
103
104 //console.log("Searching for text \""+text+"\" length: "+ text.length);
105 if (text.length < 3){
106
107 wpide_close_autocomplete();
108 return;
109 }
110
111 autocompletelength = text.length;
112
113 //create the dropdown for autocomplete
114 var sel = editor.getSelection();
115 var session = editor.getSession();
116 var lead = sel.getSelectionLead();
117
118 var pos = editor.renderer.textToScreenCoordinates(lead.row, lead.column);
119 var ac = document.getElementById('ac'); // #ac is auto complete html select element
120
121
122
123 if( typeof ac !== 'undefined' ){
124
125 //add editor click listener
126 //editor clicks should hide the autocomplete dropdown
127 editor.container.addEventListener('click', function(e){
128
129 wpide_close_autocomplete();
130
131 autocompleting=false;
132 autocompletelength = 2;
133
134 }, false);
135
136 } //end - create initial autocomplete dropdown and related actions
137
138
139 //calulate the editor container offset
140 var obj=editor.container;
141
142 var curleft = 0;
143 var curtop = 0;
144
145 if (obj.offsetParent) {
146
147 do {
148 curleft += obj.offsetLeft;
149 curtop += obj.offsetTop;
150 } while (obj = obj.offsetParent);
151
152 }
153
154
155 //position autocomplete
156 ac.style.top= ((pos.pageY - curtop)+20) + "px";
157 ac.style.left= ((pos.pageX - curleft)+10) + "px";
158 ac.style.display='block';
159 ac.style.background='white';
160
161
162 //remove all options, starting a fresh list
163 ac.options.length = 0;
164
165
166 //loop through WP tags and check for a match
167 if (autocomplete_wordpress){
168 var tag;
169 for(i in autocomplete_wordpress) {
170 //if(!html_tags.hasOwnProperty(i) ){
171 // continue;
172 //}
173
174 tag= i;
175 //see if the tag is a match
176 if( text !== tag.substr(0,text.length) ){
177 continue;
178 }
179
180 //add parentheses
181 tag = tag + "()";
182
183 var option = document.createElement('option');
184 option.text = tag;
185 option.value = tag;
186 option.setAttribute('title', wpide_app_path + 'images/wpac.png');//path to icon image or wpac.png
187
188
189 try {
190 ac.add(option, null); // standards compliant; doesn't work in IE
191 }
192 catch(ex) {
193 ac.add(option); // IE only
194 }
195
196 }//end for
197 }//end php autocomplete
198
199 //loop through PHP tags and check for a match
200 if (autocomplete_php){
201 var tag;
202 for(i in autocomplete_php) {
203 //if(!html_tags.hasOwnProperty(i) ){
204 // continue;
205 //}
206
207 tag= i;
208 //see if the tag is a match
209 if( text !== tag.substr(0,text.length) ){
210 continue;
211 }
212
213 //add parentheses
214 tag = tag + "()";
215
216 var option = document.createElement('option');
217 option.text = tag;
218 option.value = tag;
219 option.setAttribute('title', wpide_app_path + 'images/phpac.png');//path to icon image or wpac.png
220
221 try {
222 ac.add(option, null); // standards compliant; doesn't work in IE
223 }
224 catch(ex) {
225 ac.add(option); // IE only
226 }
227
228
229 }//end for
230 }//end php autocomplete
231
232
233 //check for matches
234 if ( ac.length === 0 ) {
235 wpide_close_autocomplete();
236 } else {
237
238 ac.selectedIndex=0;
239 autocompleting=true;
240 oHandler = jQuery("#ac").msDropDown({visibleRows:10, rowHeight:20}).data("dd");
241
242 jQuery("#ac_child").click(function(item){
243 //get the link node and pass to select AC item function
244 if (typeof item.srcElement != 'undefined'){
245 var link_node = item.srcElement; //works on chrome
246 }else{
247 var link_node = item.target; //works on Firefox etc
248 }
249
250 selectACitem(link_node);
251 });
252
253 jQuery("#ac_child a").mouseover(function(item){
254 //show the code in the info panel
255
256 //get the link ID
257 if (typeof item.srcElement != 'undefined'){
258 var link_id = item.srcElement.id; //works on chrome
259 }else{
260 var link_id = item.target.id; //works on Firefox etc
261 }
262
263 if (link_id == '') return; //if the link doesn't have an id it's not valid so just stop
264
265
266 //if this command item is enabled
267 if (jQuery("#"+link_id).hasClass("enabled")){
268
269 var selected_item_index = jQuery("#"+link_id).index();
270
271 if (selected_item_index > -1){ //if select item is valid
272
273 //set the selected menu item
274 oHandler.selectedIndex(selected_item_index);
275 //show command help panel for this command
276 wpide_function_help();
277
278 }
279 }
280
281 });
282
283
284 jQuery("#ac_child").css("z-index", "9999");
285 jQuery("#ac_child").css("background-color", "#ffffff");
286 jQuery("#ac_msdd").css("z-index", "9999");
287 jQuery("#ac_msdd").css("position", "absolute");
288 jQuery("#ac_msdd").css("top", ac.style.top);
289 jQuery("#ac_msdd").css("left", ac.style.left);
290
291 //show command help panel for this command
292 wpide_function_help();
293
294 }
295
296 }
297
298 function token_test(){
299
300 var iterator = new TokenIterator(editor.getSession(), range.start.row, range.start.column);
301 var current_token_type = iterator.getCurrentToken().type;
302 return iterator.getCurrentToken();
303 }
304
305 function wpide_close_autocomplete(){
306 if (typeof document.getElementById('ac') != 'undefined') document.getElementById('ac').style.display='none';
307 if (typeof oHandler != 'undefined') oHandler.close();
308
309 autocompleting = false;
310
311 //clear the text in the command help panel
312 //jQuery("#wpide_info_content").html("");
313 }
314
315 function selectionChanged(e) {
316 var selected_text = editor.getSession().doc.getTextRange(editor.getSelectionRange());
317
318 //check for hex colour match
319 if ( selected_text.match('^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$') != null ){
320
321 var therange = editor.getSelectionRange();
322 therange.end.column = therange.start.column;
323 therange.start.column = therange.start.column-1;
324
325 // only show color assist if the character before the selection indicates a hex color (#)
326 if ( editor.getSession().doc.getTextRange( therange ) == "#" ){
327 jQuery("#wpide_color_assist").show();
328 }
329
330 }
331 }
332
333 function wpide_function_help() {
334 //mouse over
335
336 try
337 {
338 var selected_command_item = jQuery("#ac_child a.selected");
339
340
341 key = selected_command_item.find("span.ddTitleText").text().replace("()","");
342
343 //wordpress autocomplete
344 if ( selected_command_item.find("img").attr("src").indexOf("wpac.png") >= 0){
345
346 if (autocomplete_wordpress[key].desc != undefined){
347
348 //compose the param info
349 var param_text ="";
350 for(i=0; i<autocomplete_wordpress[key].params.length; i++) {
351
352 //wrap params in a span to highlight not required
353 if (autocomplete_wordpress[key].params[i].required == "no"){
354 param_text = param_text + "<span class='wpide_func_arg_notrequired'>" + autocomplete_wordpress[key].params[i]['param'] + "<em>optional</em></span><br /> <br />";
355 }else{
356 param_text = param_text + autocomplete_wordpress[key].params[i]['param'] + "<br /> <br />";
357 }
358
359 }
360 //compose returns text
361 if (autocomplete_wordpress[key].returns.length > 0){
362 returns_text = "<br /><br /><strong>Returns:</strong> " + autocomplete_wordpress[key].returns;
363 }else{
364 returns_text = "";
365 }
366
367
368 //output command info
369 jQuery("#wpide_info_content").html(
370 "<strong class='wpide_func_highlight_black'>Function: </strong><strong class='wpide_func_highlight'>" + key + "(</strong><br />" +
371 "<span class='wpide_func_desc'>" + autocomplete_wordpress[key].desc + "</span><br /><br /><em class='wpide_func_params'>" +
372 param_text + "</em>"+
373 "<strong class='wpide_func_highlight'>)</strong> " +
374 returns_text +
375 "<p><a href='http://codex.wordpress.org/Function_Reference/" + key + "' target='_blank'>See " + key + "() in the WordPress codex</a></p>"
376 );
377 }
378
379 }
380
381 //php autocomplete
382 if ( selected_command_item.find("img").attr("src").indexOf("phpac.png") >= 0){
383
384 if (autocomplete_php[key].returns != undefined){
385
386 //params text
387 var param_text ="";
388 for(i=0; i<autocomplete_php[key].params.length; i++) {
389
390 //wrap params in a span to highlight not required
391 if (autocomplete_php[key].params[i].required == "no"){
392 param_text = param_text + "<span class='wpide_func_arg_notrequired'>" + autocomplete_php[key].params[i]['param'] + "<em>optional</em></span><br /> <br />";
393 }else{
394 param_text = param_text + autocomplete_php[key].params[i]['param'] + "<br /> <br />";
395 }
396
397 }
398 //compose returns text
399 if (autocomplete_php[key].returns.length > 0){
400 returns_text = "<br /><br /><strong>Returns:</strong> " + autocomplete_php[key].returns;
401 }else{
402 returns_text = "";
403 }
404
405 jQuery("#wpide_info_content").html(
406 "<strong class='wpide_func_highlight_black'>Function: </strong><strong class='wpide_func_highlight'>" + key + "(</strong><br />" +
407 autocomplete_php[key].desc + "<br /><br /><em class='wpide_func_params'>" +
408 param_text + "</em>" +
409 "<strong class='wpide_func_highlight'>)</strong>" +
410 returns_text +
411 "<p><a href='http://php.net/manual/en/function." + key.replace(/_/g, "-") + ".php' target='_blank'>See " + key + "() in the PHP manual</a></p>"
412 );
413
414 }
415
416 }
417
418
419
420 }
421 catch(err)
422 {
423 //Handle errors here
424 }
425
426 }
427
428 //open another file and add to editor
429 function wpide_set_file_contents(file, callback_func){
430 "use strict";
431
432 //ajax call to get file contents we are about to edit
433 var data = { action: 'wpide_get_file', filename: file, _wpnonce: jQuery('#_wpnonce').val(), _wp_http_referer: jQuery('#_wp_http_referer').val() };
434
435 jQuery.post(ajaxurl, data, function(response) {
436 var the_path = file.replace(/^.*[\\\/]/, '');
437 var the_id = "wpide_tab_" + last_added_editor_session;
438
439 //enable editor now we have a file open
440 jQuery('#fancyeditordiv textarea').removeAttr("disabled");
441
442 jQuery("#wpide_toolbar_tabs").append('<span id="'+the_id+'" sessionrel="'+last_added_editor_session+'" title=" '+file+' " rel="'+file+'" class="wpide_tab">'+ the_path +'</a> <a class="close_tab" href="#">x</a> ');
443
444 saved_editor_sessions[last_added_editor_session] = new EditSession(response);//set saved session
445 saved_editor_sessions[last_added_editor_session].on('change', onSessionChange);
446 saved_undo_manager[last_added_editor_session] = new UndoManager(editor.getSession().getUndoManager());//new undo manager for this session
447
448 last_added_editor_session++; //increment session counter
449
450 //add click event for the new tab.
451 //We are actually clearing the click event and adding it again for all tab elements, it's the only way I could get the click handler listening on all dynamically added tabs
452 jQuery(".wpide_tab").off('click').on("click", function(event){
453 event.preventDefault();
454
455 jQuery('input[name=filename]').val( jQuery(this).attr('rel') );
456
457 //save current editor into session
458 //get old editor out of session and apply to editor
459 var clicksesh = jQuery(this).attr('sessionrel'); //editor id number
460 saved_editor_sessions[ clicksesh ].setUndoManager(saved_undo_manager[ clicksesh ]);
461 editor.setSession( saved_editor_sessions[ clicksesh ] );
462
463 //set this tab as active
464 jQuery(".wpide_tab").removeClass('active');
465 jQuery(this).addClass('active');
466
467 var currentFilename = jQuery(this).attr('rel');
468 var mode;
469
470 //turn autocomplete off initially, then enable as needed
471 editor.getSession().enable_autocomplete = false;
472
473 //set the editor mode based on file name
474 if (/\.css$/.test(currentFilename)) {
475 mode = require("ace/mode/css").Mode;
476 }
477 else if (/\.less$/.test(currentFilename)) {
478 mode = require("ace/mode/css").Mode;
479 }
480 else if (/\.js$/.test(currentFilename)) {
481 mode = require("ace/mode/javascript").Mode;
482 }
483 else {
484 mode = require("ace/mode/php").Mode; //default to php
485 //only enable session change / auto complete if needed
486 editor.getSession().enable_autocomplete = true;
487 }
488 editor.getSession().setMode(new mode());
489
490 editor.getSession().on('change', onSessionChange);
491
492 editor.getSession().selection.on('changeSelection', selectionChanged);
493
494 editor.resize();
495 editor.focus();
496 //make a note of current editor
497 current_editor_session = clicksesh;
498
499 });
500
501 //add click event for tab close.
502 //We are actually clearing the click event and adding it again for all tab elements, it's the only way I could get the click handler listening on all dynamically added tabs
503 jQuery(".close_tab").off('click').on("click", function(event){
504 event.preventDefault();
505 var clicksesh = jQuery(this).parent().attr('sessionrel');
506 var activeFallback;
507
508 //if the currently selected tab is being removed then remember to make the first tab active
509 if ( jQuery("#wpide_tab_"+clicksesh).hasClass('active') ) {
510 activeFallback = true;
511 }else{
512 activeFallback = false;
513 }
514
515 //remove tab
516 jQuery(this).parent().remove();
517
518 //clear session and undo
519 saved_undo_manager[clicksesh] = undefined;
520 saved_editor_sessions[clicksesh] = undefined;
521
522 //Clear the active editor if all tabs closed or activate first tab if required since the active tab may have been deleted
523 if (jQuery(".wpide_tab").length == 0){
524 editor.getSession().setValue( "" );
525 }else if ( activeFallback ){
526 jQuery( "#" + jQuery(".wpide_tab")[0].id ).click();
527 }
528
529 });
530
531 jQuery("#"+the_id).click();
532
533 if (callback_func != null) {
534 callback_func(response);
535 }
536
537 });
538
539
540 }
541
542 function saveDocument() {
543 //ajax call to save the file and generate a backup if needed
544 var data = { action: 'wpide_save_file', filename: jQuery('input[name=filename]').val(), _wpnonce: jQuery('#_wpnonce').val(), _wp_http_referer: jQuery('#_wp_http_referer').val(), content: editor.getSession().getValue() };
545 jQuery.post(ajaxurl, data, function(response) {
546 if (response === 'success') {
547 jQuery("#wpide_message").html('<span>File saved.</span>');
548 jQuery("#wpide_message").show();
549 jQuery("#wpide_message").fadeOut(5000);
550 } else {
551 alert("error: " + response);
552 }
553 });
554 }
555
556 //enter/return command
557 function selectACitem (item) {
558 if( document.getElementById('ac').style.display === 'block' && oHandler.visible() == 'block' ){
559 var ac_dropdwn = document.getElementById('ac');
560 var tag = ac_dropdwn.options[ac_dropdwn.selectedIndex].value;
561 var sel = editor.selection.getRange();
562 var line = editor.getSession().getLine(sel.start.row);
563 sel.start.column = sel.start.column - autocompletelength;
564
565 if (item.length){
566 tag = item; //get tag from new msdropdown passed as arg
567 }else{
568 tag = jQuery("#ac_msdd a.selected").children("span.ddTitleText").text(); //get tag from new msdropdown
569 }
570
571 //clean up the tag/command
572 tag = tag.replace(")", ""); //remove end parenthesis
573
574 //console.log(tag);
575 editor.selection.setSelectionRange(sel);
576 editor.insert(tag);
577
578 wpide_close_autocomplete();
579 } else {
580 editor.insert('\n');
581 }
582 }
583
584
585 jQuery(document).ready(function($) {
586 $("#wpide_save").click(saveDocument);
587
588 // drag and drop colour picker image
589 $("#wpide_color_assist").on('drop', function(e) {
590 e.preventDefault();
591 e.originalEvent.dataTransfer.items[0].getAsString(function(url){
592
593 $(".ImageColorPickerCanvas", $("#side-info-column") ).remove();
594 $("img", $("#wpide_color_assist")).attr('src', url );
595
596 });
597 });
598
599 $("#wpide_color_assist").on('dragover', function(e) {
600 $(this).addClass("hover");
601 }).on('dragleave', function(e) {
602 $(this).removeClass("hover");
603 });
604
605
606 //add div for ace editor to latch on to
607 $('#template').prepend("<div style='width:80%;height:500px;margin-right:0!important;' id='fancyeditordiv'></div>");
608 //create the editor instance
609 editor = ace.edit("fancyeditordiv");
610 //turn off print margin
611 editor.setPrintMarginColumn(false);
612 //set the editor theme
613 editor.setTheme("ace/theme/dawn");
614 //get a copy of the initial file contents (the file being edited)
615 //var intialData = $('#newcontent').val()
616 var intialData = "Use the file manager to find a file you wish edit, click the file name to edit. \n\n";
617
618
619 //startup info - usefull for debugging
620 var data = { action: 'wpide_startup_check', _wpnonce: jQuery('#_wpnonce').val(), _wp_http_referer: jQuery('#_wp_http_referer').val() };
621
622 jQuery.post(ajaxurl, data, function(response) {
623 if (response == "-1"){
624 intialData = intialData + "Permission/security problem with ajax request. Refresh WPide and try again. \n\n";
625 }else{
626 intialData = intialData + response;
627 }
628
629 editor.getSession().setValue( intialData );
630
631 });
632
633
634
635 //make initial editor read only
636 $('#fancyeditordiv textarea').attr("disabled", "disabled");
637
638 //use editors php mode
639 var phpMode = require("ace/mode/php").Mode;
640 editor.getSession().setMode(new phpMode());
641
642 //START AUTOCOMPLETE
643 //create the autocomplete dropdown
644 var ac = document.createElement('select');
645 ac.id = 'ac';
646 ac.name = 'ac';
647 ac.style.position='absolute';
648 ac.style.zIndex=100;
649 ac.style.width='auto';
650 ac.style.display='none';
651 ac.style.height='auto';
652 ac.size=10;
653 editor.container.appendChild(ac);
654
655 //hook onto any change in editor contents
656 editor.getSession().on('change', onSessionChange);//end editor change event
657
658
659
660 //START COMMANDS
661
662 //Key up command
663 editor.commands.addCommand({
664 name: "up",
665 bindKey: {
666 win: "Up",
667 mac: "Up",
668 sender: "editor"
669 },
670
671 exec: function(env, args, request) {
672 if (oHandler && oHandler.visible() === 'block'){
673 oHandler.previous();
674
675 //show command help panel for this command
676 wpide_function_help();
677 //console.log("handler is visible");
678
679 }else if( document.getElementById('ac').style.display === 'block' ) {
680 var select=document.getElementById('ac');
681 if( select.selectedIndex === 0 ) {
682 select.selectedIndex = select.options.length-1;
683 } else {
684 select.selectedIndex = select.selectedIndex-1;
685 }
686 //console.log("ac is visible");
687 } else {
688 var range = editor.getSelectionRange();
689 editor.clearSelection();
690 editor.moveCursorTo(range.end.row - 1, range.end.column);
691 }
692 }
693 });
694
695
696 //key down command
697 editor.commands.addCommand({
698 name: "down",
699 bindKey: {
700 win: "Down",
701 mac: "Down",
702 sender: "editor"
703 },
704 exec: function(env, args, request) {
705
706 if (oHandler && oHandler.visible() === 'block'){
707 oHandler.next();
708
709 //show command help panel for this command
710 wpide_function_help();
711
712 }else if ( document.getElementById('ac').style.display === 'block' ) {
713 var select=document.getElementById('ac');
714 if ( select.selectedIndex === select.options.length-1 ) {
715 select.selectedIndex=0;
716 } else {
717 select.selectedIndex=select.selectedIndex+1;
718 }
719 } else {
720 var range = editor.getSelectionRange();
721 editor.clearSelection();
722 editor.moveCursorTo(range.end.row +1, range.end.column);
723 }
724 }
725 });
726
727
728
729 editor.commands.addCommand({
730 name: "enter",
731 bindKey: {
732 win: "Return",
733 mac: "Return",
734 sender: "editor"
735 },
736 exec: selectACitem
737 });
738
739 // save command:
740 editor.commands.addCommand({
741 name: "save",
742 bindKey: {
743 win: "Ctrl-S",
744 mac: "Command-S",
745 sender: "editor"
746 },
747 exec: saveDocument
748 });
749
750 //END COMMANDS
751
752
753 //click action for new directory/file submit link
754 $("#wpide_create_new_directory, #wpide_create_new_file").click(function(e){
755 e.preventDefault();
756
757 var data_input = jQuery(this).parent().find("input.has_data");
758 var item = eval('('+ data_input.attr("rel") +')');
759
760 //item.path file|directory
761 var data = { action: 'wpide_create_new', path: item.path, type: item.type, file: data_input.val(), _wpnonce: jQuery('#_wpnonce').val(), _wp_http_referer: jQuery('#_wp_http_referer').val() };
762
763 jQuery.post(ajaxurl, data, function(response) {
764
765 if (response == "1"){
766 //remove the file/dir name from the text input
767 data_input.val("");
768
769 if ( jQuery("ul.jqueryFileTree a[rel='"+ item.path +"']").length == 0){
770
771 //if no parent then we are adding something to the wp-content folder so regenerate the whole filetree
772 the_filetree();
773
774 }
775
776 //click the parent once to hide
777 jQuery("ul.jqueryFileTree a[rel='"+ item.path +"']").click();
778
779 //hide the parent input block
780 data_input.parent().hide();
781
782 //click the parent once again to show with new folder and focus on this area
783 jQuery("ul.jqueryFileTree a[rel='"+ item.path +"']").click();
784 jQuery("ul.jqueryFileTree a[rel='"+ item.path +"']").focus();
785
786 }else if (response == "-1"){
787 alert("Permission/security problem. Refresh WPide and try again.");
788 }else{
789 alert(response);
790 }
791
792
793 });
794
795 });
796
797 });//end jquery load
798