Newer
Older
// Don't change the URL hash for nested tabs or in dialogs
if ($(this).closest('.tab_content, .dialog').length == 0)
$.changeHash($(this).attr('href'), true);
}
if ($tab.length) {
$ul.children('li.active').removeClass('active');
$(this).closest('li').addClass('active');
$container.children('.tab_content').hide();
$tab.fadeIn('fast').show();
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
$.changeHash = function(hash, quiet) {
if (quiet) {
hash = hash.replace( /^#/, '' );
var fx, node = $( '#' + hash );
if ( node.length ) {
node.attr( 'id', '' );
fx = $( '<div></div>' )
.css({
position:'absolute',
visibility:'hidden',
top: $(document).scrollTop() + 'px'
})
.attr( 'id', hash )
.appendTo( document.body );
}
document.location.hash = hash;
if ( node.length ) {
fx.remove();
node.attr( 'id', hash );
}
}
else {
document.location.hash = hash;
}
};
// Forms — submit, stay on same tab
$(document).on('submit', 'form', function() {
if (!!$(this).attr('action') && $(this).attr('action').indexOf('#') == -1)
$(this).attr('action', $(this).attr('action') + window.location.hash);
$(document).on('click', 'a.collaborator, a.collaborators:not(.noclick)', function(e) {
e.preventDefault();
var url = 'ajax.php/'+$(this).attr('href').substr(1);
$.dialog(url, 201, function (xhr) {
var resp = $.parseJSON(xhr.responseText);
$('#t'+resp.id+'-recipients').text(resp.text);
$('.tip_box').remove();
}, {
onshow: function() { $('#user-search').focus(); }
});
return false;
});
// NOTE: getConfig should be global
getConfig = (function() {
return function() {
return dfd;
$(document).on('pjax:click', function(options) {
// Stop all animations
$(document).stop(false, true);
// Remove tips and clear any pending timer
$('.tip, .help-tips, .previewfaq, .preview').each(function() {
if ($(this).data('timer'))
clearTimeout($(this).data('timer'));
});
$('.tip_box, .typeahead.dropdown-menu').remove();
});
$(document).on('pjax:start', function() {
// Cancel save-changes warning banner
$(document).unbind('pjax:beforeSend.changed');
$(window).unbind('beforeunload');
// Close popups
$('.dialog .body').empty().parent().hide();
$.toggleOverlay(false);
$(document).on('pjax:send', function(event) {
if ($('#loadingbar').length !== 0) {
$('#loadingbar').remove();
}
$("body").append("<div id='loadingbar'></div>");
$("#loadingbar").addClass("waiting").append($("<dt/><dd/>"));
// right
$('#loadingbar').stop(false, true).width((50 + Math.random() * 30) + "%");
$('#overlay').css('background-color','white');
$.toggleOverlay(true);
});
$(document).on('pjax:complete', function() {
// right
$("#loadingbar").width("101%").delay(200).fadeOut(400, function() {
$(this).remove();
});
$.toggleOverlay(false);
$('#overlay').removeAttr('style');
// Enable PJAX for the staff interface
if ($.support.pjax) {
$(document).on('click', 'a', function(event) {
var $this = $(this);
if (!$this.hasClass('no-pjax')
&& !$this.closest('.no-pjax').length
&& $this.attr('href').charAt(0) != '#')
$.pjax.click(event, {container: $this.data('pjaxContainer') || $('#pjax-container'), timeout: 30000});
$(document).on('click', '.link:not(a):not(.button)', function(event) {
var $e = $(event.currentTarget);
$('<a>').attr({href: $e.attr('href'), 'class': $e.attr('class')})
.hide()
.insertBefore($e)
.get(0).click(event);
});
// Quick-Add dialogs
$(document).on('change', 'select[data-quick-add]', function() {
var $select = $(this),
selected = $select.find('option:selected'),
type = selected.parent().closest('[data-quick-add]').data('quickAdd');
if (!type || (selected.data('quickAdd') === undefined && selected.val() !== ':new:'))
$.dialog('ajax.php/admin/quick-add/' + type, 201,
function(xhr, data) {
data = JSON.parse(data);
if (data && data.id && data.name) {
var id = data.id;
if (selected.data('idPrefix'))
id = selected.data('idPrefix') + id;
// Quick note interface
$(document).on('click.note', '.quicknote .action.edit-note', function() {
var note = $(this).closest('.quicknote'),
body = note.find('.body'),
T = $('<textarea>').text(body.html());
T.addClass('no-bar small');
body.replaceWith(T);
$.redact(T);
note.find('.action.edit-note').hide();
note.find('.action.save-note').show();
note.find('.action.cancel-edit').show();
$('#new-note-box').hide();
return false;
});
$(document).on('click.note', '.quicknote .action.cancel-edit', function() {
var note = $(this).closest('.quicknote'),
T = note.find('textarea'),
body = $('<div class="body">');
body.load('ajax.php/note/' + note.data('id'), function() {
try { T.redactor('core.destroy'); } catch (e) {}
T.replaceWith(body);
note.find('.action.save-note').hide();
note.find('.action.cancel-edit').hide();
note.find('.action.edit-note').show();
$('#new-note-box').show();
});
return false;
});
$(document).on('click.note', '.quicknote .action.save-note', function() {
var note = $(this).closest('.quicknote'),
T = note.find('textarea');
$.post('ajax.php/note/' + note.data('id'),
function(html) {
var body = $('<div class="body">').html(html);
try { T.redactor('core.destroy'); } catch (e) {}
T.replaceWith(body);
note.find('.action.save-note').hide();
note.find('.action.cancel-edit').hide();
note.find('.action.edit-note').show();
$('#new-note-box').show();
},
'html'
);
return false;
});
$(document).on('click.note', '.quicknote .delete', function() {
var that = $(this),
id = $(this).closest('.quicknote').data('id');
$.ajax('ajax.php/note/' + id, {
type: 'delete',
success: function() {
that.closest('.quicknote').animate(
{height: 0, opacity: 0}, 'slow', function() {
$(this).remove();
});
}
});
return false;
});
$(document).on('click', '#new-note', function() {
var note = $(this).closest('.quicknote'),
T = $('<textarea>'),
button = $('<input type="button">').val(__('Create'));
button.click(function() {
$.post('ajax.php/' + note.data('url'),
{ note: T.redactor('code.get'), no_options: note.hasClass('no-options') },
function(response) {
$(T).redactor('core.destroy').replaceWith(note);
$(response).show('highlight').insertBefore(note.parent());
$('.submit', note.parent()).remove();
},
'html'
);
});
T.addClass('no-bar small');
note.replaceWith(T);
$('<p>').addClass('submit').css('text-align', 'center')
.append(button).appendTo(T.parent());
$.redact(T);
return false;
});
if ($.oststrings && $.oststrings[s])
return $.oststrings[s];
// Thanks, http://stackoverflow.com/a/487049
function addSearchParam(data) {
var kvp = document.location.search.substr(1).replace('+', ' ').split('&');
var i=kvp.length, x, params = {};
while (i--) {
x = kvp[i].split('=');
params[decodeURIComponent(x[0])] = decodeURIComponent(x[1]);
}
//this will reload the page, it's likely better to store this until finished
return $.param($.extend(params, data));
// Periodically adjust relative times
window.relativeAdjust = setInterval(function() {
// Thanks, http://stackoverflow.com/a/7641822/1025836
var prettyDate = function(time) {
var date = new Date((time || "").replace(/-/g, "/").replace(/[TZ]/g, " ")),
diff = (((new Date()).getTime() - date.getTime()) / 1000),
day_diff = Math.floor(diff / 86400);
if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31) return;
return day_diff == 0 && (
diff < 60 && __("just now")
|| diff < 120 && __("about a minute ago")
|| diff < 3600 && __("%d minutes ago").replace('%d', Math.floor(diff/60))
|| diff < 7200 && __("about an hour ago")
|| diff < 86400 && __("%d hours ago").replace('%d', Math.floor(diff/3600))
)
|| day_diff == 1 && __("yesterday")
|| day_diff < 7 && __("%d days ago").replace('%d', day_diff);
// Longer dates don't need to change dynamically
};
$('time.relative[datetime]').each(function() {
var rel = prettyDate($(this).attr('datetime'));
if (rel) $(this).text(rel);
});
}, 20000);
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
// Add 'afterShow' event to jQuery elements,
// thanks http://stackoverflow.com/a/1225238/1025836
(function ($) {
var _oldShow = $.fn.show;
$.fn.show = function (/*speed, easing, callback*/) {
var argsArray = Array.prototype.slice.call(arguments),
duration = argsArray[0],
easing,
callback,
callbackArgIndex;
// jQuery recursively calls show sometimes; we shouldn't
// handle such situations. Pass it to original show method.
if (!this.selector) {
_oldShow.apply(this, argsArray);
return this;
}
if (argsArray.length === 2) {
if ($.isFunction(argsArray[1])) {
callback = argsArray[1];
callbackArgIndex = 1;
} else {
easing = argsArray[1];
}
} else if (argsArray.length === 3) {
easing = argsArray[1];
callback = argsArray[2];
callbackArgIndex = 2;
}
return $(this).each(function () {
var obj = $(this),
oldCallback = callback,
newCallback = function () {
if ($.isFunction(oldCallback)) {
oldCallback.apply(obj);
}
};
if (callback) {
argsArray[callbackArgIndex] = newCallback;
}
obj.trigger('beforeShow');
_oldShow.apply(obj, argsArray);
obj.trigger('afterShow');
});
};
})(jQuery);