Upload files to 'js'
This commit is contained in:
parent
e9d431635d
commit
a1ff8c5171
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,168 @@
|
|||
// Handle .hide-if-no-js and .hide-if-js styles
|
||||
$(document).ready(function(){
|
||||
$('.hide-if-no-js').removeClass('hide-if-no-js');
|
||||
$('.hide-if-js').hide();
|
||||
});
|
||||
|
||||
// Change an element text an revert in a smooth pulse. el is an element id like '#copybox h2'
|
||||
function html_pulse( el, newtext ){
|
||||
var oldtext = $(el).html();
|
||||
// Fast pulse to "Copied" and revert
|
||||
$(el).fadeTo(
|
||||
"normal",
|
||||
0.01,
|
||||
function(){
|
||||
$(el)
|
||||
.html( newtext )
|
||||
.css('opacity', 1)
|
||||
.fadeTo(
|
||||
"slow", 1, // this fades from 1 to 1: just a 'sleep(1)' actually
|
||||
function(){
|
||||
$(el).fadeTo("normal", 0.01, function(){$(el).html( oldtext ).css('opacity', 1)});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Update feedback message
|
||||
function feedback(msg, type, delay) {
|
||||
closeme = ( type == 'fail' || type == 'error' ) ? true : false;
|
||||
delay = delay || ( closeme == true ? 10000 : 3500 );
|
||||
$.notifyBar({
|
||||
html: '<span>'+msg+'</span>',
|
||||
delay: delay,
|
||||
animationSpeed: "normal",
|
||||
close: closeme,
|
||||
cls: type
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
// Unused for now
|
||||
function logout() {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: {action:'logout'},
|
||||
success: function() {
|
||||
window.parent.location.href = window.parent.location.href;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Begin the spinning animation & disable a button
|
||||
function add_loading(el) {
|
||||
$(el).attr("disabled", "disabled").addClass('disabled').addClass('loading');
|
||||
}
|
||||
|
||||
// End spinning animation
|
||||
function end_loading(el) {
|
||||
$(el).removeClass('loading');
|
||||
}
|
||||
|
||||
// Un-disable an element
|
||||
function end_disable(el) {
|
||||
$(el).removeAttr("disabled").removeClass('disabled');
|
||||
}
|
||||
|
||||
// Trim long string
|
||||
function trim_long_string( string, length) {
|
||||
var newstring = string;
|
||||
length = length || 60;
|
||||
if ( newstring.length > length ) {
|
||||
newstring = newstring.substr(0, (length - 5) ) + '[...]';
|
||||
}
|
||||
return newstring;
|
||||
}
|
||||
|
||||
// Get the var=xxx from a query string
|
||||
function get_var_from_query( url, varname, default_val ) {
|
||||
if( varname == undefined ) {
|
||||
varname = 'nonce';
|
||||
}
|
||||
if( default_val == undefined ) {
|
||||
default_val = '';
|
||||
}
|
||||
|
||||
// Split the url on '?' and get only the params (which is element 1)
|
||||
url = url.split('?')[1];
|
||||
// Now split those params on '&' so we can get each one individually (Ex. param_var=param_value)
|
||||
url = url.split('&');
|
||||
// Now we have to find the varname in that array using methods that IE likes (Curse you IE!!!)
|
||||
var i=0;
|
||||
for( i=0; i<url.length; i++ ){
|
||||
// So split the first param elemment on '=' and check the param_var to see if it matches varname (element 0)
|
||||
if( url[i].split('=')[0] == varname ){
|
||||
// If it matches we want to return the param_value
|
||||
return url[i].split('=')[1];
|
||||
}
|
||||
}
|
||||
|
||||
// If we didn't find anything then we just return the default_val
|
||||
return default_val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Jquery Cookie plugin
|
||||
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
|
||||
* Dual licensed under the MIT and GPL licenses:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* Available at http://plugins.jquery.com/files/jquery.cookie.js.txt
|
||||
*/
|
||||
jQuery.cookie = function(name, value, options) {
|
||||
if (typeof value != 'undefined') { // name and value given, set cookie
|
||||
options = options || {};
|
||||
if (value === null) {
|
||||
value = '';
|
||||
options.expires = -1;
|
||||
}
|
||||
var expires = '';
|
||||
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
|
||||
var date;
|
||||
if (typeof options.expires == 'number') {
|
||||
date = new Date();
|
||||
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
|
||||
} else {
|
||||
date = options.expires;
|
||||
}
|
||||
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
|
||||
}
|
||||
// CAUTION: Needed to parenthesize options.path and options.domain
|
||||
// in the following expressions, otherwise they evaluate to undefined
|
||||
// in the packed version for some reason...
|
||||
var path = options.path ? '; path=' + (options.path) : '';
|
||||
var domain = options.domain ? '; domain=' + (options.domain) : '';
|
||||
var secure = options.secure ? '; secure' : '';
|
||||
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
|
||||
} else { // only name given, get cookie
|
||||
var cookieValue = null;
|
||||
if (document.cookie && document.cookie != '') {
|
||||
var cookies = document.cookie.split(';');
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var cookie = jQuery.trim(cookies[i]);
|
||||
// Does this cookie string begin with the name we want?
|
||||
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
};
|
||||
|
||||
// Split a URL into protocol, slashes and the rest
|
||||
function get_protocol_slashes_and_rest( url ) {
|
||||
if( ups=url.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ ) ) {
|
||||
ups=ups[0];
|
||||
var ur=url.split(new RegExp(ups))[1];
|
||||
var ups=ups.split(/\:/);
|
||||
return { protocol: ups[0]+':', slashes: ups[1], rest: ur };
|
||||
} else {
|
||||
return { protocol: '', slashes: '', rest: url };;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
$(document).ready(function(){
|
||||
$('ul.toggle_display').css('display', 'block');
|
||||
$('.tab h2').css('display','none');
|
||||
|
||||
// Toggle tabs
|
||||
$('ul.toggle_display li a').click(function(){
|
||||
var target = $(this).attr('href').replace('#', ''); // 'stat_tab_location'
|
||||
var divs = target.split('_')[1]; // 'tab'
|
||||
$('div.'+divs).css('display', 'none');
|
||||
$('div#'+target).css('display', 'block');
|
||||
$('ul.stat_'+divs+' li a').removeClass('selected');
|
||||
$('ul.stat_'+divs+' li a[href="#'+target+'"]').addClass('selected').css('outline', 'none').blur();
|
||||
return false;
|
||||
});
|
||||
|
||||
// Activate main tab
|
||||
if (location.hash) {
|
||||
$('#tabs ul#headers li a[href="'+location.hash+'"]').click();
|
||||
} else {
|
||||
$('#tabs ul#headers li a:first').click();
|
||||
}
|
||||
|
||||
// Activate first line graph
|
||||
$('#stats_lines li a:first').click();
|
||||
|
||||
// Prettify list
|
||||
$('#historical_clicks li:odd').css('background', '#E3F3FF');
|
||||
|
||||
// Toggle detail lists
|
||||
$('a.details').click(function(){
|
||||
var target = $(this).attr('id').replace('more_', 'details_');
|
||||
$('#'+target).toggle();
|
||||
return false;
|
||||
});
|
||||
|
||||
// If an image src is erroneous (404 or anything) replace it with a transparent gif
|
||||
$('.fix_images').each(function(i,img) {
|
||||
$(img).on("error", function(){
|
||||
$(img).attr('src', 'images/blank.gif');
|
||||
});
|
||||
});
|
||||
|
||||
// If we have the zeroclipboard thing, init it when Share Tab is displayed
|
||||
$('#tabs ul#headers li a[href="#stat_tab_share"]').click(function(){
|
||||
init_clipboard();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,232 @@
|
|||
// Init some stuff
|
||||
$(document).ready(function(){
|
||||
$('#add-url, #add-keyword').keypress(function(e){
|
||||
if (e.which == 13) {add_link();}
|
||||
});
|
||||
add_link_reset();
|
||||
$('#new_url_form').attr('action', 'javascript:add_link();');
|
||||
|
||||
$('input.text').focus(function(){
|
||||
$(this).select();
|
||||
});
|
||||
|
||||
// this one actually has little impact, the .hasClass('disabled') in each edit_link_display(), remove() etc... fires faster
|
||||
$(document).on( 'click', 'a.button', function() {
|
||||
if( $(this).hasClass('disabled') ) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// When Searching, explode search text in pieces -- see split_search_text_before_search()
|
||||
$('#filter_form').submit( function(){
|
||||
split_search_text_before_search();
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
// Create new link and add to table
|
||||
function add_link() {
|
||||
if( $('#add-button').hasClass('disabled') ) {
|
||||
return false;
|
||||
}
|
||||
var newurl = $("#add-url").val();
|
||||
var nonce = $("#nonce-add").val();
|
||||
if ( !newurl || newurl == 'http://' || newurl == 'https://' ) {
|
||||
return;
|
||||
}
|
||||
var keyword = $("#add-keyword").val();
|
||||
add_loading("#add-button");
|
||||
$.getJSON(
|
||||
ajaxurl,
|
||||
{action:'add', url: newurl, keyword: keyword, nonce: nonce},
|
||||
function(data){
|
||||
if(data.status == 'success') {
|
||||
$('#main_table tbody').prepend( data.html ).trigger("update");
|
||||
$('#nourl_found').css('display', 'none');
|
||||
zebra_table();
|
||||
increment_counter();
|
||||
toggle_share_fill_boxes( data.url.url, data.shorturl, data.url.title );
|
||||
}
|
||||
|
||||
add_link_reset();
|
||||
end_loading("#add-button");
|
||||
end_disable("#add-button");
|
||||
|
||||
feedback(data.message, data.status);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function toggle_share_fill_boxes( url, shorturl, title ) {
|
||||
$('#copylink').val( shorturl );
|
||||
$('#titlelink').val( title );
|
||||
$('#origlink').attr( 'href', url ).html( url );
|
||||
$('#statlink').attr( 'href', shorturl+'+' ).html( shorturl+'+' );
|
||||
var tweet = ( title ? title + ' ' + shorturl : shorturl );
|
||||
$('#tweet_body').val( tweet ).keypress();
|
||||
$('#shareboxes').slideDown( '300', function(){ init_clipboard(); } ); // clipboard re-initialized after slidedown to make sure the invisible Flash element is correctly positionned
|
||||
$('#tweet_body').keypress();
|
||||
}
|
||||
|
||||
// Display the edition interface
|
||||
function edit_link_display(id) {
|
||||
if( $('#edit-button-'+id).hasClass('disabled') ) {
|
||||
return false;
|
||||
}
|
||||
add_loading('#actions-'+id+' .button');
|
||||
var keyword = $('#keyword_'+id).val();
|
||||
var nonce = get_var_from_query( $('#edit-button-'+id).attr('href'), 'nonce' );
|
||||
$.getJSON(
|
||||
ajaxurl,
|
||||
{ action: "edit_display", keyword: keyword, nonce: nonce, id: id },
|
||||
function(data){
|
||||
$("#id-" + id).after( data.html );
|
||||
$("#edit-url-"+ id).focus();
|
||||
end_loading('#actions-'+id+' .button');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Delete a link
|
||||
function remove_link(id) {
|
||||
if( $('#delete-button-'+id).hasClass('disabled') ) {
|
||||
return false;
|
||||
}
|
||||
if (!confirm('Really delete?')) {
|
||||
return;
|
||||
}
|
||||
var keyword = $('#keyword_'+id).val();
|
||||
var nonce = get_var_from_query( $('#delete-button-'+id).attr('href'), 'nonce' );
|
||||
$.getJSON(
|
||||
ajaxurl,
|
||||
{ action: "delete", keyword: keyword, nonce: nonce, id: id },
|
||||
function(data){
|
||||
if (data.success == 1) {
|
||||
$("#id-" + id).fadeOut(function(){
|
||||
$(this).remove();
|
||||
if( $('#main_table tbody tr').length == 1 ) {
|
||||
$('#nourl_found').css('display', '');
|
||||
}
|
||||
|
||||
zebra_table();
|
||||
});
|
||||
decrement_counter();
|
||||
decrease_total_clicks( id );
|
||||
} else {
|
||||
alert('something wrong happened while deleting :/');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Redirect to stat page
|
||||
function go_stats(link) {
|
||||
window.location=link;
|
||||
}
|
||||
|
||||
// Cancel edition of a link
|
||||
function edit_link_hide(id) {
|
||||
$("#edit-" + id).fadeOut(200, function(){
|
||||
$("#edit-" + id).remove();
|
||||
end_disable('#actions-'+id+' .button');
|
||||
});
|
||||
}
|
||||
|
||||
// Save edition of a link
|
||||
function edit_link_save(id) {
|
||||
add_loading("#edit-close-" + id);
|
||||
var newurl = $("#edit-url-" + id).val();
|
||||
var newkeyword = $("#edit-keyword-" + id).val();
|
||||
var title = $("#edit-title-" + id).val();
|
||||
var keyword = $('#old_keyword_'+id).val();
|
||||
var nonce = $('#nonce_'+id).val();
|
||||
var www = $('#yourls-site').val();
|
||||
$.getJSON(
|
||||
ajaxurl,
|
||||
{action:'edit_save', url: newurl, id: id, keyword: keyword, newkeyword: newkeyword, title: title, nonce: nonce },
|
||||
function(data){
|
||||
if(data.status == 'success') {
|
||||
|
||||
if( data.url.title != '' ) {
|
||||
var display_link = '<a href="' + data.url.url + '" title="' + data.url.title + '">' + data.url.display_title + '</a><br/><small><a href="' + data.url.url + '">' + data.url.display_url + '</a></small>';
|
||||
} else {
|
||||
var display_link = '<a href="' + data.url.url + '" title="' + data.url.url + '">' + data.url.display_url + '</a>';
|
||||
}
|
||||
|
||||
$("#url-" + id).html(display_link);
|
||||
$("#keyword-" + id).html('<a href="' + data.url.shorturl + '" title="' + data.url.shorturl + '">' + data.url.keyword + '</a>');
|
||||
$("#edit-" + id).fadeOut(200, function(){
|
||||
$("#edit-" + id).remove();
|
||||
$('#main_table tbody').trigger("update");
|
||||
});
|
||||
$('#keyword_'+id).val( newkeyword );
|
||||
$('#statlink-'+id).attr( 'href', data.url.shorturl+'+' );
|
||||
}
|
||||
feedback(data.message, data.status);
|
||||
end_loading("#edit-close-" + id);
|
||||
end_disable("#edit-close-" + id);
|
||||
if(data.status == 'success') {
|
||||
end_disable("#actions-" + id + ' .button');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Prettify table with odd & even rows
|
||||
function zebra_table() {
|
||||
$("#main_table tbody tr:even").removeClass('odd').addClass('even');
|
||||
$("#main_table tbody tr:odd").removeClass('even').addClass('odd');
|
||||
$('#main_table tbody').trigger("update");
|
||||
}
|
||||
|
||||
// Ready to add another URL
|
||||
function add_link_reset() {
|
||||
$('#add-url').val('').focus();
|
||||
$('#add-keyword').val('');
|
||||
}
|
||||
|
||||
// Increment URL counters
|
||||
function increment_counter() {
|
||||
$('.increment').each(function(){
|
||||
$(this).html( parseInt($(this).html()) + 1);
|
||||
});
|
||||
}
|
||||
|
||||
// Decrement URL counters
|
||||
function decrement_counter() {
|
||||
$('.increment').each(function(){
|
||||
$(this).html( parseInt($(this).html()) - 1 );
|
||||
});
|
||||
}
|
||||
|
||||
// Decrease number of total clicks
|
||||
function decrease_total_clicks( id ) {
|
||||
var total_clicks = $("#overall_tracking strong:nth-child(2)");
|
||||
total_clicks.html( parseInt( total_clicks.html() ) - parseInt( $('#clicks-' + id).html() ) );
|
||||
}
|
||||
|
||||
// Toggle Share box
|
||||
function toggle_share(id) {
|
||||
if( $('#share-button-'+id).hasClass('disabled') ) {
|
||||
return false;
|
||||
}
|
||||
var link = $('#url-'+id+' a:first');
|
||||
var longurl = link.attr('href');
|
||||
var title = link.attr('title');
|
||||
var shorturl = $('#keyword-'+id+' a:first').attr('href');
|
||||
|
||||
toggle_share_fill_boxes( longurl, shorturl, title );
|
||||
}
|
||||
|
||||
// When "Search" is clicked, split search text to beat servers which don't like query string with "http://"
|
||||
// See https://github.com/YOURLS/YOURLS/issues/1576
|
||||
function split_search_text_before_search() {
|
||||
// Add 2 hidden fields and populate them with parts of search text
|
||||
$("<input type='hidden' name='search_protocol' />").appendTo('#filter_form');
|
||||
$("<input type='hidden' name='search_slashes' />").appendTo('#filter_form');
|
||||
var search = get_protocol_slashes_and_rest( $('#filter_form input[name=search]').val() );
|
||||
$('#filter_form input[name=search]').val( search.rest );
|
||||
$('#filter_form input[name=search_protocol]').val( search.protocol );
|
||||
$('#filter_form input[name=search_slashes]').val( search.slashes );
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,319 @@
|
|||
/**
|
||||
the script only works on "input [type=text]"
|
||||
http://teddevito.com/demos/calendar.php
|
||||
**/
|
||||
|
||||
// don't declare anything out here in the global namespace
|
||||
|
||||
(function($) { // create private scope (inside you can use $ instead of jQuery)
|
||||
|
||||
// functions and vars declared here are effectively 'singletons'. there will be only a single
|
||||
// instance of them. so this is a good place to declare any immutable items or stateless
|
||||
// functions. for example:
|
||||
|
||||
var today = new Date(); // used in defaults
|
||||
var months = 'January,February,March,April,May,June,July,August,September,October,November,December'.split(',');
|
||||
var months = l10n_cal_month;
|
||||
var monthlengths = '31,28,31,30,31,30,31,31,30,31,30,31'.split(',');
|
||||
var dateRegEx = /^\d{1,2}\/\d{1,2}\/\d{2}|\d{4}$/;
|
||||
var yearRegEx = /^\d{4,4}$/;
|
||||
|
||||
// next, declare the plugin function
|
||||
$.fn.simpleDatepicker = function(options) {
|
||||
|
||||
// functions and vars declared here are created each time your plugn function is invoked
|
||||
|
||||
// you could probably refactor your 'build', 'load_month', etc, functions to be passed
|
||||
// the DOM element from below
|
||||
|
||||
var opts = jQuery.extend({}, jQuery.fn.simpleDatepicker.defaults, options);
|
||||
|
||||
// replaces a date string with a date object in opts.startdate and opts.enddate, if one exists
|
||||
// populates two new properties with a ready-to-use year: opts.startyear and opts.endyear
|
||||
|
||||
setupYearRange();
|
||||
/** extracts and setup a valid year range from the opts object **/
|
||||
function setupYearRange () {
|
||||
|
||||
var startyear, endyear;
|
||||
if (opts.startdate.constructor == Date) {
|
||||
startyear = opts.startdate.getFullYear();
|
||||
} else if (opts.startdate) {
|
||||
if (yearRegEx.test(opts.startdate)) {
|
||||
startyear = opts.startdate;
|
||||
} else if (dateRegEx.test(opts.startdate)) {
|
||||
opts.startdate = new Date(opts.startdate);
|
||||
startyear = opts.startdate.getFullYear();
|
||||
} else {
|
||||
startyear = today.getFullYear();
|
||||
}
|
||||
} else {
|
||||
startyear = today.getFullYear();
|
||||
}
|
||||
opts.startyear = startyear;
|
||||
|
||||
if (opts.enddate.constructor == Date) {
|
||||
endyear = opts.enddate.getFullYear();
|
||||
} else if (opts.enddate) {
|
||||
if (yearRegEx.test(opts.enddate)) {
|
||||
endyear = opts.enddate;
|
||||
} else if (dateRegEx.test(opts.enddate)) {
|
||||
opts.enddate = new Date(opts.enddate);
|
||||
endyear = opts.enddate.getFullYear();
|
||||
} else {
|
||||
endyear = today.getFullYear();
|
||||
}
|
||||
} else {
|
||||
endyear = today.getFullYear();
|
||||
}
|
||||
opts.endyear = endyear;
|
||||
}
|
||||
|
||||
/** HTML factory for the actual datepicker table element **/
|
||||
// has to read the year range so it can setup the correct years in our HTML <select>
|
||||
function newDatepickerHTML () {
|
||||
|
||||
var years = [];
|
||||
|
||||
// process year range into an array
|
||||
for (var i = 0; i <= opts.endyear - opts.startyear; i ++) years[i] = opts.startyear + i;
|
||||
|
||||
// build the table structure
|
||||
var table = jQuery('<table class="datepicker" cellpadding="0" cellspacing="0"></table>');
|
||||
table.append('<thead></thead>');
|
||||
table.append('<tfoot></tfoot>');
|
||||
table.append('<tbody></tbody>');
|
||||
|
||||
// month select field
|
||||
var monthselect = '<select name="month">';
|
||||
for (var i in l10n_cal_month) monthselect += '<option value="'+i+'">'+l10n_cal_month[i]+'</option>';
|
||||
monthselect += '</select>';
|
||||
|
||||
// year select field
|
||||
var yearselect = '<select name="year">';
|
||||
for (var i in years) yearselect += '<option>'+years[i]+'</option>';
|
||||
yearselect += '</select>';
|
||||
|
||||
jQuery("thead",table).append('<tr class="controls"><th colspan="7"><span class="prevMonth">«</span> '+monthselect+yearselect+' <span class="nextMonth">»</span></th></tr>');
|
||||
jQuery("thead",table).append('<tr class="days"><th>'+l10n_cal_days[0]+'</th><th>'+l10n_cal_days[1]+'</th><th>'+l10n_cal_days[2]+'</th><th>'+l10n_cal_days[3]+'</th><th>'+l10n_cal_days[4]+'</th><th>'+l10n_cal_days[5]+'</th><th>'+l10n_cal_days[6]+'</th></tr>');
|
||||
jQuery("tfoot",table).append('<tr><td colspan="2"><span class="today">'+l10n_cal_today+'</span></td><td colspan="3"> </td><td colspan="2"><span class="close">'+l10n_cal_close+'</span></td></tr>');
|
||||
for (var i = 0; i < 6; i++) jQuery("tbody",table).append('<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>');
|
||||
return table;
|
||||
}
|
||||
|
||||
/** get the real position of the input (well, anything really) **/
|
||||
//http://www.quirksmode.org/js/findpos.html
|
||||
function findPosition (obj) {
|
||||
var curleft = curtop = 0;
|
||||
if (obj.offsetParent) {
|
||||
do {
|
||||
curleft += obj.offsetLeft;
|
||||
curtop += obj.offsetTop;
|
||||
} while (obj = obj.offsetParent);
|
||||
return [curleft,curtop];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** load the initial date and handle all date-navigation **/
|
||||
// initial calendar load (e is null)
|
||||
// prevMonth & nextMonth buttons
|
||||
// onchange for the select fields
|
||||
function loadMonth (e, el, datepicker, chosendate) {
|
||||
|
||||
// reference our years for the nextMonth and prevMonth buttons
|
||||
var mo = jQuery("select[name=month]", datepicker).get(0).selectedIndex;
|
||||
var yr = jQuery("select[name=year]", datepicker).get(0).selectedIndex;
|
||||
var yrs = jQuery("select[name=year] option", datepicker).get().length;
|
||||
|
||||
// first try to process buttons that may change the month we're on
|
||||
if (e && jQuery(e.target).hasClass('prevMonth')) {
|
||||
if (0 == mo && yr) {
|
||||
yr -= 1; mo = 11;
|
||||
jQuery("select[name=month]", datepicker).get(0).selectedIndex = 11;
|
||||
jQuery("select[name=year]", datepicker).get(0).selectedIndex = yr;
|
||||
} else {
|
||||
mo -= 1;
|
||||
jQuery("select[name=month]", datepicker).get(0).selectedIndex = mo;
|
||||
}
|
||||
} else if (e && jQuery(e.target).hasClass('nextMonth')) {
|
||||
if (11 == mo && yr + 1 < yrs) {
|
||||
yr += 1; mo = 0;
|
||||
jQuery("select[name=month]", datepicker).get(0).selectedIndex = 0;
|
||||
jQuery("select[name=year]", datepicker).get(0).selectedIndex = yr;
|
||||
} else {
|
||||
mo += 1;
|
||||
jQuery("select[name=month]", datepicker).get(0).selectedIndex = mo;
|
||||
}
|
||||
}
|
||||
|
||||
// maybe hide buttons
|
||||
if (0 == mo && !yr) jQuery("span.prevMonth", datepicker).hide();
|
||||
else jQuery("span.prevMonth", datepicker).show();
|
||||
if (yr + 1 == yrs && 11 == mo) jQuery("span.nextMonth", datepicker).hide();
|
||||
else jQuery("span.nextMonth", datepicker).show();
|
||||
|
||||
// clear the old cells
|
||||
var cells = jQuery("tbody td", datepicker).unbind().empty().removeClass('date');
|
||||
|
||||
// figure out what month and year to load
|
||||
var m = jQuery("select[name=month]", datepicker).val();
|
||||
var y = jQuery("select[name=year]", datepicker).val();
|
||||
var d = new Date(y, m, 1);
|
||||
var startindex = d.getDay();
|
||||
var numdays = monthlengths[m];
|
||||
|
||||
// http://en.wikipedia.org/wiki/Leap_year
|
||||
if (1 == m && ((y%4 == 0 && y%100 != 0) || y%400 == 0)) numdays = 29;
|
||||
|
||||
// test for end dates (instead of just a year range)
|
||||
if (opts.startdate.constructor == Date) {
|
||||
var startMonth = opts.startdate.getMonth();
|
||||
var startDate = opts.startdate.getDate();
|
||||
}
|
||||
if (opts.enddate.constructor == Date) {
|
||||
var endMonth = opts.enddate.getMonth();
|
||||
var endDate = opts.enddate.getDate();
|
||||
}
|
||||
|
||||
// walk through the index and populate each cell, binding events too
|
||||
for (var i = 0; i < numdays; i++) {
|
||||
|
||||
var cell = jQuery(cells.get(i+startindex)).removeClass('chosen');
|
||||
|
||||
// test that the date falls within a range, if we have a range
|
||||
if (
|
||||
(yr || ((!startDate && !startMonth) || ((i+1 >= startDate && mo == startMonth) || mo > startMonth))) &&
|
||||
(yr + 1 < yrs || ((!endDate && !endMonth) || ((i+1 <= endDate && mo == endMonth) || mo < endMonth)))) {
|
||||
|
||||
cell
|
||||
.text(i+1)
|
||||
.addClass('date')
|
||||
.hover(
|
||||
function () { jQuery(this).addClass('over'); },
|
||||
function () { jQuery(this).removeClass('over'); })
|
||||
.click(function () {
|
||||
var chosenDateObj = new Date(jQuery("select[name=year]", datepicker).val(), jQuery("select[name=month]", datepicker).val(), jQuery(this).text());
|
||||
closeIt(el, datepicker, chosenDateObj);
|
||||
});
|
||||
|
||||
// highlight the previous chosen date
|
||||
if (i+1 == chosendate.getDate() && m == chosendate.getMonth() && y == chosendate.getFullYear()) cell.addClass('chosen');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** closes the datepicker **/
|
||||
// sets the currently matched input element's value to the date, if one is available
|
||||
// remove the table element from the DOM
|
||||
// indicate that there is no datepicker for the currently matched input element
|
||||
function closeIt (el, datepicker, dateObj) {
|
||||
if (dateObj && dateObj.constructor == Date)
|
||||
el.val(jQuery.fn.simpleDatepicker.formatOutput(dateObj));
|
||||
datepicker.remove();
|
||||
datepicker = null;
|
||||
jQuery.data(el.get(0), "simpleDatepicker", { hasDatepicker : false });
|
||||
}
|
||||
|
||||
// iterate the matched nodeset
|
||||
return this.each(function() {
|
||||
|
||||
// functions and vars declared here are created for each matched element. so if
|
||||
// your functions need to manage or access per-node state you can defined them
|
||||
// here and use $this to get at the DOM element
|
||||
|
||||
if ( jQuery(this).is('input') && 'text' == jQuery(this).attr('type')) {
|
||||
|
||||
var datepicker;
|
||||
jQuery.data(jQuery(this).get(0), "simpleDatepicker", { hasDatepicker : false });
|
||||
|
||||
// open a datepicker on the click event
|
||||
jQuery(this).click(function (ev) {
|
||||
|
||||
var $this = jQuery(ev.target);
|
||||
|
||||
if (false == jQuery.data($this.get(0), "simpleDatepicker").hasDatepicker) {
|
||||
|
||||
// store data telling us there is already a datepicker
|
||||
jQuery.data($this.get(0), "simpleDatepicker", { hasDatepicker : true });
|
||||
|
||||
// validate the form's initial content for a date
|
||||
var initialDate = $this.val();
|
||||
|
||||
if (initialDate && dateRegEx.test(initialDate)) {
|
||||
var chosendate = new Date(initialDate);
|
||||
} else if (opts.chosendate.constructor == Date) {
|
||||
var chosendate = opts.chosendate;
|
||||
} else if (opts.chosendate) {
|
||||
var chosendate = new Date(opts.chosendate);
|
||||
} else {
|
||||
var chosendate = today;
|
||||
}
|
||||
|
||||
// insert the datepicker in the DOM
|
||||
datepicker = newDatepickerHTML();
|
||||
jQuery("body").prepend(datepicker);
|
||||
|
||||
// position the datepicker
|
||||
var elPos = findPosition($this.get(0));
|
||||
var x = (parseInt(opts.x) ? parseInt(opts.x) : 0) + elPos[0];
|
||||
var y = (parseInt(opts.y) ? parseInt(opts.y) : 0) + elPos[1];
|
||||
jQuery(datepicker).css({ position: 'absolute', left: x, top: y });
|
||||
|
||||
// bind events to the table controls
|
||||
jQuery("span", datepicker).css("cursor","pointer");
|
||||
jQuery("select", datepicker).bind('change', function () { loadMonth (null, $this, datepicker, chosendate); });
|
||||
jQuery("span.prevMonth", datepicker).click(function (e) { loadMonth (e, $this, datepicker, chosendate); });
|
||||
jQuery("span.nextMonth", datepicker).click(function (e) { loadMonth (e, $this, datepicker, chosendate); });
|
||||
jQuery("span.today", datepicker).click(function () { closeIt($this, datepicker, new Date()); });
|
||||
jQuery("span.close", datepicker).click(function () { closeIt($this, datepicker); });
|
||||
|
||||
// set the initial values for the month and year select fields
|
||||
// and load the first month
|
||||
jQuery("select[name=month]", datepicker).get(0).selectedIndex = chosendate.getMonth();
|
||||
jQuery("select[name=year]", datepicker).get(0).selectedIndex = Math.max(0, chosendate.getFullYear() - opts.startyear);
|
||||
loadMonth(null, $this, datepicker, chosendate);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// finally, I like to expose default plugin options as public so they can be manipulated. one
|
||||
// way to do this is to add a property to the already-public plugin fn
|
||||
|
||||
jQuery.fn.simpleDatepicker.formatOutput = function (dateObj) {
|
||||
return (dateObj.getMonth() + 1) + "/" + dateObj.getDate() + "/" + dateObj.getFullYear();
|
||||
};
|
||||
|
||||
jQuery.fn.simpleDatepicker.defaults = {
|
||||
// date string matching /^\d{1,2}\/\d{1,2}\/\d{2}|\d{4}$/
|
||||
chosendate : today,
|
||||
|
||||
// date string matching /^\d{1,2}\/\d{1,2}\/\d{2}|\d{4}$/
|
||||
// or four digit year
|
||||
startdate : today.getFullYear(),
|
||||
enddate : today.getFullYear() + 1,
|
||||
|
||||
// offset from the top left corner of the input element
|
||||
x : 1, // must be in px
|
||||
y : 18 // must be in px
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
||||
// Init the form
|
||||
$(document).ready(function(){
|
||||
$('#date_first').simpleDatepicker({startdate: 2005, enddate: 2100});
|
||||
$('#date_second').simpleDatepicker({startdate: 2005, enddate: 2100});
|
||||
|
||||
$('#date_filter').change(function(){
|
||||
var show = $(this).val() == 'between' ? 'inline' : 'none';
|
||||
$('#date_second').css('display', show);
|
||||
$('#date_and').css('display', show);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Notify Bar - jQuery plugin
|
||||
*
|
||||
* Copyright (c) 2009-2010 Dmitri Smirnov
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* Version: 1.2.2
|
||||
*
|
||||
* Project home:
|
||||
* http://www.dmitri.me/blog/notify-bar
|
||||
*/
|
||||
|
||||
/**
|
||||
* param Object
|
||||
*/
|
||||
jQuery.notifyBar = function(settings) {
|
||||
|
||||
(function($) {
|
||||
|
||||
var bar = notifyBarNS = {};
|
||||
notifyBarNS.shown = false;
|
||||
|
||||
if( !settings) {
|
||||
settings = {};
|
||||
}
|
||||
// HTML inside bar
|
||||
notifyBarNS.html = settings.html || "Your message here";
|
||||
|
||||
//How long bar will be delayed, doesn't count animation time.
|
||||
notifyBarNS.delay = settings.delay || 2000;
|
||||
|
||||
//How long notifyBarNS bar will be slided up and down
|
||||
notifyBarNS.animationSpeed = settings.animationSpeed || 200;
|
||||
|
||||
//Use own jquery object usually DIV, or use default
|
||||
notifyBarNS.jqObject = settings.jqObject;
|
||||
|
||||
//Set up own class
|
||||
notifyBarNS.cls = settings.cls || "";
|
||||
|
||||
//close button
|
||||
notifyBarNS.close = settings.close || false;
|
||||
|
||||
if( notifyBarNS.jqObject) {
|
||||
bar = notifyBarNS.jqObject;
|
||||
notifyBarNS.html = bar.html();
|
||||
} else {
|
||||
bar = jQuery("<div></div>")
|
||||
.addClass("jquery-notify-bar")
|
||||
.addClass(notifyBarNS.cls)
|
||||
.attr("id", "__notifyBar");
|
||||
}
|
||||
|
||||
bar.html(notifyBarNS.html).hide();
|
||||
var id = bar.attr("id");
|
||||
switch (notifyBarNS.animationSpeed) {
|
||||
case "slow":
|
||||
asTime = 600;
|
||||
break;
|
||||
case "normal":
|
||||
asTime = 400;
|
||||
break;
|
||||
case "fast":
|
||||
asTime = 200;
|
||||
break;
|
||||
default:
|
||||
asTime = notifyBarNS.animationSpeed;
|
||||
}
|
||||
if( bar != 'object'); {
|
||||
jQuery("body").prepend(bar);
|
||||
}
|
||||
|
||||
// Style close button in CSS file
|
||||
if( notifyBarNS.close) {
|
||||
bar.append(jQuery("<a href='#' class='notify-bar-close'>Close [X]</a>"));
|
||||
jQuery(".notify-bar-close").click(function() {
|
||||
if( bar.attr("id") == "__notifyBar") {
|
||||
jQuery("#" + id).slideUp(asTime, function() { jQuery("#" + id).remove() });
|
||||
} else {
|
||||
jQuery("#" + id).slideUp(asTime);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
bar.slideDown(asTime);
|
||||
|
||||
// If taken from DOM dot not remove just hide
|
||||
if( bar.attr("id") == "__notifyBar") {
|
||||
setTimeout("jQuery('#" + id + "').slideUp(" + asTime +", function() {jQuery('#" + id + "').remove()});", notifyBarNS.delay + asTime);
|
||||
} else {
|
||||
setTimeout("jQuery('#" + id + "').slideUp(" + asTime +", function() {jQuery('#" + id + "')});", notifyBarNS.delay + asTime);
|
||||
}
|
||||
|
||||
})(jQuery) };
|
|
@ -0,0 +1,49 @@
|
|||
$(document).ready(function(){
|
||||
$('#tweet_body').focus();
|
||||
|
||||
$('#tweet_body').keypress(function(){
|
||||
setTimeout( function(){update_share()}, 50 ); // we're delaying, otherwise keypress() always triggers too fast before current key press actually inserts a letter?!! Go figure.
|
||||
});
|
||||
})
|
||||
|
||||
function update_share() {
|
||||
var text = encodeURIComponent( $('#tweet_body').val() );
|
||||
var url = encodeURIComponent( $('#copylink').val() );
|
||||
var tw = 'https://twitter.com/intent/tweet?text='+text;
|
||||
var fb = 'https://www.facebook.com/share.php?u='+url ;
|
||||
$('#share_tw').attr('href', tw);
|
||||
$('#share_fb').attr('href', fb);
|
||||
|
||||
var charcount = parseInt(280 - $('#tweet_body').val().length);
|
||||
$('#charcount')
|
||||
.toggleClass("negative", charcount < 0)
|
||||
.text( charcount );
|
||||
}
|
||||
|
||||
function share(dest) {
|
||||
var url = $('#share_'+dest).attr('href');
|
||||
switch (dest) {
|
||||
case 'fb':
|
||||
//var url = $('#share_fb').attr('href');
|
||||
window.open( url, 'fb','toolbar=no,width=1000,height=550');
|
||||
break;
|
||||
case 'tw':
|
||||
//var url = $('#share_tw').attr('href');
|
||||
window.open(url, 'tw','toolbar=no,width=800,height=550');
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function init_clipboard() {
|
||||
var clipboard = new ClipboardJS('#copylink', {
|
||||
text: function (trigger) {
|
||||
return $(trigger).val();
|
||||
}
|
||||
});
|
||||
|
||||
clipboard.on('success', function () {
|
||||
$('#copylink').select();
|
||||
html_pulse('#copybox h2, #copybox h3', 'Copied!');
|
||||
});
|
||||
};
|
|
@ -0,0 +1,40 @@
|
|||
// Tablesorter comes from own file now.
|
||||
|
||||
var yourls_defaultsort = 2; // default column to sort on (overwrite this inline in page)
|
||||
var yourls_defaultorder = 1; // default order ('asc':0, 'desc':1) to sort on (overwrite this inline in page)
|
||||
|
||||
// Initialise the table to sort
|
||||
$(document).ready(function(){
|
||||
if ($("#main_table").tablesorter && $("#main_table tr#nourl_found").css('display') == 'none') {
|
||||
var order = {'keyword':0, 'url':1, 'timestamp':2, 'ip':3, 'clicks':4};
|
||||
var order_by = {'asc':0, 'desc':1};
|
||||
var sort_by = order[query_string('sort_by')];
|
||||
var sort_order = order_by[query_string('sort_order')];
|
||||
if( sort_by == undefined ) {
|
||||
sort_by = yourls_defaultsort;
|
||||
sort_order = yourls_defaultorder;
|
||||
}
|
||||
|
||||
$("#main_table").tablesorter({
|
||||
textExtraction: {
|
||||
1: function(node, table, cellIndex){return $(node).find("small a").text();} // Sort column "URL" by URL, not by whole cell content
|
||||
},
|
||||
sortList:[[ sort_by, sort_order ]],
|
||||
headers: { 5: {sorter: false} }, // no sorter on column "Actions"
|
||||
widgets: ['zebra'], // prettify, see tr.normal-row and tr.alt-row in tablesorter.css
|
||||
widgetOptions : { zebra : [ "normal-row", "alt-row" ] }
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Get query string
|
||||
function query_string( key ) {
|
||||
default_="";
|
||||
key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
|
||||
var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
|
||||
var qs = regex.exec(window.location.href);
|
||||
if(qs == null)
|
||||
return yourls_defaultsort;
|
||||
else
|
||||
return qs[1];
|
||||
}
|
Loading…
Reference in New Issue