source: trunk/spip/esqueleto-redcta/plugins/thickbox2/head.php @ 242

Last change on this file since 242 was 71, checked in by guille, 17 years ago
File size: 3.2 KB
RevLine 
[71]1<?php
2
3function ThickBox1_insert_head($flux){
4
5// on ajoute la class thickbox aux liens de type="image/xxx"
6
7// TODO: ne charger thickbox.js et thickbox.css que si
8// $("a.thickbox,a[@type='image/jpeg'],...").size() > 0)
9// var_dump(isset($GLOBALS["spip_pipeline"]["insert_js"]));
10if(!isset($GLOBALS["spip_pipeline"]["insert_js"]))
11
12$flux = ThickBox1_header_prive($flux);
13return $flux;
14}
15
16function ThickBox1_header_prive($flux) {
17
18$flux .=
19
20'
21<script src=\''.url_absolue(find_in_path('javascript/thickbox.js')).'\' type=\'text/javascript\'></script>
22<link rel="stylesheet" href="'.url_absolue(find_in_path('thickbox.css')).'" type="text/css" media="projection, screen" />
23<script type="text/javascript"><!--
24// Inside the function "this" will be "document" when called by ready()
25// and "the ajaxed element" when called because of onAjaxLoad
26var init_f = function() {
27        if ($("a.thickbox,a[@type=\'image/jpeg\'],a[@type=\'image/png\'],a[@type=\'image/gif\']",this).addClass("thickbox").size()) {
28                TB_chemin_animation = "'.url_absolue(find_in_path('circle_animation.gif')).'";
29                TB_chemin_close = "'.url_absolue(find_in_path('close.gif')).'";
30                TB_chemin_css = "'.url_absolue(find_in_path('thickbox.css')).'";
31                TB_init(this);
32        };
33}
34//onAjaxLoad is defined in private area only
35if(typeof onAjaxLoad == "function") onAjaxLoad(init_f);
36$(document).ready(init_f);
37// --></script>';
38
39return $flux;
40
41}
42
43function ThickBox1_insert_js($flux){
44// on ajoute la class thickbox aux liens de type="image/xxx"
45
46// TODO: ne charger thickbox.js et thickbox.css que si
47// $("a.thickbox,a[@type='image/jpeg'],...").size() > 0)
48
49if($flux['type']=='inline')
50  $flux["data"]["ThickBox1"] =
51'
52<script type="text/javascript"><!--
53// Inside the function "this" will be "document" when called by ready()
54// and "the ajaxed element" when called because of onAjaxLoad
55var init_f = function() {
56        var me = this;
57        if ($("a.thickbox,a[@type=\'image/jpeg\'],a[@type=\'image/png\'],a[@type=\'image/gif\']",me).addClass("thickbox").size()) {
58       
59                var TB_initload = function(){
60                        TB_chemin_animation = "'.url_absolue(find_in_path('circle_animation.gif')).'";
61                        TB_chemin_close = "'.url_absolue(find_in_path('close.gif')).'";
62                        TB_chemin_css = "'.url_absolue(find_in_path('thickbox.css')).'";
63                        TB_init(me);
64                };
65
66                if (typeof TB_init == "function") {
67                        TB_initload();
68                } else {
69                        jQuery("head")
70                        .prepend("<link rel=\'stylesheet\'type=\'text/css\' href=\''.url_absolue(find_in_path('thickbox.css')).'\' />");
71                        $.getScript("'
72                                .url_absolue(find_in_path('javascript/thickbox.js'))
73                                .'", TB_initload)
74                }
75        };
76}
77//onAjaxLoad is defined in private area only
78if(typeof onAjaxLoad == "function") onAjaxLoad(init_f);
79
80// Demarrage : on charge et execute les scripts de thickbox en asynchrone
81// ce qui permet a la page de s\'afficher plus tot
82$(document).ready(function(){setTimeout(init_f,200)});
83// --></script>';
84
85        return $flux;
86}
87
88function ThickBox1_verifie_js_necessaire($flux) {
89
90//var_dump($flux["page"]);
91$page = $flux["page"]["texte"];
92$necessaire = preg_match(",<a[^>]+type\s*=\s*['\"]image/(?:jpeg|png|gif)['\"],iUs",$page) ||
93              preg_match(",<a[^>]+class\s*=\s*['\"].*\bthickbox\b.*['\"],iUs",$page);
94
95$flux["data"]["ThickBox1"] = $necessaire;
96
97return $flux;
98 
99}
100
101?>
Note: See TracBrowser for help on using the repository browser.