themes/enanium/js/inlinerename.js
changeset 921 a71de5e21423
child 955 de4f81abc5e3
equal deleted inserted replaced
920:4babf8545826 921:a71de5e21423
       
     1 function ajaxRenameInline()
       
     2 {
       
     3   if ( KILL_SWITCH || IE )
       
     4     return false;
       
     5   // This trick is _so_ vBulletin...
       
     6   elem = document.getElementById('h2PageName');
       
     7   if(!elem) return;
       
     8   elem.style.display = 'none';
       
     9   name = elem.firstChild.nodeValue;
       
    10   textbox = document.createElement('input');
       
    11   textbox.type = 'text';
       
    12   textbox.value = name;
       
    13   textbox.id = 'pageheading';
       
    14   textbox.size = name.length + 7;
       
    15   textbox.onkeyup = function(e) { if(!e) return; if(e.keyCode == 13) ajaxRenameInlineSave(); if(e.keyCode == 27) ajaxRenameInlineCancel(); };
       
    16   textbox.oldname = name;
       
    17   elem.parentNode.insertBefore(textbox, elem);
       
    18   document.onclick = ajaxRenameInlineCancel;
       
    19   
       
    20   load_component(['l10n', 'fadefilter', 'messagebox']);
       
    21   textbox.focus();
       
    22   textbox.select();
       
    23 }
       
    24 
       
    25 function ajaxRenameInlineSave()
       
    26 {
       
    27   elem1 = document.getElementById('h2PageName');
       
    28   elem2 = document.getElementById('pageheading');
       
    29   if(!elem1 || !elem2) return;
       
    30   value = elem2.value;
       
    31   elem2.parentNode.removeChild(elem2); // just destroy the thing
       
    32   elem1.removeChild(elem1.firstChild);
       
    33   elem1.appendChild(document.createTextNode(value));
       
    34   elem1.style.display = 'block';
       
    35   if(!value || value=='' || value==elem2.oldname) return;
       
    36   setAjaxLoading();
       
    37   ajaxPost(stdAjaxPrefix+'&_mode=rename', 'newtitle='+ajaxEscape(value), function() {
       
    38     if ( ajax.readyState == 4 )
       
    39     {
       
    40       unsetAjaxLoading();
       
    41       var response = String(ajax.responseText);
       
    42       if ( !check_json_response(response) )
       
    43       {
       
    44         handle_invalid_json(response);
       
    45         return false;
       
    46       }
       
    47       response = parseJSON(response);
       
    48       if ( response.success )
       
    49       {
       
    50         new MessageBox( MB_OK|MB_ICONINFORMATION, $lang.get('ajax_rename_success_title'), $lang.get('ajax_rename_success_body', { page_name_new: value }) );
       
    51       }
       
    52       else
       
    53       {
       
    54         alert(response.error);
       
    55       }
       
    56     }
       
    57   });
       
    58 }
       
    59 
       
    60 function ajaxRenameInlineCancel(e)
       
    61 {
       
    62   if ( typeof(e) != 'object' && IE )
       
    63     e = window.event;
       
    64   elem1 = document.getElementById('h2PageName');
       
    65   elem2 = document.getElementById('pageheading');
       
    66   if(!elem1 || !elem2) return;
       
    67   if ( typeof(e) == 'object' && e.target )
       
    68   {
       
    69     if(e.target == elem2)
       
    70       return;
       
    71   }
       
    72   //value = elem2.value;
       
    73   elem2.parentNode.removeChild(elem2); // just destroy the thing
       
    74   //elem1.innerHTML = value;
       
    75   elem1.style.display = 'block';
       
    76   document.onclick = null;
       
    77 }
       
    78 
       
    79 addOnloadHook(function()
       
    80   {
       
    81     var h2 = document.getElementById('h2PageName');
       
    82     if ( h2 )
       
    83     {
       
    84       h2.ondblclick = function()
       
    85       {
       
    86         ajaxRenameInline();
       
    87       }
       
    88     }
       
    89   });