[ Index ] |
PHP Cross Reference of YOURLS |
[Summary view] [Print] [Text view]
1 // Init some stuff 2 $(document).ready(function(){ 3 $('#add-url, #add-keyword').keypress(function(e){ 4 if (e.which == 13) {add_link();} 5 }); 6 add_link_reset(); 7 $('#new_url_form').attr('action', 'javascript:add_link();'); 8 9 $('input.text').focus(function(){ 10 $(this).select(); 11 }); 12 13 // this one actually has little impact, the .hasClass('disabled') in each edit_link_display(), remove() etc... fires faster 14 $(document).on( 'click', 'a.button', function() { 15 if( $(this).hasClass('disabled') ) { 16 return false; 17 } 18 }); 19 20 // When Searching, explode search text in pieces -- see split_search_text_before_search() 21 $('#filter_form').submit( function(){ 22 split_search_text_before_search(); 23 return true; 24 }); 25 }); 26 27 // Create new link and add to table 28 function add_link() { 29 if( $('#add-button').hasClass('disabled') ) { 30 return false; 31 } 32 var newurl = $("#add-url").val(); 33 var nonce = $("#nonce-add").val(); 34 if ( !newurl || newurl == 'http://' || newurl == 'https://' ) { 35 return; 36 } 37 var keyword = $("#add-keyword").val(); 38 var nextid = parseInt($('#main_table tbody tr[id^="id-"]').length) + 1; 39 add_loading("#add-button"); 40 $.getJSON( 41 ajaxurl, 42 {action:'add', url: newurl, keyword: keyword, nonce: nonce, rowid: nextid}, 43 function(data){ 44 if(data.status == 'success') { 45 $('#main_table tbody').prepend( data.html ).trigger("update"); 46 $('#nourl_found').css('display', 'none'); 47 zebra_table(); 48 increment_counter(); 49 toggle_share_fill_boxes( data.url.url, data.shorturl, data.url.title ); 50 } 51 52 add_link_reset(); 53 end_loading("#add-button"); 54 end_disable("#add-button"); 55 56 feedback(data.message, data.status); 57 } 58 ); 59 } 60 61 function toggle_share_fill_boxes( url, shorturl, title ) { 62 $('#copylink').val( shorturl ); 63 $('#titlelink').val( title ); 64 $('#origlink').attr( 'href', url ).html( url ); 65 $('#statlink').attr( 'href', shorturl+'+' ).html( shorturl+'+' ); 66 var tweet = ( title ? title + ' ' + shorturl : shorturl ); 67 $('#tweet_body').val( tweet ).keypress(); 68 $('#shareboxes').slideDown( '300', function(){ init_clipboard(); } ); // clipboard re-initialized after slidedown to make sure the invisible Flash element is correctly positionned 69 $('#tweet_body').keypress(); 70 } 71 72 // Display the edition interface 73 function edit_link_display(id) { 74 if( $('#edit-button-'+id).hasClass('disabled') ) { 75 return false; 76 } 77 add_loading('#actions-'+id+' .button'); 78 var keyword = $('#keyword_'+id).val(); 79 var nonce = get_var_from_query( $('#edit-button-'+id).attr('href'), 'nonce' ); 80 $.getJSON( 81 ajaxurl, 82 { action: "edit_display", keyword: keyword, nonce: nonce, id: id }, 83 function(data){ 84 $("#id-" + id).after( data.html ); 85 $("#edit-url-"+ id).focus(); 86 end_loading('#actions-'+id+' .button'); 87 } 88 ); 89 } 90 91 // Delete a link 92 function remove_link(id) { 93 if( $('#delete-button-'+id).hasClass('disabled') ) { 94 return false; 95 } 96 if (!confirm('Really delete?')) { 97 return; 98 } 99 var keyword = $('#keyword_'+id).val(); 100 var nonce = get_var_from_query( $('#delete-button-'+id).attr('href'), 'nonce' ); 101 $.getJSON( 102 ajaxurl, 103 { action: "delete", keyword: keyword, nonce: nonce, id: id }, 104 function(data){ 105 if (data.success == 1) { 106 $("#id-" + id).fadeOut(function(){ 107 $(this).remove(); 108 if( $('#main_table tbody tr').length == 1 ) { 109 $('#nourl_found').css('display', ''); 110 } 111 112 zebra_table(); 113 }); 114 decrement_counter(); 115 decrease_total_clicks( id ); 116 } else { 117 alert('something wrong happened while deleting :/'); 118 } 119 } 120 ); 121 } 122 123 // Redirect to stat page 124 function go_stats(link) { 125 window.location=link; 126 } 127 128 // Cancel edition of a link 129 function edit_link_hide(id) { 130 $("#edit-" + id).fadeOut(200, function(){ 131 $("#edit-" + id).remove(); 132 end_disable('#actions-'+id+' .button'); 133 }); 134 } 135 136 // Save edition of a link 137 function edit_link_save(id) { 138 add_loading("#edit-close-" + id); 139 var newurl = $("#edit-url-" + id).val(); 140 var newkeyword = $("#edit-keyword-" + id).val(); 141 var title = $("#edit-title-" + id).val(); 142 var keyword = $('#old_keyword_'+id).val(); 143 var nonce = $('#nonce_'+id).val(); 144 var www = $('#yourls-site').val(); 145 $.getJSON( 146 ajaxurl, 147 {action:'edit_save', url: newurl, id: id, keyword: keyword, newkeyword: newkeyword, title: title, nonce: nonce }, 148 function(data){ 149 if(data.status == 'success') { 150 151 if( data.url.title != '' ) { 152 var display_link = '<a href="' + data.url.url + '" title="' + data.url.title + '">' + data.url.display_title + '</a><br/><small><a href="' + data.url.url + '">' + data.url.display_url + '</a></small>'; 153 } else { 154 var display_link = '<a href="' + data.url.url + '" title="' + data.url.url + '">' + data.url.display_url + '</a>'; 155 } 156 157 $("#url-" + id).html(display_link); 158 $("#keyword-" + id).html('<a href="' + data.url.shorturl + '" title="' + data.url.shorturl + '">' + data.url.keyword + '</a>'); 159 $("#edit-" + id).fadeOut(200, function(){ 160 $("#edit-" + id).remove(); 161 $('#main_table tbody').trigger("update"); 162 }); 163 $('#keyword_'+id).val( newkeyword ); 164 $('#statlink-'+id).attr( 'href', data.url.shorturl+'+' ); 165 } 166 feedback(data.message, data.status); 167 end_loading("#edit-close-" + id); 168 end_disable("#edit-close-" + id); 169 if(data.status == 'success') { 170 end_disable("#actions-" + id + ' .button'); 171 } 172 } 173 ); 174 } 175 176 // Prettify table with odd & even rows 177 function zebra_table() { 178 $("#main_table tbody tr:even").removeClass('odd').addClass('even'); 179 $("#main_table tbody tr:odd").removeClass('even').addClass('odd'); 180 $('#main_table tbody').trigger("update"); 181 } 182 183 // Ready to add another URL 184 function add_link_reset() { 185 $('#add-url').val('').focus(); 186 $('#add-keyword').val(''); 187 } 188 189 // Increment URL counters 190 function increment_counter() { 191 $('.increment').each(function(){ 192 $(this).html( parseInt($(this).html()) + 1); 193 }); 194 } 195 196 // Decrement URL counters 197 function decrement_counter() { 198 $('.increment').each(function(){ 199 $(this).html( parseInt($(this).html()) - 1 ); 200 }); 201 } 202 203 // Decrease number of total clicks 204 function decrease_total_clicks( id ) { 205 var total_clicks = $("#overall_tracking strong:nth-child(2)"); 206 total_clicks.html( parseInt( total_clicks.html() ) - parseInt( $('#clicks-' + id).html() ) ); 207 } 208 209 // Toggle Share box 210 function toggle_share(id) { 211 if( $('#share-button-'+id).hasClass('disabled') ) { 212 return false; 213 } 214 var link = $('#url-'+id+' a:first'); 215 var longurl = link.attr('href'); 216 var title = link.attr('title'); 217 var shorturl = $('#keyword-'+id+' a:first').attr('href'); 218 219 toggle_share_fill_boxes( longurl, shorturl, title ); 220 } 221 222 // When "Search" is clicked, split search text to beat servers which don't like query string with "http://" 223 // See https://github.com/YOURLS/YOURLS/issues/1576 224 function split_search_text_before_search() { 225 // Add 2 hidden fields and populate them with parts of search text 226 $("<input type='hidden' name='search_protocol' />").appendTo('#filter_form'); 227 $("<input type='hidden' name='search_slashes' />").appendTo('#filter_form'); 228 var search = get_protocol_slashes_and_rest( $('#filter_form input[name=search]').val() ); 229 $('#filter_form input[name=search]').val( search.rest ); 230 $('#filter_form input[name=search_protocol]').val( search.protocol ); 231 $('#filter_form input[name=search_slashes]').val( search.slashes ); 232 } 233
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Jan 21 05:10:11 2025 | Cross-referenced by PHPXref 0.7.1 |