This repository has been archived by the owner on Sep 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js.erb
64 lines (55 loc) · 1.81 KB
/
index.js.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<%= File.read(settings.root + '/admin/jquery.js') %>
jQuery.noConflict();
(function($) {
$(function() {
// Short-circuit if this has run already (bookmarklet clicked twice).
if (window._copy_initialized) {
// Make the blocks clickable unless the Copy dialog is present.
if ($('#_copy').length == 0) {
clickable();
}
return true;
}
function clickable() {
$('._copy_editable').addClass('_copy_clickable');
}
function unclickable() {
$('._copy_editable').removeClass('_copy_clickable');
}
$('head').append('<style><%= File.read(settings.root + '/admin/copy.css').gsub(/\n/, " \\\n") %></style>');
$('._copy_clickable').live('click', function() {
var copy = $(this);
unclickable();
$.ajax({
url: '/_copy/'+copy.attr('data-name'),
success: function(html) {
$('body').prepend(html);
$('#_copy').css({ margin:'-'+($('#_copy').height() / 2)+'px 0 0 -'+($('#_copy').width() / 2)+'px' });
$('#_copy textarea').get(0).focus();
}
});
});
$('._copy_cancel').live('click', function() {
$('#_copy').remove();
clickable();
return false;
});
$('._copy_edit_form').live('submit', function() {
var form = $(this);
var original = $('[data-name="'+form.attr('data-content-name')+'"]');
form.find(':submit').attr('disabled', 'disabled');
$.ajax({
type: 'PUT',
url: form.attr('action'),
data: { content: form.find('textarea').val(), wrap_tag: original.get(0).tagName.toLowerCase() },
success: function(html) {
$('#_copy').remove();
original.replaceWith(html);
}
})
return false;
})
clickable();
window._copy_initialized = true;
});
})(jQuery);