Dotclear

source: plugins/colorbox/_public.php @ 2416

Revision 2416, 6.2 KB checked in by philippe, 13 years ago (diff)

colorbox : fixed notices with new settings

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of ColorBox, a plugin for Dotclear 2.
5#
6# Copyright (c) 2009 Philippe Amalgame and contributors
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK ------------------------------------
12
13$core->addBehavior('publicHeadContent',array('colorboxPublic','publicHeadContent'));
14
15class colorboxPublic
16{
17     public static function publicHeadContent($core)
18     {
19          # Settings compatibility test
20          if (!version_compare(DC_VERSION,'2.1.7','<=')) {
21               $s =& $core->blog->settings->colorbox;
22          } else {
23               $core->blog->settings->setNamespace('colorbox');
24               $s =& $core->blog->settings;
25          }
26         
27          if (!$s->colorbox_enabled) {
28               return;
29          }
30         
31          $url = $core->blog->getQmarkURL().'pf='.basename(dirname(__FILE__));
32         
33          $icon_name = 'zoom.png';
34          $icon_width = '16';
35          $icon_height = '16';
36         
37          echo
38          '<style type="text/css">'."\n".
39          '@import url('.$url.'/css/colorbox_common.css);'."\n".
40          "</style>\n".
41          '<style type="text/css">'."\n".
42          '@import url('.$url.'/themes/'.$s->colorbox_theme.'/colorbox_theme.css);'."\n".
43          "</style>\n";
44         
45          if ($s->colorbox_user_files) {
46               $public_path = $core->blog->public_path;
47               $public_url = $core->blog->settings->system->public_url;         
48               $colorbox_user_path = $public_path.'/colorbox/themes/';
49               $colorbox_user_url = $public_url.'/colorbox/themes/';
50               
51               if (file_exists($colorbox_user_path.$s->colorbox_theme.'/colorbox_user.css')){
52                    echo
53                    '<style type="text/css">'."\n".
54                    '@import url('.$colorbox_user_url.$s->colorbox_theme.'/colorbox_user.css);'."\n".
55                    "</style>\n";
56               }
57          } else {
58               $theme_path = path::fullFromRoot($core->blog->settings->system->themes_path."/".$core->blog->settings->system->theme,DC_ROOT);;
59               $theme_url = $core->blog->settings->system->themes_url."/".$core->blog->settings->system->theme;
60               $colorbox_user_path = $theme_path.'/colorbox/themes/'.$s->colorbox_theme.'/colorbox_user.css';
61               $colorbox_user_url = $theme_url.'/colorbox/themes/'.$s->colorbox_theme.'/colorbox_user.css';
62               if (file_exists($colorbox_user_path)){
63               echo
64                    '<style type="text/css">'."\n".
65                    '@import url('.$colorbox_user_url.');'."\n".
66                    "</style>\n";
67               };
68
69          }
70          echo
71          '<script type="text/javascript" src="'.$url.'/js/jquery.colorbox-min.js"></script>'."\n".
72          '<script type="text/javascript">'."\n".
73          "//<![CDATA[\n";
74         
75          $selectors = 'div.post'.($s->colorbox_selectors !== '' ? ','.$s->colorbox_selectors : '');
76         
77          echo
78          '$(window).load(function(){'.
79               'var count = 0; '.
80               '$("'.$selectors.'").each(function() {'."\n".
81                    'count++;'."\n".
82                    '$(this).find("a[href$=.jpg],a[href$=.jpeg],a[href$=.png],a[href$=.gif],'.
83                    'a[href$=.JPG],a[href$=.JPEG],a[href$=.PNG],a[href$=.GIF]").addClass("colorbox_zoom");'."\n".
84                    '$(this).find("a[href$=.jpg],a[href$=.jpeg],a[href$=.png],a[href$=.gif],'.
85                    'a[href$=.JPG],a[href$=.JPEG],a[href$=.PNG],a[href$=.GIF]").attr("rel", "colorbox-"+count);'."\n";
86         
87          echo
88          '$(this).find("a.colorbox_zoom").each(function(){'."\n".
89               'var p = $(this).find("img");'."\n".
90               'if (p.attr("title") != 0 && $(this).attr("title") == 0){'."\n".
91                    '$(this).attr("title", p.attr("title"));'."\n".
92               '}'."\n".
93          '});'."\n";
94                   
95          if ($s->colorbox_zoom_icon_permanent)
96          {
97               echo
98               '$(this).find("a.colorbox_zoom").each(function(){'."\n".
99                    'var p = $(this).find("img");'."\n".
100                    'if (p.length != 0){'."\n".
101                         'var offset = p.offset();'."\n".
102                         'var parent = p.offsetParent();'."\n".
103                         'var offsetparent = parent.offset();'."\n".
104                         'var parenttop = offsetparent.top;'."\n".
105                         'var parentleft = offsetparent.left;'."\n".
106                         'var top = offset.top-parenttop;'."\n";
107                             
108               if ($s->colorbox_position) {
109                    echo 'var left = offset.left-parentleft;'."\n";
110               } else {       
111                    echo 'var left = offset.left-parentleft+p.outerWidth()-'.$icon_width.';'."\n";
112               }
113               
114               echo '$(this).append("<span style=\"z-index:10;width:'.$icon_width.'px;height:'.$icon_height.'px;top:'.'"+top+"'.'px;left:'.'"+left+"'.'px;background: url('.html::escapeJS($url).'/themes/'.$s->colorbox_theme.'/images/zoom.png) top left no-repeat; position:absolute;\"></span>");'."\n".
115                    '}'."\n".
116               '});'."\n";
117          }
118         
119          if ($s->colorbox_zoom_icon && !$s->colorbox_zoom_icon_permanent)
120          {
121               echo
122               '$(\'body\').prepend(\'<img id="colorbox_magnify" style="display:block;padding:0;margin:0;z-index:10;width:'.$icon_width.'px;height:'.$icon_height.'px;position:absolute;top:0;left:0;display:none;" src="'.html::escapeJS($url).'/themes/'.$s->colorbox_theme.'/images/zoom.png" alt=""  />\');'."\n".
123               '$(\'img#colorbox_magnify\').click(function ()'."\n".
124                    '{ '."\n".
125                         '$("a.colorbox_zoom img.colorbox_hovered").click(); '."\n".
126                         '$("a.colorbox_zoom img.colorbox_hovered").removeClass(\'colorbox_hovered\');'."\n".
127                    '});'."\n".
128                    '$(\'a.colorbox_zoom img\').click(function ()'."\n". 
129                    '{ '."\n".
130                         '$(this).removeClass(\'colorbox_hovered\');'."\n".
131                    '});'."\n".
132                    '$("a.colorbox_zoom img").hover(function(){'."\n".
133                    'var p = $(this);'."\n".
134                    'p.addClass(\'colorbox_hovered\');'."\n".
135                    'var offset = p.offset();'."\n";
136
137               if (!$s->colorbox_position) {
138                    echo '$(\'img#colorbox_magnify\').css({\'top\' : offset.top, \'left\' : offset.left+p.outerWidth()-'.$icon_width.'});'."\n";
139               } else {
140                    echo '$(\'img#colorbox_magnify\').css({\'top\' : offset.top, \'left\' : offset.left});'."\n";
141               }
142               echo
143               '$(\'img#colorbox_magnify\').show();'."\n".
144               '},function(){'."\n".
145                    'var p = $(this);'."\n".
146                    'p.removeClass(\'colorbox_hovered\');'."\n".
147                    '$(\'img#colorbox_magnify\').hide();'."\n".
148               '});'."\n";
149          }
150         
151          foreach (unserialize($s->colorbox_advanced) as $k => $v) {
152               if ($v === '') {
153                    $opts[] = $k.': false';
154               }
155               elseif (is_bool($v)) {
156                    $opts[] = $k.': '.($v ? 'true' : 'false');
157               }
158               elseif (is_numeric($v)) {
159                    $opts[] = $k.": ".$v;
160               }
161               elseif (is_string($v)) {
162                    $opts[] = $k.": '".$v."'";
163               }
164          }
165         
166          echo 
167          "});\n".
168          '$("a[rel*=\'colorbox-\']").colorbox({'.implode(",\n",$opts).'});'."\n".
169          "});\n".
170          "\n//]]>\n".
171          "</script>\n";
172     }
173}
174
175?>
Note: See TracBrowser for help on using the repository browser.

Sites map