This commit is contained in:
albert
2010-08-18 18:42:33 -04:00
parent 23656e3fa9
commit 5610731b35
48 changed files with 664 additions and 716 deletions

View File

@@ -1,79 +0,0 @@
// Cookie.setup();
$(document).ready(function() {
// $("#hide-upgrade-account-link").click(function() {
// $("#upgrade-account").hide();
// Cookie.put('hide-upgrade-account', '1', 7);
// });
// Comment listing
$(".comment-section form").hide();
$(".comment-section input.expand-comment-response").click(function() {
var post_id = $(this).closest(".comment-section").attr("data-post-id");
$(".comment-section[data-post-id=" + post_id + "] form").show();
$(this).hide();
})
});
var Danbooru = {};
// ContextMenu
Danbooru.ContextMenu = {};
Danbooru.ContextMenu.add_icon = function() {
$("menu[type=context] > li").append('<img src="/images/arrow2_s.png">');
}
Danbooru.ContextMenu.toggle_icon = function(li) {
if (li == null) {
$("menu[type=context] > li > img").attr("src", "/images/arrow2_s.png");
} else {
$(li).find("img").attr("src", function() {
if (this.src.match(/_n/)) {
return "/images/arrow2_s.png";
} else {
return "/images/arrow2_n.png";
}
});
}
}
Danbooru.ContextMenu.setup = function() {
$("menu[type=context] li").hover(
function() {$(this).css({"background-color": "#F6F6F6"})},
function() {$(this).css({"background-color": "#EEE"})}
);
this.add_icon();
$("menu[type=context] > li").click(function(e) {
$(this).parent().find("ul").toggle();
e.stopPropagation();
Danbooru.ContextMenu.toggle_icon(this);
});
$(document).click(function() {
$("menu[type=context] > ul").hide();
Danbooru.ContextMenu.toggle_icon();
});
$("menu[type=context] > ul > li").click(function(element) {
$(this).closest("ul").toggle();
var text = $(this).text()
var menu = $(this).closest("menu");
menu.children("li").text(text);
if (menu.attr("data-update-field-id")) {
$("#" + menu.attr("data-update-field-id")).val(text);
Danbooru.ContextMenu.add_icon();
}
if (menu.attr("data-submit-on-change") == "true") {
menu.closest("form").submit();
}
});
}
$(document).ready(function() {
Danbooru.ContextMenu.setup();
});

View File

@@ -1,129 +0,0 @@
// from http://github.com/rails/jquery-ujs/raw/master/src/rails.js
jQuery(function ($) {
var csrf_token = $('meta[name=csrf-token]').attr('content'),
csrf_param = $('meta[name=csrf-param]').attr('content');
$.fn.extend({
/**
* Triggers a custom event on an element and returns the event result
* this is used to get around not being able to ensure callbacks are placed
* at the end of the chain.
*
* TODO: deprecate with jQuery 1.4.2 release, in favor of subscribing to our
* own events and placing ourselves at the end of the chain.
*/
triggerAndReturn: function (name, data) {
var event = new $.Event(name);
this.trigger(event, data);
return event.result !== false;
},
/**
* Handles execution of remote calls firing overridable events along the way
*/
callRemote: function () {
var el = this,
data = el.is('form') ? el.serializeArray() : [],
method = el.attr('method') || el.attr('data-method') || 'GET',
url = el.attr('action') || el.attr('href');
if (url === undefined) {
throw "No URL specified for remote call (action or href must be present).";
} else {
if (el.triggerAndReturn('ajax:before')) {
$.ajax({
url: url,
data: data,
dataType: 'script',
type: method.toUpperCase(),
beforeSend: function (xhr) {
el.trigger('ajax:loading', xhr);
},
success: function (data, status, xhr) {
el.trigger('ajax:success', [data, status, xhr]);
},
complete: function (xhr) {
el.trigger('ajax:complete', xhr);
},
error: function (xhr, status, error) {
el.trigger('ajax:failure', [xhr, status, error]);
}
});
}
el.trigger('ajax:after');
}
}
});
/**
* confirmation handler
*/
$('a[data-confirm],input[data-confirm]').live('click', function () {
var el = $(this);
if (el.triggerAndReturn('confirm')) {
if (!confirm(el.attr('data-confirm'))) {
return false;
}
}
});
/**
* remote handlers
*/
$('form[data-remote]').live('submit', function (e) {
$(this).callRemote();
e.preventDefault();
});
$('a[data-remote],input[data-remote]').live('click', function (e) {
$(this).callRemote();
e.preventDefault();
});
$('a[data-method]:not([data-remote])').live('click', function (e){
var link = $(this),
href = link.attr('href'),
method = link.attr('data-method'),
form = $('<form method="post" action="'+href+'">'),
metadata_input = '<input name="_method" value="'+method+'" type="hidden" />';
if (csrf_param != null && csrf_token != null) {
metadata_input += '<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />';
}
form.hide()
.append(metadata_input)
.appendTo('body');
e.preventDefault();
form.submit();
});
/**
* disable-with handlers
*/
var disable_with_input_selector = 'input[data-disable-with]';
var disable_with_form_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')';
$(disable_with_form_selector).live('ajax:before', function () {
$(this).find(disable_with_input_selector).each(function () {
var input = $(this);
input.data('enable-with', input.val())
.attr('value', input.attr('data-disable-with'))
.attr('disabled', 'disabled');
});
});
$(disable_with_form_selector).live('ajax:after', function () {
$(this).find(disable_with_input_selector).each(function () {
var input = $(this);
input.removeAttr('disabled')
.val(input.data('enable-with'));
});
});
});