1
|
// see also https://github.com/geetarista/jquery-plugin-template/blob/master/jquery.plugin-template.js
|
2
|
|
3
|
/**
|
4
|
* Expected dom structure:
|
5
|
* '<div class="ahah-content" rel="'.$cdm_proxy_url.'"><span class="loading">Loading ....</span></div>';
|
6
|
*/
|
7
|
;(function($, document, window, undefined) {
|
8
|
|
9
|
|
10
|
$.fn.ahahContent = function (eventSource) {
|
11
|
|
12
|
// firebug console stub (avoids errors if firebug is not active)
|
13
|
if(typeof console === "undefined") {
|
14
|
console = { log: function() { } };
|
15
|
}
|
16
|
|
17
|
var element;
|
18
|
if( eventSource !== undefined ){
|
19
|
// if ahahContent() has been called as event handler use the eventSource
|
20
|
element = $(eventSource);
|
21
|
console.log("ahahContent() as domEventHandler for " + element);
|
22
|
} else {
|
23
|
// otherwise use this jQuery object
|
24
|
element = $(this);
|
25
|
console.log("ahahContent() as jQuery function for " + element);
|
26
|
}
|
27
|
|
28
|
|
29
|
// register with all elements matching the css class selector '.ahah-content'
|
30
|
element.find(".ahah-content").each(function(index, element) {
|
31
|
|
32
|
var ahahContent = $(element);
|
33
|
|
34
|
var url = ahahContent.attr("data-cdm-ahah-url");
|
35
|
ahahContent.attr("data-cdm-ahah-url", '');
|
36
|
ahahContent.attr("data-cdm-ahah-url-loaded", url);
|
37
|
|
38
|
console.log("ahahContent() url:" + url);
|
39
|
if(url !== undefined && url.length > 1){
|
40
|
ahahContent.find('.loading').css('display', 'block');
|
41
|
$.get(url, function(html){
|
42
|
ahahContent.find('.loading').remove().end().append(html);
|
43
|
});
|
44
|
}
|
45
|
});
|
46
|
|
47
|
};
|
48
|
})(jQuery, document, window);
|
49
|
|
50
|
|
51
|
|
52
|
jQuery(document).ready(
|
53
|
function() {
|
54
|
//
|
55
|
jQuery("body").ahahContent();
|
56
|
|
57
|
// register events to detect lightbox opening
|
58
|
// for FireFox, Webkit and Opera
|
59
|
jQuery("body").bind('overflow', function(event){
|
60
|
jQuery('#jquery-lightbox').ahahContent();
|
61
|
});
|
62
|
// for Chrome and >=IE9(???)
|
63
|
// - Chrome: this only works for the first image in a lighbox gallery FIXME (need lightbox with callback!)
|
64
|
jQuery("body").bind('overflowchanged', function(event){
|
65
|
window.setTimeout(
|
66
|
function() {
|
67
|
jQuery('#jquery-lightbox').ahahContent();
|
68
|
},
|
69
|
2000 // milli seconds
|
70
|
);
|
71
|
});
|
72
|
|
73
|
// register the ahahContent as domEventHandler
|
74
|
// see domEvents.js
|
75
|
//
|
76
|
// the for example dynabox will execute the callback after loading
|
77
|
// the content into the dynabox. By this it is for possible
|
78
|
// to have ahahContent content inside of dynaboxes
|
79
|
document.domEventHandlers.push(jQuery().ahahContent);
|
80
|
}
|
81
|
);
|