2 $(document).ready(function(){
\r
3 $('#add-url, #add-keyword').keypress(function(e){
\r
4 if (e.which == 13) {add();}
\r
7 $('#new_url_form').attr('action', 'javascript:add();');
\r
9 $('input.text').focus(function(){
\r
13 // this one actually has little impact, the .hasClass('disabled') in each edit(), remove() etc... fires faster
\r
14 $('a.button').live('click', function() {
\r
15 if( $(this).hasClass('disabled') ) {
\r
21 // Create new link and add to table
\r
23 if( $('#add-button').hasClass('disabled') ) {
\r
26 var newurl = $("#add-url").val();
\r
27 var nonce = $("#nonce-add").val();
\r
28 if ( !newurl || newurl == 'http://' || newurl == 'https://' ) {
\r
31 var keyword = $("#add-keyword").val();
\r
32 add_loading("#add-button");
\r
35 {action:'add', url: newurl, keyword: keyword, nonce: nonce},
\r
37 if(data.status == 'success') {
\r
38 $('#main_table tbody').prepend( data.html ).trigger("update");
\r
39 $('#nourl_found').css('display', 'none');
\r
42 toggle_share_fill_boxes( data.url.url, data.shorturl, data.url.title );
\r
46 end_loading("#add-button");
\r
47 end_disable("#add-button");
\r
49 feedback(data.message, data.status);
\r
54 function toggle_share_fill_boxes( url, shorturl, title ) {
\r
55 $('#copylink').val( shorturl );
\r
56 $('#titlelink').val( title );
\r
57 $('#origlink').attr( 'href', url ).html( url );
\r
58 $('#statlink').attr( 'href', shorturl+'+' ).html( shorturl+'+' );
\r
59 var tweet = ( title ? title + ' ' + shorturl : shorturl );
\r
60 $('#tweet_body').val( tweet ).keypress();
\r
61 $('#shareboxes').slideDown( '300', function(){ init_clipboard(); } ); // clipboard re-initialized after slidedown to make sure the invisible Flash element is correctly positionned
\r
62 $('#tweet_body').keypress();
\r
65 // Display the edition interface
\r
67 if( $('#edit-button-'+id).hasClass('disabled') ) {
\r
70 add_loading('#actions-'+id+' .button');
\r
71 var keyword = $('#keyword_'+id).val();
\r
72 var nonce = get_var_from_query( $('#edit-button-'+id).attr('href'), 'nonce' );
\r
75 { action: "edit_display", keyword: keyword, nonce: nonce, id: id },
\r
77 $("#id-" + id).after( data.html );
\r
78 $("#edit-url-"+ id).focus();
\r
79 end_loading('#actions-'+id+' .button');
\r
85 function remove(id) {
\r
86 if( $('#delete-button-'+id).hasClass('disabled') ) {
\r
89 if (!confirm('Really delete?')) {
\r
92 var keyword = $('#keyword_'+id).val();
\r
93 var nonce = get_var_from_query( $('#delete-button-'+id).attr('href'), 'nonce' );
\r
96 { action: "delete", keyword: keyword, nonce: nonce, id: id },
\r
98 if (data.success == 1) {
\r
99 $("#id-" + id).fadeOut(function(){
\r
101 if( $('#main_table tbody tr').length == 1 ) {
\r
102 $('#nourl_found').css('display', '');
\r
109 alert('something wrong happened while deleting :/');
\r
115 // Redirect to stat page
\r
116 function stats(link) {
\r
117 window.location=link;
\r
120 // Cancel edition of a link
\r
121 function hide_edit(id) {
\r
122 $("#edit-" + id).fadeOut(200, function(){
\r
123 end_disable('#actions-'+id+' .button');
\r
127 // Save edition of a link
\r
128 function edit_save(id) {
\r
129 add_loading("#edit-close-" + id);
\r
130 var newurl = encodeURI( $("#edit-url-" + id).val() );
\r
131 var newkeyword = $("#edit-keyword-" + id).val();
\r
132 var title = $("#edit-title-" + id).val();
\r
133 var keyword = $('#old_keyword_'+id).val();
\r
134 var nonce = $('#nonce_'+id).val();
\r
135 var www = $('#yourls-site').val();
\r
138 {action:'edit_save', url: newurl, id: id, keyword: keyword, newkeyword: newkeyword, title: title, nonce: nonce },
\r
140 if(data.status == 'success') {
\r
142 if( data.url.title != '' ) {
\r
143 var display_link = '<a href="' + data.url.url + '" title="' + data.url.url + '">' + data.url.display_title + '</a><br/><small><a href="' + data.url.url + '">' + data.url.display_url + '</a></small>';
\r
145 var display_link = '<a href="' + data.url.url + '" title="' + data.url.url + '">' + data.url.display_url + '</a>';
\r
148 $("#url-" + id).html(display_link);
\r
149 $("#keyword-" + id).html('<a href="' + data.url.shorturl + '" title="' + data.url.shorturl + '">' + data.url.keyword + '</a>');
\r
150 $("#timestamp-" + id).html(data.url.date);
\r
151 $("#edit-" + id).fadeOut(200, function(){
\r
152 $('#main_table tbody').trigger("update");
\r
154 $('#keyword_'+id).val( newkeyword );
\r
155 $('#statlink-'+id).attr( 'href', data.url.shorturl+'+' );
\r
157 feedback(data.message, data.status);
\r
158 end_loading("#edit-close-" + id);
\r
159 end_disable("#actions-" + id + ' .button');
\r
164 // Prettify table with odd & even rows
\r
165 function zebra_table() {
\r
166 $("#main_table tbody tr:even").removeClass('odd').addClass('even');
\r
167 $("#main_table tbody tr:odd").removeClass('even').addClass('odd');
\r
168 $('#main_table tbody').trigger("update");
\r
171 // Ready to add another URL
\r
172 function reset_url() {
\r
173 $('#add-url').val('http://').focus();
\r
174 $('#add-keyword').val('');
\r
177 // Increment URL counters
\r
178 function increment() {
\r
179 $('.increment').each(function(){
\r
180 $(this).html( parseInt($(this).html()) + 1);
\r
184 // Decrement URL counters
\r
185 function decrement() {
\r
186 $('.increment').each(function(){
\r
187 $(this).html( parseInt($(this).html()) - 1 );
\r
191 // Toggle Share box
\r
192 function toggle_share(id) {
\r
193 if( $('#share-button-'+id).hasClass('disabled') ) {
\r
196 var link = $('#url-'+id+' a:first');
\r
197 var longurl = link.attr('href');
\r
198 var title = link.attr('title');
\r
199 var shorturl = $('#keyword-'+id+' a:first').attr('href');
\r
201 toggle_share_fill_boxes( longurl, shorturl, title );
\r