auto_image_handling.js
8.88 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// Image Node Auto-Format with Auto Image Grouping.
// Original version by Steve McKenzie.
// Altered by Stella Power for jQuery version.
(function ($) {
function parse_url(url, param) {
param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
url = url.replace(/&/, "&");
var regexS = "[\\?&]"+param+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(url);
if (results === null) {
return "";
}
else {
return results[1];
}
}
function lightbox2_init_triggers(classes, rel_type, custom_class) {
if (classes == '' || rel_type == 0) {
return;
}
var settings = Drupal.settings.lightbox2;
var link_target = "";
if (settings.node_link_target !== 0) {
link_target = 'target="'+ settings.node_link_target +'"';
}
$("a:has("+classes+")").each(function(i) {
if ((!settings.disable_for_gallery_lists && !settings.disable_for_acidfree_gallery_lists) || (!$(this).parents("td.giAlbumCell").attr("class") && !$(this).parents(".galleries").length && !$(this).parents(".acidfree-folder").length && !$(this).parents(".acidfree-list").length) || ($(this).parents(".galleries").length && !settings.disable_for_gallery_lists) || (($(this).parents(".acidfree-folder").length || $(this).parents(".acidfree-list").length) && !settings.disable_for_acidfree_gallery_lists)) {
var child = $(this).find(classes);
// Ensure the child has a class attribute we can work with.
if ($(child).attr("class")) {
// Set the alt text.
var alt = $(child).attr("alt");
if (!alt) {
alt = "";
}
// Set the image node link text.
var link_text = settings.node_link_text;
var download_link_text = settings.download_link_text;
var rewrite = 1;
// Set the rel attribute.
var rel = "lightbox";
var lightframe = false;
if (rel_type == "lightframe_ungrouped") {
rel = "lightframe[]";
lightframe = true;
}
else if (rel_type == "lightframe") {
lightframe = true;
}
else if (rel_type == "lightbox_ungrouped") {
rel = "lightbox[]";
}
if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
rel = rel_type + "[" + $(child).attr("class") + "]";
}
// Set the basic href attribute - need to ensure there's no language
// string (e.g. /en) prepended to the URL.
var id = null;
var href = $(child).attr("src");
var download = null;
var orig_href = $(this).attr("href");
var pattern = new RegExp(settings.file_path);
if (orig_href.match(pattern)) {
var lang_pattern = new RegExp(Drupal.settings.basePath + "\\w\\w\\/");
orig_href = orig_href.replace(lang_pattern, Drupal.settings.basePath);
}
var frame_href = orig_href;
// Handle flickr images.
if ($(child).attr("class").match("flickr-photo-img") ||
$(child).attr("class").match("flickr-photoset-img")) {
href = $(child).attr("src").replace("_s.", ".").replace("_t.", ".").replace("_m.", ".").replace("_b.", ".");
if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
rel = rel_type + "[flickr]";
if ($(child).parents("div.block-flickr").attr("class")) {
id = $(child).parents("div.block-flickr").attr("id");
rel = rel_type + "["+ id +"]";
}
}
download = href;
}
// Handle "image-img_assist_custom" images.
else if ($(child).filter("img[class*=img_assist_custom]").size()) {
// Image assist uses "+" signs for spaces which doesn't work for
// normal links.
if (settings.display_image_size != "original") {
orig_href = orig_href.replace(/\+/, " ");
href = $(child).attr("src").replace(new RegExp("\\.img_assist_custom-[0-9]+x[0-9]+"), ((settings.display_image_size === "")?settings.display_image_size:"."+ settings.display_image_size));
if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
rel = rel_type + "[node_images]";
}
if (lightframe) {
frame_href = orig_href + "/lightbox2";
}
}
else {
rewrite = 0;
}
}
// Handle "inline" images.
else if ($(child).attr("class").match("inline")) {
href = orig_href;
}
// Handle gallery2 block images.
else if ($(child).attr("class").match("ImageFrame_image") || $(child).attr("class").match("ImageFrame_none")) {
var thumb_id = parse_url(href, "g2_itemId");
var new_id = parse_url(orig_href, "g2_itemId");
if (new_id && thumb_id) {
var g2pattern = new RegExp("g2_itemId="+thumb_id);
var replacement = "g2_itemId="+ new_id;
href = href.replace(g2pattern, replacement);
}
rel = rel_type + "[gallery2]";
if ($(child).parents("div.block-gallery").attr("class")) {
id = $(child).parents("div.block-gallery").attr("id");
rel = rel_type + "["+ id +"]";
}
download = href;
}
// Set the href attribute.
else if (settings.image_node_sizes != '()' && !custom_class) {
if (settings.display_image_size != "original") {
href = $(child).attr("src").replace(new RegExp(settings.image_node_sizes), ((settings.display_image_size === "")?settings.display_image_size:"."+ settings.display_image_size)).replace(/(image\/view\/\d+)(\/[\w\-]*)/, ((settings.display_image_size === "")?"$1/_original":"$1/"+ settings.display_image_size));
if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
rel = rel_type + "[node_images]";
if ($(child).parents("div.block-multiblock,div.block-image").attr("class")) {
id = $(child).parents("div.block-multiblock,div.block-image").attr("id");
rel = rel_type + "["+ id +"]";
}
}
download = $(child).attr("src").replace(new RegExp(settings.image_node_sizes), "").replace(/(image\/view\/\d+)(\/[\w\-]*)/, "$1/_original");
if (lightframe) {
frame_href = orig_href + "/lightbox2";
}
}
else {
rewrite = 0;
}
}
// Modify the image url.
var img_title = $(child).attr("title");
if (!img_title) {
img_title = $(this).attr("title");
if (!img_title) {
img_title = $(child).attr("alt");
}
$(child).attr({title: img_title});
}
if (lightframe) {
href = frame_href;
}
if (rewrite) {
if (!custom_class) {
var title_link = "";
if (link_text.length) {
title_link = "<br /><br /><a href=\"" + orig_href + "\" id=\"lightbox2-node-link-text\" "+ link_target +" >"+ link_text + "</a>";
}
if (download_link_text.length && download) {
title_link = title_link + " - <a href=\"" + download + "\" id=\"lightbox2-download-link-text\" target=\"_blank\">" + download_link_text + "</a>";
}
rel = rel + "[" + img_title + title_link + "]";
$(this).attr({
rel: rel,
href: href
});
}
else {
if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
rel = rel_type + "[" + $(child).attr("class") + "]";
if ($(child).parents("div.block-image").attr("class")) {
id = $(child).parents("div.block-image").attr("id");
rel = rel_type + "["+ id +"]";
}
}
rel = rel + "[" + img_title + "]";
$(this).attr({
rel: rel,
href: orig_href
});
}
}
}
}
});
}
function lightbox2_image_nodes() {
var settings = Drupal.settings.lightbox2;
// Don't do it on the image assist popup selection screen.
var img_assist = document.getElementById("img_assist_thumbs");
if (!img_assist) {
// Select the enabled image types.
lightbox2_init_triggers(settings.trigger_lightbox_classes, "lightbox_ungrouped");
lightbox2_init_triggers(settings.custom_trigger_classes, settings.custom_class_handler, true);
lightbox2_init_triggers(settings.trigger_lightbox_group_classes, "lightbox");
lightbox2_init_triggers(settings.trigger_slideshow_classes, "lightshow");
lightbox2_init_triggers(settings.trigger_lightframe_classes, "lightframe_ungrouped");
lightbox2_init_triggers(settings.trigger_lightframe_group_classes, "lightframe");
}
}
Drupal.behaviors.initAutoLightbox = {
attach: function(context, settings) {
lightbox2_image_nodes();
}
};
//End jQuery block
}(jQuery));