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
45 toggle_share_fill_boxes( data.url.url, data.shorturl, data.url.title );
\r
47 end_loading("#add-button");
\r
48 end_disable("#add-button");
\r
50 feedback(data.message, data.status);
\r
55 function toggle_share_fill_boxes( url, shorturl, title ) {
\r
56 $('#copylink').val( shorturl );
\r
57 $('#titlelink').val( title );
\r
58 $('#origlink').attr( 'href', url ).html( url );
\r
59 $('#statlink').attr( 'href', shorturl+'+' ).html( shorturl+'+' );
\r
60 var tweet = ( title ? title + ' ' + shorturl : shorturl );
\r
61 $('#tweet_body').val( tweet ).keypress();
\r
62 $('#shareboxes').slideDown( '300', function(){ init_clipboard(); } ); // clipboard re-initialized after slidedown to make sure the invisible Flash element is correctly positionned
\r
63 $('#tweet_body').keypress();
\r
66 // Display the edition interface
\r
68 if( $('#edit-button-'+id).hasClass('disabled') ) {
\r
71 add_loading('#actions-'+id+' .button');
\r
72 var keyword = $('#keyword_'+id).val();
\r
73 var nonce = get_var_from_query( $('#edit-button-'+id).attr('href'), 'nonce' );
\r
76 { action: "edit_display", keyword: keyword, nonce: nonce, id: id },
\r
78 $("#id-" + id).after( data.html );
\r
79 $("#edit-url-"+ id).focus();
\r
80 end_loading('#actions-'+id+' .button');
\r
86 function remove(id) {
\r
87 if( $('#delete-button-'+id).hasClass('disabled') ) {
\r
90 if (!confirm('Really delete?')) {
\r
93 var keyword = $('#keyword_'+id).val();
\r
94 var nonce = get_var_from_query( $('#delete-button-'+id).attr('href'), 'nonce' );
\r
97 { action: "delete", keyword: keyword, nonce: nonce, id: id },
\r
99 if (data.success == 1) {
\r
100 $("#id-" + id).fadeOut(function(){
\r
102 if( $('#main_table tbody tr').length == 1 ) {
\r
103 $('#nourl_found').css('display', '');
\r
110 alert('something wrong happened while deleting :/');
\r
116 // Redirect to stat page
\r
117 function stats(link) {
\r
118 window.location=link;
\r
121 // Cancel edition of a link
\r
122 function hide_edit(id) {
\r
123 $("#edit-" + id).fadeOut(200, function(){
\r
124 end_disable('#actions-'+id+' .button');
\r
128 // Save edition of a link
\r
129 function edit_save(id) {
\r
130 add_loading("#edit-close-" + id);
\r
131 var newurl = $("#edit-url-" + id).val();
\r
132 var newkeyword = $("#edit-keyword-" + id).val();
\r
133 var title = $("#edit-title-" + id).val();
\r
134 var keyword = $('#old_keyword_'+id).val();
\r
135 var nonce = $('#nonce_'+id).val();
\r
136 var www = $('#yourls-site').val();
\r
139 {action:'edit_save', url: newurl, id: id, keyword: keyword, newkeyword: newkeyword, title: title, nonce: nonce },
\r
141 if(data.status == 'success') {
\r
143 if( data.url.title != '' ) {
\r
144 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
146 var display_link = '<a href="' + data.url.url + '" title="' + data.url.url + '">' + data.url.display_url + '</a>';
\r
149 $("#url-" + id).html(display_link);
\r
150 $("#keyword-" + id).html('<a href="' + data.url.shorturl + '" title="' + data.url.shorturl + '">' + data.url.keyword + '</a>');
\r
151 $("#timestamp-" + id).html(data.url.date);
\r
152 $("#edit-" + id).fadeOut(200, function(){
\r
153 $('#main_table tbody').trigger("update");
\r
155 $('#keyword_'+id).val( newkeyword );
\r
156 $('#statlink-'+id).attr( 'href', data.url.shorturl+'+' );
\r
158 feedback(data.message, data.status);
\r
159 end_loading("#edit-close-" + id);
\r
160 end_disable("#actions-" + id + ' .button');
\r
165 // Prettify table with odd & even rows
\r
166 function zebra_table() {
\r
167 $("#main_table tbody tr:even").removeClass('odd').addClass('even');
\r
168 $("#main_table tbody tr:odd").removeClass('even').addClass('odd');
\r
169 $('#main_table tbody').trigger("update");
\r
172 // Ready to add another URL
\r
173 function reset_url() {
\r
174 $('#add-url').val('http://').focus();
\r
175 $('#add-keyword').val('');
\r
178 // Increment URL counters
\r
179 function increment() {
\r
180 $('.increment').each(function(){
\r
181 $(this).html( parseInt($(this).html()) + 1);
\r
185 // Decrement URL counters
\r
186 function decrement() {
\r
187 $('.increment').each(function(){
\r
188 $(this).html( parseInt($(this).html()) - 1 );
\r
192 // Toggle Share box
\r
193 function toggle_share(id) {
\r
194 if( $('#share-button-'+id).hasClass('disabled') ) {
\r
197 var link = $('#url-'+id+' a:first');
\r
198 var longurl = link.attr('href');
\r
199 var title = link.attr('title');
\r
200 var shorturl = $('#keyword-'+id+' a:first').attr('href');
\r
202 toggle_share_fill_boxes( longurl, shorturl, title );
\r