1 |
85ad3d82
|
Assos Assos
|
(function ($) {
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
Drupal.flagLink = function(context) {
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
function updateLink(element, newHtml) {
|
24 |
|
|
var $newLink = $(newHtml);
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
$('.flag-message', $newLink).css('display', 'none');
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
var $nucleus = $newLink.is('a') ? $newLink : $('a.flag', $newLink);
|
32 |
|
|
$nucleus.addClass('flag-processed').click(flagClick);
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
var $wrapper = $(element).parents('.flag-wrapper:first');
|
36 |
|
|
|
37 |
|
|
$wrapper.after($newLink).remove();
|
38 |
|
|
Drupal.attachBehaviors($newLink.get(0));
|
39 |
|
|
|
40 |
|
|
$('.flag-message', $newLink).fadeIn();
|
41 |
|
|
setTimeout(function(){ $('.flag-message.flag-auto-remove', $newLink).fadeOut() }, 3000);
|
42 |
|
|
return $newLink.get(0);
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
function flagClick(event) {
|
49 |
|
|
|
50 |
|
|
event.preventDefault();
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
var element = this;
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
var $wrapper = $(element).parents('.flag-wrapper');
|
60 |
|
|
if ($wrapper.is('.flag-waiting')) {
|
61 |
|
|
|
62 |
|
|
return false;
|
63 |
|
|
}
|
64 |
|
|
$wrapper.addClass('flag-waiting');
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
$('span.flag-message:visible').fadeOut();
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
$.ajax({
|
71 |
|
|
type: 'POST',
|
72 |
|
|
url: element.href,
|
73 |
|
|
data: { js: true },
|
74 |
|
|
dataType: 'json',
|
75 |
|
|
success: function (data) {
|
76 |
|
|
data.link = $wrapper.get(0);
|
77 |
|
|
$.event.trigger('flagGlobalBeforeLinkUpdate', [data]);
|
78 |
|
|
if (!data.preventDefault) {
|
79 |
|
|
data.link = updateLink(element, data.newLink);
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
var $wrappers = $('.flag-wrapper.flag-' + data.flagName.flagNameToCSS() + '-' + data.contentId).not(data.link);
|
85 |
|
|
var $newLink = $(data.newLink);
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
$('.flag-message', $newLink).hide();
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
$wrappers = $newLink.replaceAll($wrappers);
|
92 |
|
|
Drupal.attachBehaviors($wrappers.parent());
|
93 |
|
|
|
94 |
|
|
$.event.trigger('flagGlobalAfterLinkUpdate', [data]);
|
95 |
|
|
},
|
96 |
|
|
error: function (xmlhttp) {
|
97 |
|
|
alert('An HTTP error '+ xmlhttp.status +' occurred.\n'+ element.href);
|
98 |
|
|
$wrapper.removeClass('flag-waiting');
|
99 |
|
|
}
|
100 |
|
|
});
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
$('a.flag-link-toggle:not(.flag-processed)', context).addClass('flag-processed').click(flagClick);
|
104 |
|
|
};
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
Drupal.flagAnonymousLinks = function(context) {
|
110 |
|
|
$('a.flag:not(.flag-anonymous-processed)', context).each(function() {
|
111 |
|
|
this.href += (this.href.match(/\?/) ? '&' : '?') + 'has_js=1';
|
112 |
|
|
$(this).addClass('flag-anonymous-processed');
|
113 |
|
|
});
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
String.prototype.flagNameToCSS = function() {
|
117 |
|
|
return this.replace(/_/g, '-');
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
Drupal.flagAnonymousLinkTemplates = function(context) {
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
var templates = Drupal.settings.flag.templates;
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
var userFlags = Drupal.flagCookie('flags');
|
130 |
|
|
if (userFlags) {
|
131 |
|
|
userFlags = userFlags.split('+');
|
132 |
|
|
for (var n in userFlags) {
|
133 |
|
|
var flagInfo = userFlags[n].match(/(\w+)_(\d+)/);
|
134 |
|
|
var flagName = flagInfo[1];
|
135 |
|
|
var contentId = flagInfo[2];
|
136 |
|
|
|
137 |
|
|
if (templates[flagName + '_' + contentId]) {
|
138 |
|
|
$('.flag-' + flagName.flagNameToCSS() + '-' + contentId, context).after(templates[flagName + '_' + contentId]).remove();
|
139 |
|
|
}
|
140 |
|
|
}
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
var globalFlags = document.cookie.match(/flag_global_(\w+)_(\d+)=([01])/g);
|
145 |
|
|
if (globalFlags) {
|
146 |
|
|
for (var n in globalFlags) {
|
147 |
|
|
var flagInfo = globalFlags[n].match(/flag_global_(\w+)_(\d+)=([01])/);
|
148 |
|
|
var flagName = flagInfo[1];
|
149 |
|
|
var contentId = flagInfo[2];
|
150 |
|
|
var flagState = (flagInfo[3] == '1') ? 'flag' : 'unflag';
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
if (templates[flagName + '_' + contentId]) {
|
156 |
|
|
$('.flag-' + flagName.flagNameToCSS() + '-' + contentId, context).each(function() {
|
157 |
|
|
if ($(this).find('.' + flagState + '-action').size()) {
|
158 |
|
|
$(this).after(templates[flagName + '_' + contentId]).remove();
|
159 |
|
|
}
|
160 |
|
|
});
|
161 |
|
|
}
|
162 |
|
|
}
|
163 |
|
|
}
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
Drupal.flagCookie = function(name, value, options) {
|
173 |
|
|
if (typeof value != 'undefined') {
|
174 |
|
|
options = options || {};
|
175 |
|
|
if (value === null) {
|
176 |
|
|
value = '';
|
177 |
|
|
options = $.extend({}, options);
|
178 |
|
|
options.expires = -1;
|
179 |
|
|
}
|
180 |
|
|
var expires = '';
|
181 |
|
|
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
|
182 |
|
|
var date;
|
183 |
|
|
if (typeof options.expires == 'number') {
|
184 |
|
|
date = new Date();
|
185 |
|
|
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
|
186 |
|
|
} else {
|
187 |
|
|
date = options.expires;
|
188 |
|
|
}
|
189 |
|
|
expires = '; expires=' + date.toUTCString();
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
var path = options.path ? '; path=' + (options.path) : '';
|
195 |
|
|
var domain = options.domain ? '; domain=' + (options.domain) : '';
|
196 |
|
|
var secure = options.secure ? '; secure' : '';
|
197 |
|
|
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
|
198 |
|
|
} else {
|
199 |
|
|
var cookieValue = null;
|
200 |
|
|
if (document.cookie && document.cookie != '') {
|
201 |
|
|
var cookies = document.cookie.split(';');
|
202 |
|
|
for (var i = 0; i < cookies.length; i++) {
|
203 |
|
|
var cookie = jQuery.trim(cookies[i]);
|
204 |
|
|
|
205 |
|
|
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
206 |
|
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
207 |
|
|
break;
|
208 |
|
|
}
|
209 |
|
|
}
|
210 |
|
|
}
|
211 |
|
|
return cookieValue;
|
212 |
|
|
}
|
213 |
|
|
};
|
214 |
|
|
|
215 |
|
|
Drupal.behaviors.flagLink = {};
|
216 |
|
|
Drupal.behaviors.flagLink.attach = function(context) {
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
if (Drupal.settings.flag && Drupal.settings.flag.templates) {
|
220 |
|
|
Drupal.flagAnonymousLinkTemplates(context);
|
221 |
|
|
}
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
if (Drupal.settings.flag && Drupal.settings.flag.anonymous) {
|
226 |
|
|
Drupal.flagAnonymousLinks(context);
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
Drupal.flagLink(context);
|
231 |
|
|
};
|
232 |
|
|
|
233 |
|
|
})(jQuery); |