Changeset 62 for branches

Show
Ignore:
Timestamp:
02/28/09 17:10:12 (3 years ago)
Author:
daris
Message:

ajax post edit: extension is using jquery now

Location:
branches/ajax_post_edit
Files:
4 added
3 modified

Legend:

Unmodified
Added
Removed
  • branches/ajax_post_edit/ajax_post_edit.js

    r54 r62  
    77/**********************************************************/ 
    88 
    9 // Detect Internet Explorer 
    10 var ie = /msie/i.test (navigator.userAgent); 
    119 
    1210/* 
     
    1614{ 
    1715        // checking if link 'Quick Edit' exists, if not exists user probably typed on adress bar javascript:ape_quick_edit(id) 
    18         if ($('edit' + id)) 
     16        if ($('#edit' + id)) 
    1917        { 
    2018                // if other post is editing, cancel edit 
     
    3432                        ape_hide_menu(); 
    3533                        ape_id = id; 
    36                         ape_temp_post = $('post' + ape_id).innerHTML; 
    37                         ape_show_loading_info(); 
    38  
    39                         sendRequest('action=get&id=' + ape_id + '&csrf_token=' + ape['crsf_token'], function() {ape_on_ready_get_post()}); 
     34                        ape_temp_post = $('#post' + ape_id).html(); 
     35                         
     36                        // Show loading info 
     37                        $('#post' + ape_id).html($('#post' + ape_id).html() + '<div style="float:right"><img src="' + base_url + '/extensions/ajax_post_edit/loading.gif"> ' + ape['Loading'] + '</div>'); 
     38 
     39                        var values = { 
     40                                action: 'get', 
     41                                id: ape_id, 
     42                                csrf_token: ape['csrf_token'] 
     43                        }; 
     44                        $.post(ape_url, values, function(data) {ape_on_ready_get_post(data)}); 
    4045                } 
    4146        } 
     
    4651        Function executed after receiving post data 
    4752*/ 
    48 function ape_on_ready_get_post() 
    49 { 
    50         var parsed_message = match(http.responseText, 'parsed_message'); 
     53function ape_on_ready_get_post(data) 
     54{ 
     55        var parsed_message = match(data, 'parsed_message'); 
    5156 
    5257        // If there aren't any errors 
    5358        if (parsed_message != '') 
    5459        { 
    55                 var entry_content_html = http.responseText.substring(0, http.responseText.indexOf('<!-- END FORM -->')); 
    56                 $('post' + ape_id).innerHTML = entry_content_html; 
    57  
    58                 $('postedit').style.height = textAreaHeight + 'px'; 
    59                 $('postedit').focus(); 
     60                var entry_content_html = data.substring(0, data.indexOf('<!-- END FORM -->')); 
     61                 
     62                 
     63                $('#post' + ape_id).fadeOut('fast', function() { 
     64                        $(this).html(entry_content_html); 
     65 
     66                        $('#postedit').height(textAreaHeight + 'px'); 
     67 
     68                        $('#post' + ape_id).fadeIn('fast', function() { $('#postedit').focus(); } ); 
     69                } ); 
     70 
    6071                return 1; 
    6172        } 
    6273 
    63         if (http.responseText.substring(0, 12) == 'csrf_confirm') 
    64         { 
    65                 response = http.responseText.split(':'); 
     74        if (data.substring(0, 12) == 'csrf_confirm') 
     75        { 
     76                response = data.split(':'); 
    6677                if (confirm(response[1])) 
    6778                { 
    68                         ape['crsf_token'] = response[2]; 
    69                         sendRequest('action=get&id=' + ape_id + '&csrf_token=' + response[2], function() {ape_on_ready_get_post()}); 
     79                        ape['csrf_token'] = response[2]; 
     80 
     81                        var values = { 
     82                                action: 'get', 
     83                                id: ape_id, 
     84                                csrf_token: response[2] 
     85                        }; 
     86                        $.post(ape_url, values, function(data) {ape_on_ready_get_post(data)}); 
    7087                } 
    7188        } 
    7289        else 
    73                 alert(http.responseText); 
     90                alert(data); 
    7491         
    75         $('post' + ape_id).innerHTML = ape_temp_post; 
     92        $('#post' + ape_id).html(ape_temp_post); 
    7693        id = -1; 
    7794} 
     
    83100function ape_update_post() 
    84101{ 
    85         ape_enable(false); 
    86  
    87         ape_update_url = 'action=update&id=' + ape_id + '&req_message=' + encodeURIComponent($('postedit').value) + '&utf=1'; 
    88         if ($('fldsilent')) 
    89                 ape_update_url += '&silent=' + ($('fldsilent').checked ? 1 : 0); 
    90  
    91         if ($('req_subject')) 
    92                 ape_update_url += '&req_subject=' + encodeURIComponent($('req_subject').value); 
    93          
    94         ape_update_url += '&csrf_token=' + ape['crsf_token']; 
    95  
    96         sendRequest(ape_update_url, function() {ape_on_ready_update_post()}); 
    97         ape_show_saving_info(); 
     102        $('#post_edit_form input, #post_edit_form textarea').attr('disabled', 'disabled'); 
     103 
     104        ape_update_values = { 
     105                action: 'update', 
     106                id: ape_id, 
     107                req_message: $('#postedit').val(), 
     108                csrf_token: ape['csrf_token'] 
     109        }; 
     110 
     111        if ($('#fldsilent')) 
     112                ape_update_values['silent'] = $('#fldsilent').attr('checked') ? 1 : 0; 
     113 
     114        if ($('#req_subject')) 
     115                ape_update_values['req_subject'] = $('req_subject').val; 
     116 
     117        $.post(ape_url, ape_update_values, function(data) {ape_on_ready_update_post(data)}); 
     118 
     119        // Show saving info 
     120        $('#edit_info').show(); 
    98121} 
    99122 
     
    102125        Function executed after receiving update request 
    103126*/ 
    104 function ape_on_ready_update_post() 
    105 { 
    106         var message = match(http.responseText, 'message'); 
     127function ape_on_ready_update_post(data) 
     128{ 
     129        var message = match(data, 'message'); 
    107130        if (message != '') 
    108131        { 
     
    110133                try 
    111134                { 
    112                         pun_quote_posts[ape_id] = $('postedit').value; 
     135                        pun_quote_posts[ape_id] = $('#postedit').val; 
    113136                } 
    114137                catch (e) {} 
    115138         
    116                 var last_edit = match(http.responseText, 'last_edit'); 
     139                var last_edit = match(data, 'last_edit'); 
    117140 
    118141                var sig = ''; 
     142                 
    119143                if (ape_temp_post.toLowerCase().indexOf('<div class="sig-content">') != -1) // if post has signature 
    120144                        sig = ape_temp_post.substring(ape_temp_post.toLowerCase().indexOf('<div class="sig-content">')); // get it 
    121                 $('post' + ape_id).innerHTML = message + last_edit + sig; // display post 
    122                 ape_id = -1; 
     145                 
     146                // display post 
     147                $('#post' + ape_id).fadeOut('fast', function() { 
     148                        $('#post' + ape_id).html(message + last_edit + sig); 
     149                        $('#post' + ape_id).fadeIn('fast'); 
     150                        ape_id = -1; 
     151                } );  
    123152                return 1; 
    124153        } 
    125154 
    126155 
    127         var error = match(http.responseText, 'error'); 
    128  
     156        var error = match(data, 'error'); 
    129157        // if message has errors 
    130158        if (error != '') 
    131159        { 
    132                 var cur_message = $('postedit').value; 
     160                var cur_message = $('#postedit').val(); 
    133161 
    134162                // if recently displayed errors 
    135                 if ($('edit-error')) 
     163                if (document.getElementById('edit-error')) 
    136164                { 
    137165                        error = error.substring(error.indexOf('>')+1); 
    138166                        error = error.substring(0, error.lastIndexOf('</')); 
    139                         $('edit-error').innerHTML = error; 
     167                        $('#edit-error').html(error); 
    140168                } 
    141169                else 
    142170                { 
    143                         if ($('fldsilent')) 
    144                                 var cur_silent = $('fldsilent').checked; 
    145  
    146                         var entry_content = $('post' + ape_id); // post element 
    147                         var html = entry_content.innerHTML; 
     171                        if ($('#fldsilent')) 
     172                                var cur_silent = $('#fldsilent').checked; 
     173 
     174                        var html = $('#post' + ape_id).html(); 
    148175                        var replace = html.substring(0, html.indexOf('<', 2)); 
    149176                        html = html.replace(replace, replace + error); 
    150                         entry_content.innerHTML = html; 
    151  
    152                         $('postedit').value = cur_message; 
    153                         if ($('fldsilent')) 
    154                                 $('fldsilent').checked = cur_silent; 
    155  
    156                 } 
    157                 ape_enable(true); 
    158                 ape_hide_saving_info(); 
     177                        $('#post' + ape_id).html(html); 
     178 
     179                        $('#postedit').val(cur_message); 
     180                        if ($('#fldsilent')) 
     181                                $('#fldsilent').attr('checked', cur_silent); 
     182 
     183                } 
     184                $('#post_edit_form input, #post_edit_form textarea').removeAttr('disabled'); 
     185                 
     186                // Hide saving info 
     187                $('#edit_info').hide(); 
    159188        } 
    160189        else 
    161190        { 
    162                 if (http.responseText.substring(0, 12) == 'csrf_confirm') 
    163                 { 
    164                         response = http.responseText.split(':'); 
     191                if (data.substring(0, 12) == 'csrf_confirm') 
     192                { 
     193                        response = data.split(':'); 
    165194                        if (confirm(response[1])) 
    166195                        { 
    167                                 ape['crsf_token'] = response[2]; 
    168                                 sendRequest(ape_update_url.substring(0, ape_update_url.indexOf('&csrf_token=') + 12) + response[2], function() {ape_on_ready_update_post()}); 
     196                                ape['csrf_token'] = response[2]; 
     197                                ape_update_values['csrf_token'] = response[2]; 
     198                                $.post(ape_url, ape_update_values, function(data) {ape_on_ready_update_post(data)}); 
    169199                        } 
    170200                        else 
    171201                        { 
    172                                 ape_enable(true); 
    173                                 ape_hide_saving_info(); 
     202                                $('#post_edit_form input, #post_edit_form textarea').removeAttr('disabled'); 
     203                                 
     204                                // Hide saving info 
     205                                $('#edit_info').hide(); 
    174206                        } 
    175207                } 
    176208                else 
    177                         alert(http.responseText); 
     209                        alert(data); 
    178210        } 
    179211} 
     
    185217function ape_cancel_edit() 
    186218{ 
    187         $('post' + ape_id).innerHTML = ape_temp_post; 
    188         ape_id = -1; 
    189 } 
    190  
    191  
    192 /* 
    193         Shows loading message (@ Loading...) 
    194 */ 
    195 function ape_show_loading_info() 
    196 { 
    197         $('post' + ape_id).innerHTML += '<div style="float:right"><img src="' + base_url + '/extensions/ajax_post_edit/loading.gif"> ' + ape['Loading'] + '</div>'; 
    198 } 
    199  
    200  
    201 /* 
    202         Shows saving message (@ Saving...) 
    203 */ 
    204 function ape_show_saving_info() 
    205 { 
    206         $('edit_info').style.display = 'block'; 
    207 } 
    208  
    209 /* 
    210         Hides saving information 
    211 */ 
    212 function ape_hide_saving_info() 
    213 { 
    214         $('edit_info').style.display = 'none'; 
    215 } 
    216  
    217  
    218 /* 
    219         ape_enable (or disable) form box 
    220 */ 
    221 function ape_enable(t) 
    222 { 
    223         var enb = !t; 
    224         $('postedit').disabled = enb; 
    225         $('btn_updatePost').disabled = enb; 
    226         $('btn_cancelUpdate').disabled = enb; 
    227         $('btn_fullEdit').disabled = enb; 
    228         if ($('fldsilent')) 
    229                 $('fldsilent').disabled = enb; 
     219        $('#post' + ape_id).fadeOut('fast', function() { 
     220                $('#post' + ape_id).html(ape_temp_post); 
     221                $('#post' + ape_id).fadeIn('fast'); 
     222                ape_id = -1; 
     223        } ); 
    230224} 
    231225 
     
    239233                return; 
    240234 
    241         var pos = findPos($('menu' + id)); 
    242         pos[0] += $('menu' + id).offsetWidth; 
    243         pos[1] += $('menu' + id).offsetHeight + 3; 
     235        var pos = findPos(document.getElementById('menu' + id)); 
     236        pos[0] += document.getElementById('menu' + id).offsetWidth; 
     237        pos[1] += document.getElementById('menu' + id).offsetHeight + 3; 
    244238 
    245239        var menu = document.createElement('div'); 
    246240        menu.setAttribute('id', 'menu'); 
    247241 
    248         menu.style.position = 'absolute'; 
    249242        menu.style.left =  pos[0] + 'px'; 
    250243        menu.style.top =  pos[1] + 'px'; 
    251244 
    252         menu.className = 'popup brd brd-page main-content'; 
     245        menu.className = 'popup'; 
    253246        menu.onmouseover = function () {ape_menu_hovered = true} 
    254247        menu.onmouseout = function () {ape_menu_hovered = false} 
     
    261254 
    262255        document.body.appendChild(menu); 
    263  
    264         $('menu').style.left = pos[0] - $('menu').offsetWidth + 'px'; 
    265  
     256         
     257        $('#menu').fadeIn('fast'); 
     258 
     259        document.getElementById('menu').style.left = pos[0] + 4 - document.getElementById('menu').clientWidth + 'px'; 
     260         
    266261        document.onclick = function() { 
    267262                        if (ape_menu_hovered == false) 
     
    276271function ape_hide_menu() 
    277272{ 
    278         if ($('menu')) 
    279                 document.body.removeChild($('menu')); 
     273        $('#menu').fadeOut('fast', function() { $(this).remove() } ); 
    280274} 
    281275 
     
    321315 
    322316 
    323 /* 
    324         Function sending ajax request 
    325         @data = data to send 
    326         @onready = function which will be executed after receiving data 
    327 */ 
    328 function sendRequest(data, onready) 
    329 { 
    330         // Without this IE don't get second reply (i think there's something wrong with onreadystatechange function) 
    331         if (ie) 
    332                 http = getHTTPObject(); 
    333  
    334         http.onreadystatechange = function() 
    335         { 
    336                 if (http.readyState == 4) 
    337                         onready(); 
    338         }; 
    339  
    340         http.open('POST', base_url + '/extensions/ajax_post_edit/edit.php', true); 
    341         http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'); 
    342  
    343         http.send(data); 
    344 } 
    345  
    346  
    347 /* 
    348         Function creating ajax request object 
    349 */ 
    350 function getHTTPObject() 
    351 { 
    352         var xmlhttp; 
    353         /*@cc_on 
    354         @if (@_jscript_version >= 5) 
    355                 try { 
    356                         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
    357                 } catch (e) { 
    358                         try { 
    359                                 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    360                         } catch (E) { 
    361                                 xmlhttp = false; 
    362                         } 
    363                 } 
    364         @else 
    365                 xmlhttp = false; 
    366         @end @*/ 
    367         if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { 
    368                 try { 
    369                         xmlhttp = new XMLHttpRequest(); 
    370                 } catch (e) { 
    371                         xmlhttp = false; 
    372                 } 
    373         } 
    374         return xmlhttp; 
    375 } 
    376  
    377  
    378 /* 
    379         Function returning element from elid 
    380 */ 
    381 function $(el_id) 
    382 { 
    383         return document.getElementById(el_id); 
    384 } 
    385  
    386  
    387 var http = getHTTPObject();     // We create the HTTP Object 
    388317var ape_temp_post;              // post message with html 
    389318var ape_id = -1;                // currently edited post id 
    390319var ape_menu_hovered = false;   // if menu is hovered 
    391320var ape; 
    392 var ape_update_url = ''; 
     321var ape_update_values; 
     322var ape_url = base_url + '/extensions/ajax_post_edit/edit.php'; 
  • branches/ajax_post_edit/manifest.xml

    r54 r62  
    3232 
    3333        $ape = 'var base_url = \''.$base_url.'\';'; 
    34         $ape .= "\n".'var ape = {\'crsf_token\' : \''.generate_form_token($ext_info['url'].'/edit.php').'\''; 
     34        $ape .= "\n".'var ape = {\'csrf_token\' : \''.generate_form_token($ext_info['url'].'/edit.php').'\''; 
    3535        $ape .= ', \'Loading\' : \''.$lang_ape['Loading'].'\''; 
    3636        $ape .= ', \'Quick edit\' : \''.$lang_ape['Quick Edit'].'\''; 
     
    3939        $ape .= '}'; 
    4040 
    41         $forum_head['ape_js'] = '<script type="text/javascript" src="'.$ext_info['url'].'/ajax_post_edit.js"></script>'; 
    4241        $forum_head['ape_css'] = '<link rel="stylesheet" type="text/css" media="screen" href="'.$ext_info['url'].'/style.css" />'; 
    43         $forum_head['ape_js2'] = '<script type="text/javascript">'."\n".$ape."\n".'</script>'; 
     42        $forum_head['ape_js'] = '<script type="text/javascript">'."\n".$ape."\n".'</script>'; 
     43        $forum_head['ape_js2'] = '<script type="text/javascript" src="'.$ext_info['url'].'/ajax_post_edit.js"></script>'; 
     44 
     45        if (file_exists($ext_info['path'].'/style/'.$forum_user['style'].'/style.css')) 
     46                $forum_head['quick_search_css'] = '<link rel="stylesheet" type="text/css" media="screen" href="'.$ext_info['url'].'/style/'.$forum_user['style'].'/style.css" />'; 
     47        else 
     48                $forum_head['quick_search_css'] = '<link rel="stylesheet" type="text/css" media="screen" href="'.$ext_info['url'].'/style/Oxygen/style.css" />'; 
     49         
     50        $forum_head['jquery_menu'] = '<script type="text/javascript" src="'.$ext_info['url'].'/jquery.menu.js"></script>'; 
    4451} 
    4552                                             ]]></hook> 
  • branches/ajax_post_edit/style.css

    r36 r62  
    11 
    22.popup { 
    3         background: #f1f1f1; 
    4         border: 1px solid #000 !important; 
    5         min-width: 0; 
    6         width: auto; 
    7         padding: 0px !important; 
    8 /*      font-family: Verdana; 
    9         font-size: 11px;*/ 
     3        background: transparent url(shadow.png) bottom right; 
     4        padding-right: 4px; 
     5        padding-bottom: 4px; 
     6        display: none; 
     7        position: absolute; 
    108} 
    119 
    1210.popup ul { 
     11        background: #f1f1f1; 
     12        border: 1px solid #000; 
    1313        list-style: none; 
    1414        padding-left: 0px !important; 
     
    2727        padding: 5px 10px 5px 10px; 
    2828        display: block; 
     29        text-decoration: none; 
    2930} 
    3031 
     
    3233        padding: 0; 
    3334} 
     35 
     36 
     37