Changeset 62 for branches/ajax_post_edit
- Timestamp:
- 02/28/09 17:10:12 (3 years ago)
- Location:
- branches/ajax_post_edit
- Files:
-
- 4 added
- 3 modified
-
ajax_post_edit.js (modified) (12 diffs)
-
manifest.xml (modified) (2 diffs)
-
shadow.png (added)
-
style (added)
-
style.css (modified) (3 diffs)
-
style/Oxygen (added)
-
style/Oxygen/style.css (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/ajax_post_edit/ajax_post_edit.js
r54 r62 7 7 /**********************************************************/ 8 8 9 // Detect Internet Explorer10 var ie = /msie/i.test (navigator.userAgent);11 9 12 10 /* … … 16 14 { 17 15 // 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)) 19 17 { 20 18 // if other post is editing, cancel edit … … 34 32 ape_hide_menu(); 35 33 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)}); 40 45 } 41 46 } … … 46 51 Function executed after receiving post data 47 52 */ 48 function ape_on_ready_get_post( )49 { 50 var parsed_message = match( http.responseText, 'parsed_message');53 function ape_on_ready_get_post(data) 54 { 55 var parsed_message = match(data, 'parsed_message'); 51 56 52 57 // If there aren't any errors 53 58 if (parsed_message != '') 54 59 { 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 60 71 return 1; 61 72 } 62 73 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(':'); 66 77 if (confirm(response[1])) 67 78 { 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)}); 70 87 } 71 88 } 72 89 else 73 alert( http.responseText);90 alert(data); 74 91 75 $(' post' + ape_id).innerHTML = ape_temp_post;92 $('#post' + ape_id).html(ape_temp_post); 76 93 id = -1; 77 94 } … … 83 100 function ape_update_post() 84 101 { 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(); 98 121 } 99 122 … … 102 125 Function executed after receiving update request 103 126 */ 104 function ape_on_ready_update_post( )105 { 106 var message = match( http.responseText, 'message');127 function ape_on_ready_update_post(data) 128 { 129 var message = match(data, 'message'); 107 130 if (message != '') 108 131 { … … 110 133 try 111 134 { 112 pun_quote_posts[ape_id] = $(' postedit').value;135 pun_quote_posts[ape_id] = $('#postedit').val; 113 136 } 114 137 catch (e) {} 115 138 116 var last_edit = match( http.responseText, 'last_edit');139 var last_edit = match(data, 'last_edit'); 117 140 118 141 var sig = ''; 142 119 143 if (ape_temp_post.toLowerCase().indexOf('<div class="sig-content">') != -1) // if post has signature 120 144 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 } ); 123 152 return 1; 124 153 } 125 154 126 155 127 var error = match(http.responseText, 'error'); 128 156 var error = match(data, 'error'); 129 157 // if message has errors 130 158 if (error != '') 131 159 { 132 var cur_message = $(' postedit').value;160 var cur_message = $('#postedit').val(); 133 161 134 162 // if recently displayed errors 135 if ( $('edit-error'))163 if (document.getElementById('edit-error')) 136 164 { 137 165 error = error.substring(error.indexOf('>')+1); 138 166 error = error.substring(0, error.lastIndexOf('</')); 139 $(' edit-error').innerHTML = error;167 $('#edit-error').html(error); 140 168 } 141 169 else 142 170 { 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(); 148 175 var replace = html.substring(0, html.indexOf('<', 2)); 149 176 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(); 159 188 } 160 189 else 161 190 { 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(':'); 165 194 if (confirm(response[1])) 166 195 { 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)}); 169 199 } 170 200 else 171 201 { 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(); 174 206 } 175 207 } 176 208 else 177 alert( http.responseText);209 alert(data); 178 210 } 179 211 } … … 185 217 function ape_cancel_edit() 186 218 { 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 } ); 230 224 } 231 225 … … 239 233 return; 240 234 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; 244 238 245 239 var menu = document.createElement('div'); 246 240 menu.setAttribute('id', 'menu'); 247 241 248 menu.style.position = 'absolute';249 242 menu.style.left = pos[0] + 'px'; 250 243 menu.style.top = pos[1] + 'px'; 251 244 252 menu.className = 'popup brd brd-page main-content';245 menu.className = 'popup'; 253 246 menu.onmouseover = function () {ape_menu_hovered = true} 254 247 menu.onmouseout = function () {ape_menu_hovered = false} … … 261 254 262 255 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 266 261 document.onclick = function() { 267 262 if (ape_menu_hovered == false) … … 276 271 function ape_hide_menu() 277 272 { 278 if ($('menu')) 279 document.body.removeChild($('menu')); 273 $('#menu').fadeOut('fast', function() { $(this).remove() } ); 280 274 } 281 275 … … 321 315 322 316 323 /*324 Function sending ajax request325 @data = data to send326 @onready = function which will be executed after receiving data327 */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 object349 */350 function getHTTPObject()351 {352 var xmlhttp;353 /*@cc_on354 @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 @else365 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 elid380 */381 function $(el_id)382 {383 return document.getElementById(el_id);384 }385 386 387 var http = getHTTPObject(); // We create the HTTP Object388 317 var ape_temp_post; // post message with html 389 318 var ape_id = -1; // currently edited post id 390 319 var ape_menu_hovered = false; // if menu is hovered 391 320 var ape; 392 var ape_update_url = ''; 321 var ape_update_values; 322 var ape_url = base_url + '/extensions/ajax_post_edit/edit.php'; -
branches/ajax_post_edit/manifest.xml
r54 r62 32 32 33 33 $ape = 'var base_url = \''.$base_url.'\';'; 34 $ape .= "\n".'var ape = {\'c rsf_token\' : \''.generate_form_token($ext_info['url'].'/edit.php').'\'';34 $ape .= "\n".'var ape = {\'csrf_token\' : \''.generate_form_token($ext_info['url'].'/edit.php').'\''; 35 35 $ape .= ', \'Loading\' : \''.$lang_ape['Loading'].'\''; 36 36 $ape .= ', \'Quick edit\' : \''.$lang_ape['Quick Edit'].'\''; … … 39 39 $ape .= '}'; 40 40 41 $forum_head['ape_js'] = '<script type="text/javascript" src="'.$ext_info['url'].'/ajax_post_edit.js"></script>';42 41 $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>'; 44 51 } 45 52 ]]></hook> -
branches/ajax_post_edit/style.css
r36 r62 1 1 2 2 .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; 10 8 } 11 9 12 10 .popup ul { 11 background: #f1f1f1; 12 border: 1px solid #000; 13 13 list-style: none; 14 14 padding-left: 0px !important; … … 27 27 padding: 5px 10px 5px 10px; 28 28 display: block; 29 text-decoration: none; 29 30 } 30 31 … … 32 33 padding: 0; 33 34 } 35 36 37