[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / thickbox2 / head.php
1 <?php
2
3 function ThickBox1_insert_head_css($flux){
4 static $done = false;
5 if (!$done) {
6 $done = true;
7 $flux .= ThickBox_call_css();
8 }
9 return $flux;
10 }
11
12 function ThickBox1_insert_head($flux){
13 $flux = ThickBox1_insert_head_css($flux);
14
15 // on ajoute la class thickbox aux liens de type="image/xxx"
16
17 // TODO: ne charger thickbox.js et thickbox.css que si
18 // jQuery("a.thickbox,a[type='image/jpeg'],...").size() > 0)
19 if(!$GLOBALS["spip_pipeline"]["insert_js"])
20 $flux .= ThickBox_call_js();
21
22 return $flux;
23 }
24
25 function ThickBox1_header_prive($flux) {
26 include_spip("inc/filtres");
27
28 $flux .= ThickBox_call_css();
29 $flux .= ThickBox_call_js();
30
31 return $flux;
32
33 }
34
35 function ThickBox1_insert_js($flux){
36 include_spip("inc/filtres");
37
38 // on ajoute la class thickbox aux liens de type="image/xxx"
39
40 // TODO: ne charger thickbox.js et thickbox.css que si
41 // jQuery("a.thickbox,a[type='image/jpeg'],...").size() > 0)
42
43 if($flux['type']=='inline')
44 $flux["data"]["ThickBox1"] =
45 '
46 <script type="text/javascript"><!--
47 // Inside the function "this" will be "document" when called by ready()
48 // and "the ajaxed element" when called because of onAjaxLoad
49 var init_f = function() {
50 var me = this;
51 if (jQuery("a.thickbox,a[type=\'image/jpeg\'],a[type=\'image/png\'],a[type=\'image/gif\']",me).addClass("thickbox").size()) {
52
53 var TB_initload = function(){
54 TB_chemin_animation = "'.url_absolue(find_in_path('circle_animation.gif')).'";
55 TB_chemin_close = "'.url_absolue(find_in_path('close.gif')).'";
56 TB_chemin_css = "'.url_absolue(find_in_path('thickbox.css')).'";
57 TB_init(me);
58 };
59
60 if (typeof TB_init == "function") {
61 TB_initload();
62 } else {
63 jQuery("head")
64 .prepend("<link rel=\'stylesheet\'type=\'text/css\' href=\''.url_absolue(find_in_path('thickbox.css')).'\' />");
65 jQuery.getScript("'
66 .url_absolue(find_in_path('javascript/thickbox.js'))
67 .'", TB_initload)
68 }
69 };
70 }
71 //onAjaxLoad is defined in private area only
72 if(typeof onAjaxLoad == "function") onAjaxLoad(init_f);
73
74 // Demarrage : on charge et execute les scripts de thickbox en asynchrone
75 // ce qui permet a la page de s\'afficher plus tot
76 jQuery(document).ready(function(){setTimeout(init_f.apply(document),200)});
77 // --></script>';
78
79 return $flux;
80 }
81
82 function ThickBox1_verifie_js_necessaire($flux) {
83
84 //var_dump($flux["page"]);
85 $page = $flux["page"]["texte"];
86 //cherche <a> avec un type image ou une class thickbox
87 $necessaire = preg_match(",<a[^>]+(?:(type)|class)\s*=\s*['\"](?(1)image/(?:jpeg|png|gif)|[^>'\"]*\bthickbox\b[^>'\"]*)['\"],iUs",$page);
88 $flux["data"]["ThickBox1"] = $necessaire;
89
90 return $flux;
91
92 }
93
94 function ThickBox_call_js() {
95 $flux = '<script src=\''.url_absolue(find_in_path('javascript/thickbox.js')).'\' type=\'text/javascript\'></script>';
96 $flux .= '<script type="text/javascript"><!--
97 // Inside the function "this" will be "document" when called by ready()
98 // and "the ajaxed element" when called because of onAjaxLoad
99 var init_f = function() {
100 if (jQuery("a.thickbox,a[type=\'image/jpeg\'],a[type=\'image/png\'],a[type=\'image/gif\']",this).addClass("thickbox").size()) {
101 TB_chemin_animation = "'.url_absolue(find_in_path('circle_animation.gif')).'";
102 TB_chemin_close = "'.url_absolue(find_in_path('close.gif')).'";
103 TB_chemin_css = "'.url_absolue(find_in_path('thickbox.css')).'";
104 TB_init(this);
105 };
106 }
107 //onAjaxLoad is defined in private area only
108 if(typeof onAjaxLoad == "function") onAjaxLoad(init_f);
109 if (window.jQuery) jQuery(document).ready(init_f);
110 // --></script>';
111 return $flux;
112 }
113
114 function ThickBox_call_css() {
115 $flux = '<link rel="stylesheet" href="'.url_absolue(find_in_path('thickbox.css')).'" type="text/css" media="all" />';
116 return $flux;
117 }
118 ?>