-
Notifications
You must be signed in to change notification settings - Fork 0
/
flagnote_modalframe.js
58 lines (52 loc) · 1.7 KB
/
flagnote_modalframe.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
Drupal.flagNoteModalframe = Drupal.flagNoteModalframe || {};
/**
* Helper function. Updates a link's HTML with a new one. Taken
* and adapted from flag.js
*
* @see flag.js from flag module
*/
Drupal.flagNoteModalframe.updateLink = function (element, newHtml) {
var $newLink = $(newHtml);
// Initially hide the message so we can fade it in.
$('.flag-message', $newLink).css('display', 'none');
// Find the wrapper of the old link.
var $wrapper = $(element).parents('.flag-wrapper:first');
if ($wrapper.length == 0) {
// If no ancestor wrapper was found, or if the 'flag-wrapper' class is
// attached to the <a> element itself, then take the element itself.
$wrapper = $(element);
}
// Replace the old link with the new one.
$wrapper.after($newLink).remove();
Drupal.attachBehaviors($newLink.get(0));
return $newLink.get(0);
};
Drupal.behaviors.flagNoteModalframe = function() {
$('a.modalframe-flagnote:not(.modalframe-flagnote-processed)').click(function() {
$(this).addClass('modalframe-flagnote-processed');
Drupal.theme('flagNoteModalframe', this);
return false;
});
};
Drupal.theme.prototype.flagNoteModalframe = function (element) {
var onSubmitCallback = function(args, statusMessages) {
// Themed status messages can be displayed on the page by themers
// overriding this function
if (args) {
if (args.newLink) {
Drupal.flagNoteModalframe.updateLink(element, args.newLink);
}
if (args.status) {
alert(args.status);
}
}
};
var modalOptions = {
url: $(element).attr('href'),
width: 500,
height: 300,
autoFit: true,
onSubmit: onSubmitCallback
};
Drupal.modalFrame.open(modalOptions);
};