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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
$(document).ready(function () {
admin_search.initialize();
menu_items.initialize_search();
meta_data.initialize();
menu_item_sorter.initialize();
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})
$(document).ajaxSend(function(event, request, settings) {
if (typeof(AUTH_TOKEN) == "undefined") return;
// settings.data is a serialized string like "foo=bar&baz=boink" (or null)
settings.data = settings.data || "";
settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
});
});
meta_data = {
initialize : function() {
$("#metadata").attr("style", "display: none;");
$("#button").click(function () {
$("#metadata").slideToggle("slow");
if ($("#button").attr("class") == "unselected") {
$("#button").attr("class", "selected");
}
else {
$("#button").attr("class", "unselected");
}
});
}
};
cccms = {
setup_autosave : function() {
var elements = {
title : $('#page_title'),
abstract : $('#page_abstract'),
body : $('#page_body_ifr').contents().find('#tinymce'),
}
var page = {
cached_title : elements.title.val(),
cached_abstract : elements.abstract.val(),
cached_body : elements.body.html(),
title_has_changed : function() {
return (elements.title.val() != this.cached_title)
},
abstract_has_changed : function() {
return (elements.abstract.val() != this.cached_abstract)
},
body_has_changed : function() {
return elements.body.html() != this.cached_body
}
}
jQuery.fn.submitWithAjax = function(options) {
if (page.title_has_changed() || page.abstract_has_changed() || page.body_has_changed()) {
page.cached_title = elements.title.val();
page.cached_abstract = elements.abstract.val();
page.cached_body = elements.body.html();
$("#flash").append("<img src='/images/ajax-loader.gif' alt='' />");
$.post(this.attr("action"), $(this).serialize(), null, "script");
}
};
setInterval('$("#page_editor > form").submitWithAjax()', 15000);
}
}
menu_item_sorter = {
initialize : function() {
$("#menu_item_list").sortable({
axis: 'y',
items: 'tr',
handle: 'td',
stop : function(){
$.ajax({
type: "POST",
url: "/menu_items/0/sort",
data: $(this).sortable("serialize"),
dataType: "json",
success : function(results) {
alert(results);
}
});
}
});
}
}
|