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
6 if ($("#tblUrl tr.nourl_found").length != 1) {
\r
7 $("#tblUrl").tablesorter({
\r
8 sortList:[[3,1]], // Sort on column #3 (numbering starts at 0)
\r
9 headers: { 6: {sorter: false} }, // no sorter on column #6
\r
10 widgets: ['zebra'] // prettify
\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
22 var keyword = $("#add-keyword").val();
\r
23 add_loading("#add-button");
\r
26 {mode:'add', url: newurl, keyword: keyword},
\r
28 if(data.status == 'success') {
\r
29 $('#tblUrl tbody').prepend( data.html ).trigger("update");
\r
30 $('.nourl_found').remove();
\r
35 feedback(data.message, data.status);
\r
36 end_loading("#add-button");
\r
37 end_disable("#add-button");
\r
42 // Display the edition interface
\r
44 add_loading("#edit-button-" + id);
\r
45 add_loading("#delete-button-" + id);
\r
48 { mode: "edit_display", id: id },
\r
50 $("#id-" + id).after( data.html );
\r
51 $("#edit-url-"+ id).focus();
\r
52 end_loading("#edit-button-" + id);
\r
53 end_loading("#delete-button-" + id);
\r
59 function remove(id) {
\r
60 if (!confirm('Really delete?')) {
\r
65 { mode: "delete", id: id },
\r
67 if (data.success == 1) {
\r
68 $("#id-" + id).fadeOut(function(){$(this).remove();zebra_table();});
\r
70 alert('something wrong happened while deleting :/');
\r
76 // Cancel edition of a link
\r
77 function hide_edit(id) {
\r
78 $("#edit-" + id).fadeOut(200, function(){
\r
79 end_disable("#edit-button-" + id);
\r
80 end_disable("#delete-button-" + id);
\r
84 // Save edition of a link
\r
85 function edit_save(id) {
\r
86 add_loading("#edit-close-" + id);
\r
87 var newurl = $("#edit-url-" + id).val();
\r
88 var newid = $("#edit-id-" + id).val();
\r
91 {mode:'edit_save', url: newurl, id: id, newid: newid },
\r
93 if(data.status == 'success') {
\r
94 $("#url-" + id).html('<a href="' + data.url.url + '" title="' + data.url.url + '">' + data.url.url + '</a>');
\r
95 $("#keyword-" + id).html(data.url.keyword);
\r
96 $("#shorturl-" + id).html('<a href="' + data.url.shorturl + '" title="' + data.url.shorturl + '">' + data.url.shorturl + '</a>');
\r
97 $("#timestamp-" + id).html(data.url.date);
\r
98 $("#edit-" + id).fadeOut(200, function(){
\r
99 $('#tblUrl tbody').trigger("update");
\r
102 feedback(data.message, data.status);
\r
103 end_disable("#edit-close-" + id);
\r
104 end_loading("#edit-close-" + id);
\r
105 end_disable("#edit-button-" + id);
\r
106 end_disable("#delete-button-" + id);
\r
111 // Unused for now since HTTP Auth sucks donkeys.
\r
112 function logout() {
\r
115 url: "index_ajax.php",
\r
116 data: {mode:'logout'},
\r
117 success: function() {
\r
118 window.parent.location.href = window.parent.location.href;
\r
123 // Begin the spinning animation & disable a button
\r
124 function add_loading(el) {
\r
125 $(el).attr("disabled", "disabled").addClass('disabled').addClass('loading');
\r
128 // End spinning animation
\r
129 function end_loading(el) {
\r
130 $(el).removeClass('loading');
\r
133 // Un-disable an element
\r
134 function end_disable(el) {
\r
135 $(el).removeAttr("disabled").removeClass('disabled');
\r
138 // Prettify table with odd & even rows
\r
139 function zebra_table() {
\r
140 $("#tblUrl tbody tr:even").removeClass('odd').addClass('even');
\r
141 $("#tblUrl tbody tr:odd").removeClass('even').addClass('odd');
\r
142 $('#tblUrl tbody').trigger("update");
\r
145 // Update feedback message
\r
146 function feedback(msg, type) {
\r
147 var span = (type == 'fail') ? '<span class="fail">' : '<span>' ;
\r
148 var delay = (type == 'fail') ? 2500 : 1000 ;
\r
149 $('#feedback').html(span + msg + '</span>').fadeIn(200,function(){
\r
150 $(this).animate({'opacity':1}, delay, function() {
\r
151 $(this).fadeOut(800);
\r
156 // Ready to add another URL
\r
157 function reset_url() {
\r
158 $('#add-url').val('http://').focus();
\r
159 $('#add-keyword').val('');
\r
162 // Increment URL counters
\r
163 function increment() {
\r
164 $('.increment').each(function(){
\r
165 $(this).html( parseInt($(this).html()) + 1);
\r