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').click(function(){
\r
15 // Create new link and add to table
\r
17 var newurl = $("#add-url").val();
\r
18 if ( !newurl || newurl == 'http://' || newurl == 'https://' ) {
\r
21 var keyword = $("#add-keyword").val();
\r
22 add_loading("#add-button");
\r
25 {mode:'add', url: newurl, keyword: keyword},
\r
27 if(data.status == 'success') {
\r
28 $('#tblUrl tbody').prepend( data.html ).trigger("update");
\r
29 $('.nourl_found').remove();
\r
34 feedback(data.message, data.status);
\r
36 $('#copylink').val( data.shorturl );
\r
37 $('#origlink').attr( 'href', data.url.url ).html( data.url.url );
\r
38 $('#statlink').attr( 'href', data.shorturl+'+' ).html( data.shorturl+'+' );
\r
39 $('#tweet_body').val( data.shorturl ).keypress();
\r
40 $('#shareboxes').slideDown();
\r
42 end_loading("#add-button");
\r
43 end_disable("#add-button");
\r
48 // Display the edition interface
\r
50 add_loading('#actions-'+id+' .button');
\r
51 var keyword = $('#keyword_'+id).val();
\r
54 { mode: "edit_display", keyword: keyword },
\r
56 $("#id-" + id).after( data.html );
\r
57 $("#edit-url-"+ id).focus();
\r
58 end_loading('#actions-'+id+' .button');
\r
64 function remove(id) {
\r
65 if (!confirm('Really delete?')) {
\r
68 var keyword = $('#keyword_'+id).val();
\r
71 { mode: "delete", keyword: keyword },
\r
73 if (data.success == 1) {
\r
74 $("#id-" + id).fadeOut(function(){$(this).remove();zebra_table();});
\r
77 alert('something wrong happened while deleting :/');
\r
83 // Redirect to stat page
\r
84 function stats(link) {
\r
85 window.location=link;
\r
88 // Cancel edition of a link
\r
89 function hide_edit(id) {
\r
90 $("#edit-" + id).fadeOut(200, function(){
\r
91 end_disable('#actions-'+id+' .button');
\r
95 // Save edition of a link
\r
96 function edit_save(id) {
\r
97 add_loading("#edit-close-" + id);
\r
98 var newurl = $("#edit-url-" + id).val();
\r
99 var newkeyword = $("#edit-keyword-" + id).val();
\r
100 var keyword = $('#old_keyword_'+id).val();
\r
101 var www = $('#yourls-site').val();
\r
104 {mode:'edit_save', url: newurl, keyword: keyword, newkeyword: newkeyword },
\r
106 if(data.status == 'success') {
\r
107 $("#url-" + id).html('<a href="' + data.url.url + '" title="' + data.url.url + '">' + data.url.display_url + '</a>');
\r
108 $("#keyword-" + id).html('<a href="' + data.url.shorturl + '" title="' + data.url.shorturl + '">' + data.url.keyword + '</a>');
\r
109 $("#timestamp-" + id).html(data.url.date);
\r
110 $("#edit-" + id).fadeOut(200, function(){
\r
111 $('#tblUrl tbody').trigger("update");
\r
113 $('#keyword_'+id).val( newkeyword );
\r
114 $('#statlink-'+id).attr( 'href', data.url.shorturl+'+' );
\r
116 feedback(data.message, data.status);
\r
117 end_disable("#edit-close-" + id);
\r
118 end_loading("#edit-close-" + id);
\r
119 end_disable("#edit-button-" + id);
\r
120 end_disable("#delete-button-" + id);
\r
125 // Unused for now since HTTP Auth sucks donkeys.
\r
126 function logout() {
\r
129 url: "index_ajax.php",
\r
130 data: {mode:'logout'},
\r
131 success: function() {
\r
132 window.parent.location.href = window.parent.location.href;
\r
137 // Begin the spinning animation & disable a button
\r
138 function add_loading(el) {
\r
139 $(el).attr("disabled", "disabled").addClass('disabled').addClass('loading');
\r
142 // End spinning animation
\r
143 function end_loading(el) {
\r
144 $(el).removeClass('loading');
\r
147 // Un-disable an element
\r
148 function end_disable(el) {
\r
149 $(el).removeAttr("disabled").removeClass('disabled');
\r
152 // Prettify table with odd & even rows
\r
153 function zebra_table() {
\r
154 $("#tblUrl tbody tr:even").removeClass('odd').addClass('even');
\r
155 $("#tblUrl tbody tr:odd").removeClass('even').addClass('odd');
\r
156 $('#tblUrl tbody').trigger("update");
\r
159 // Update feedback message
\r
160 function feedback(msg, type) {
\r
161 var span = (type == 'fail') ? '<span class="fail">' : '<span>' ;
\r
162 var delay = (type == 'fail') ? 2500 : 1000 ;
\r
163 $('#feedback').html(span + msg + '</span>').fadeIn(200,function(){
\r
164 $(this).animate({'opacity':1}, delay, function() {
\r
165 $(this).fadeOut(800);
\r
170 // Ready to add another URL
\r
171 function reset_url() {
\r
172 $('#add-url').val('http://').focus();
\r
173 $('#add-keyword').val('');
\r
176 // Increment URL counters
\r
177 function increment() {
\r
178 $('.increment').each(function(){
\r
179 $(this).html( parseInt($(this).html()) + 1);
\r
183 // Decrement URL counters
\r
184 function decrement() {
\r
185 $('.increment').each(function(){
\r
186 $(this).html( parseInt($(this).html()) - 1 );
\r
190 // Change an element text an revert in a smooth pulse. el is an element id like '#copybox h2'
\r
191 function html_pulse( el, newtext ){
\r
192 var oldtext = $(el).html();
\r
193 // Fast pulse to "Copied" and revert
\r
202 "slow", 1, // this fades from 1 to 1: just a 'sleep(1)' actually
\r
204 $(el).fadeTo("normal", 0.01, function(){$(el).html( oldtext ).css('opacity', 1)});
\r