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();
\r
64 $('#tweet_body').keypress();
\r
67 // Display the edition interface
\r
69 if( $('#edit-button-'+id).hasClass('disabled') ) {
\r
72 add_loading('#actions-'+id+' .button');
\r
73 var keyword = $('#keyword_'+id).val();
\r
74 var nonce = get_var_from_query( $('#edit-button-'+id).attr('href'), 'nonce' );
\r
77 { action: "edit_display", keyword: keyword, nonce: nonce, id: id },
\r
79 $("#id-" + id).after( data.html );
\r
80 $("#edit-url-"+ id).focus();
\r
81 end_loading('#actions-'+id+' .button');
\r
87 function remove(id) {
\r
88 if( $('#delete-button-'+id).hasClass('disabled') ) {
\r
91 if (!confirm('Really delete?')) {
\r
94 var keyword = $('#keyword_'+id).val();
\r
95 var nonce = get_var_from_query( $('#delete-button-'+id).attr('href'), 'nonce' );
\r
98 { action: "delete", keyword: keyword, nonce: nonce, id: id },
\r
100 if (data.success == 1) {
\r
101 $("#id-" + id).fadeOut(function(){
\r
103 if( $('#main_table tbody tr').length == 1 ) {
\r
104 $('#nourl_found').css('display', '');
\r
111 alert('something wrong happened while deleting :/');
\r
117 // Redirect to stat page
\r
118 function stats(link) {
\r
119 window.location=link;
\r
122 // Cancel edition of a link
\r
123 function hide_edit(id) {
\r
124 $("#edit-" + id).fadeOut(200, function(){
\r
125 end_disable('#actions-'+id+' .button');
\r
129 // Save edition of a link
\r
130 function edit_save(id) {
\r
131 add_loading("#edit-close-" + id);
\r
132 var newurl = $("#edit-url-" + id).val();
\r
133 var newkeyword = $("#edit-keyword-" + id).val();
\r
134 var title = $("#edit-title-" + id).val();
\r
135 var keyword = $('#old_keyword_'+id).val();
\r
136 var nonce = $('#nonce_'+id).val();
\r
137 var www = $('#yourls-site').val();
\r
140 {action:'edit_save', url: newurl, id: id, keyword: keyword, newkeyword: newkeyword, title: title, nonce: nonce },
\r
142 if(data.status == 'success') {
\r
144 if( data.url.title != '' ) {
\r
145 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
147 var display_link = '<a href="' + data.url.url + '" title="' + data.url.url + '">' + data.url.display_url + '</a>';
\r
150 $("#url-" + id).html(display_link);
\r
151 $("#keyword-" + id).html('<a href="' + data.url.shorturl + '" title="' + data.url.shorturl + '">' + data.url.keyword + '</a>');
\r
152 $("#timestamp-" + id).html(data.url.date);
\r
153 $("#edit-" + id).fadeOut(200, function(){
\r
154 $('#main_table tbody').trigger("update");
\r
156 $('#keyword_'+id).val( newkeyword );
\r
157 $('#statlink-'+id).attr( 'href', data.url.shorturl+'+' );
\r
159 feedback(data.message, data.status);
\r
160 end_loading("#edit-close-" + id);
\r
161 end_disable("#actions-" + id + ' .button');
\r
166 // Prettify table with odd & even rows
\r
167 function zebra_table() {
\r
168 $("#main_table tbody tr:even").removeClass('odd').addClass('even');
\r
169 $("#main_table tbody tr:odd").removeClass('even').addClass('odd');
\r
170 $('#main_table tbody').trigger("update");
\r
173 // Ready to add another URL
\r
174 function reset_url() {
\r
175 $('#add-url').val('http://').focus();
\r
176 $('#add-keyword').val('');
\r
179 // Increment URL counters
\r
180 function increment() {
\r
181 $('.increment').each(function(){
\r
182 $(this).html( parseInt($(this).html()) + 1);
\r
186 // Decrement URL counters
\r
187 function decrement() {
\r
188 $('.increment').each(function(){
\r
189 $(this).html( parseInt($(this).html()) - 1 );
\r
193 // Toggle Share box
\r
194 function toggle_share(id) {
\r
195 if( $('#share-button-'+id).hasClass('disabled') ) {
\r
198 var link = $('#url-'+id+' a:first');
\r
199 var longurl = link.attr('href');
\r
200 var title = link.attr('title');
\r
201 var shorturl = $('#keyword-'+id+' a:first').attr('href');
\r
203 toggle_share_fill_boxes( longurl, shorturl, title );
\r