/
globals.js
152 lines (137 loc) · 4.88 KB
/
globals.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
if (!Omeka) {
var Omeka = {};
}
(function ($) {
/**
* Add the TinyMCE WYSIWYG editor to a page.
* Default is to add to all textareas.
*
* @param {Object} [params] Parameters to pass to TinyMCE, these override the
* defaults.
*/
Omeka.wysiwyg = function (params) {
// Default parameters
initParams = {
convert_urls: false,
mode: "textareas", // All textareas
theme: "advanced",
theme_advanced_toolbar_location: "top",
theme_advanced_statusbar_location: "none",
theme_advanced_toolbar_align: "left",
theme_advanced_buttons1: "bold,italic,underline,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,|,link,formatselect,code",
theme_advanced_buttons2: "",
theme_advanced_buttons3: "",
theme_advanced_blockformats: "p,address,pre,h1,h2,h3,h4,h5,h6,blockquote,address,div",
plugins: "paste,inlinepopups,media,autoresize",
media_strict: false,
width: "100%",
autoresize_max_height: 500
};
tinyMCE.init($.extend(initParams, params));
};
Omeka.deleteConfirm = function () {
$('.delete-confirm').click(function (event) {
var url;
event.preventDefault();
if ($(this).is('input')) {
url = $(this).parents('form').attr('action');
} else if ($(this).is('a')) {
url = $(this).attr('href');
} else {
return;
}
$.post(url, function (response){
$(response).dialog({modal:true});
});
});
};
Omeka.saveScroll = function () {
var $save = $("#save"),
$window = $(window),
offset = $save.offset(),
topPadding = 62,
$contentDiv = $("#content");
if (document.getElementById("save")) {
$window.scroll(function () {
if($window.scrollTop() > offset.top && $window.width() > 767 && ($window.height() - topPadding - 85) > $save.height()) {
$save.stop().animate({
marginTop: $window.scrollTop() - offset.top + topPadding
});
} else {
$save.stop().animate({
marginTop: 0
});
}
});
}
};
Omeka.stickyNav = function() {
var $nav = $("#content-nav"),
$window = $(window);
if ($window.height() - 50 < $nav.height()) {
$nav.addClass("unfix");
}
$window.resize( function() {
if ($window.height() - 50 < $nav.height()) {
$nav.addClass("unfix");
} else {
$nav.removeClass("unfix");
}
});
};
Omeka.showAdvancedForm = function () {
var advancedForm = $('#advanced-form');
$('#search-form').addClass("with-advanced");
$('#search-form button').addClass("blue button");
advancedForm.before('<a href="#" id="advanced-search" class="blue button">Advanced Search</a>');
advancedForm.click(function (event) {
event.stopPropagation();
});
$("#advanced-search").click(function (event) {
event.preventDefault();
event.stopPropagation();
advancedForm.fadeToggle();
$(document).click(function (event) {
if (event.target.id == 'query') {
return;
}
advancedForm.fadeOut();
$(this).unbind(event);
});
});
};
Omeka.skipNav = function () {
$("#skipnav").click(function() {
$("#content").attr("tabindex", -1).focus();
});
$("#content").on("blur focusout", function () {
$(this).removeAttr("tabindex");
});
};
Omeka.addReadyCallback = function (callback, params) {
this.readyCallbacks.push([callback, params]);
};
Omeka.runReadyCallbacks = function () {
for (var i = 0; i < this.readyCallbacks.length; ++i) {
var params = this.readyCallbacks[i][1] || [];
this.readyCallbacks[i][0].apply(this, params);
}
};
Omeka.mediaFallback = function () {
$('.omeka-media').on('error', function () {
if (this.networkState === HTMLMediaElement.NETWORK_NO_SOURCE ||
this.networkState === HTMLMediaElement.NETWORK_EMPTY
) {
$(this).replaceWith(this.innerHTML);
}
});
};
Omeka.readyCallbacks = [
[Omeka.deleteConfirm, null],
[Omeka.saveScroll, null],
[Omeka.stickyNav, null],
[Omeka.showAdvancedForm, null],
[Omeka.skipNav, null],
[Omeka.mediaFallback, null]
];
})(jQuery);