2 $(document).ready(function(){
\r
3 $('#add-url, #add-keyword').keyup(function(e){ if (e.keyCode == 13) {add();} } );
\r
5 $('#new_url_form').attr('action', 'javascript:add();');
\r
7 $('input.text').click(function(){
\r
12 if ($("#tblUrl").tablesorter && $("#tblUrl tr.nourl_found").length != 1) {
\r
13 var order = {'id':0, 'url':1, 'timestamp':2, 'ip':3, 'clicks':4};
\r
14 var order_by = {'asc':0, 'desc':1};
\r
15 var s_by = order[query_string('s_by')];
\r
16 var s_order = order_by[query_string('s_order')];
\r
17 if( s_by == undefined ) {
\r
22 $("#tblUrl").tablesorter({
\r
23 sortList:[[ s_by, s_order ]], // Sort on column #3 (numbering starts at 0)
\r
24 headers: { 5: {sorter: false} }, // no sorter on column #6
\r
25 widgets: ['zebra'] // prettify
\r
32 // Create new link and add to table
\r
34 var newurl = $("#add-url").val();
\r
35 if ( !newurl || newurl == 'http://' || newurl == 'https://' ) {
\r
39 var keyword = $("#add-keyword").val();
\r
40 add_loading("#add-button");
\r
43 {mode:'add', url: newurl, keyword: keyword},
\r
45 if(data.status == 'success') {
\r
46 $('#tblUrl tbody').prepend( data.html ).trigger("update");
\r
47 $('.nourl_found').remove();
\r
52 feedback(data.message, data.status);
\r
53 end_loading("#add-button");
\r
54 end_disable("#add-button");
\r
59 // Display the edition interface
\r
61 add_loading('#actions-'+id+' .button');
\r
62 var keyword = $('#keyword_'+id).val();
\r
65 { mode: "edit_display", keyword: keyword },
\r
67 $("#id-" + id).after( data.html );
\r
68 $("#edit-url-"+ id).focus();
\r
69 end_loading('#actions-'+id+' .button');
\r
75 function remove(id) {
\r
76 if (!confirm('Really delete?')) {
\r
79 var keyword = $('#keyword_'+id).val();
\r
82 { mode: "delete", keyword: keyword },
\r
84 if (data.success == 1) {
\r
85 $("#id-" + id).fadeOut(function(){$(this).remove();zebra_table();});
\r
88 alert('something wrong happened while deleting :/');
\r
94 // Redirect to stat page
\r
95 function stats(link) {
\r
96 window.location=link;
\r
99 // Cancel edition of a link
\r
100 function hide_edit(id) {
\r
101 $("#edit-" + id).fadeOut(200, function(){
\r
102 end_disable('#actions-'+id+' .button');
\r
106 // Save edition of a link
\r
107 function edit_save(id) {
\r
108 add_loading("#edit-close-" + id);
\r
109 var newurl = $("#edit-url-" + id).val();
\r
110 var newkeyword = $("#edit-keyword-" + id).val();
\r
111 var keyword = $('#old_keyword_'+id).val();
\r
112 var www = $('#yourls-site').val();
\r
115 {mode:'edit_save', url: newurl, keyword: keyword, newkeyword: newkeyword },
\r
117 if(data.status == 'success') {
\r
118 $("#url-" + id).html('<a href="' + data.url.url + '" title="' + data.url.url + '">' + data.url.display_url + '</a>');
\r
119 $("#keyword-" + id).html('<a href="' + data.url.shorturl + '" title="' + data.url.shorturl + '">' + data.url.keyword + '</a>');
\r
120 $("#timestamp-" + id).html(data.url.date);
\r
121 $("#edit-" + id).fadeOut(200, function(){
\r
122 $('#tblUrl tbody').trigger("update");
\r
124 $('#keyword_'+id).val( newkeyword );
\r
125 $('#statlink-'+id).attr( 'href', data.url.shorturl+'+' );
\r
127 feedback(data.message, data.status);
\r
128 end_disable("#edit-close-" + id);
\r
129 end_loading("#edit-close-" + id);
\r
130 end_disable("#edit-button-" + id);
\r
131 end_disable("#delete-button-" + id);
\r
136 // Unused for now since HTTP Auth sucks donkeys.
\r
137 function logout() {
\r
140 url: "index_ajax.php",
\r
141 data: {mode:'logout'},
\r
142 success: function() {
\r
143 window.parent.location.href = window.parent.location.href;
\r
148 // Begin the spinning animation & disable a button
\r
149 function add_loading(el) {
\r
150 $(el).attr("disabled", "disabled").addClass('disabled').addClass('loading');
\r
153 // End spinning animation
\r
154 function end_loading(el) {
\r
155 $(el).removeClass('loading');
\r
158 // Un-disable an element
\r
159 function end_disable(el) {
\r
160 $(el).removeAttr("disabled").removeClass('disabled');
\r
163 // Prettify table with odd & even rows
\r
164 function zebra_table() {
\r
165 $("#tblUrl tbody tr:even").removeClass('odd').addClass('even');
\r
166 $("#tblUrl tbody tr:odd").removeClass('even').addClass('odd');
\r
167 $('#tblUrl tbody').trigger("update");
\r
170 // Update feedback message
\r
171 function feedback(msg, type) {
\r
172 var span = (type == 'fail') ? '<span class="fail">' : '<span>' ;
\r
173 var delay = (type == 'fail') ? 2500 : 1000 ;
\r
174 $('#feedback').html(span + msg + '</span>').fadeIn(200,function(){
\r
175 $(this).animate({'opacity':1}, delay, function() {
\r
176 $(this).fadeOut(800);
\r
181 // Ready to add another URL
\r
182 function reset_url() {
\r
183 $('#add-url').val('http://').focus();
\r
184 $('#add-keyword').val('');
\r
187 // Increment URL counters
\r
188 function increment() {
\r
189 $('.increment').each(function(){
\r
190 $(this).html( parseInt($(this).html()) + 1);
\r
194 // Decrement URL counters
\r
195 function decrement() {
\r
196 $('.increment').each(function(){
\r
197 $(this).html( parseInt($(this).html()) - 1 );
\r
201 // Get query string
\r
202 function query_string( key ) {
\r
204 key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
\r
205 var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
\r
206 var qs = regex.exec(window.location.href);
\r