Dotclear

source: plugins/colorbox/_public.php @ 2111

Revision 2111, 5.6 KB checked in by philippe, 14 years ago (diff)

1.3.5 : added user css management option

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.6','<=')) {
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          $public_path = $core->blog->public_path;
46          $public_url = $core->blog->settings->public_url;       
47         
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         
58          echo
59          '<script type="text/javascript" src="'.$url.'/js/jquery.colorbox-min.js"></script>'."\n".
60         
61          '<script type="text/javascript">'."\n".
62          "//<![CDATA[\n";
63         
64          $selectors = 'div.post'.($s->colorbox_selectors !== '' ? ','.$s->colorbox_selectors : '');
65         
66          echo
67          '$(window).load(function(){'.
68               'var count = 0; '.
69               '$("'.$selectors.'").each(function() {'."\n".
70                    'count++;'."\n".
71                    '$(this).find("a[href$=.jpg],a[href$=.jpeg],a[href$=.png],a[href$=.gif],'.
72                    'a[href$=.JPG],a[href$=.JPEG],a[href$=.PNG],a[href$=.GIF]").addClass("colorbox_zoom");'."\n".
73                    '$(this).find("a[href$=.jpg],a[href$=.jpeg],a[href$=.png],a[href$=.gif],'.
74                    'a[href$=.JPG],a[href$=.JPEG],a[href$=.PNG],a[href$=.GIF]").attr("rel", "colorbox-"+count);'."\n";
75         
76          echo
77          '$(this).find("a.colorbox_zoom").each(function(){'."\n".
78               'var p = $(this).find("img");'."\n".
79               'if (p.attr("title") != 0 && $(this).attr("title") == 0){'."\n".
80                    '$(this).attr("title", p.attr("title"));'."\n".
81               '}'."\n".
82          '});'."\n";
83                   
84          if ($s->colorbox_zoom_icon_permanent)
85          {
86               echo
87               '$(this).find("a.colorbox_zoom").each(function(){'."\n".
88                    'var p = $(this).find("img");'."\n".
89                    'if (p.length != 0){'."\n".
90                         'var offset = p.offset();'."\n".
91                         'var parent = p.offsetParent();'."\n".
92                         'var offsetparent = parent.offset();'."\n".
93                         'var parenttop = offsetparent.top;'."\n".
94                         'var parentleft = offsetparent.left;'."\n".
95                         'var top = offset.top-parenttop;'."\n";
96                             
97               if ($s->colorbox_position) {
98                    echo 'var left = offset.left-parentleft;'."\n";
99               } else {       
100                    echo 'var left = offset.left-parentleft+p.outerWidth()-'.$icon_width.';'."\n";
101               }
102               
103               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".
104                    '}'."\n".
105               '});'."\n";
106          }
107         
108          if ($s->colorbox_zoom_icon && !$s->colorbox_zoom_icon_permanent)
109          {
110               echo
111               '$(\'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".
112               '$(\'img#colorbox_magnify\').click(function ()'."\n".
113                    '{ '."\n".
114                         '$("a.colorbox_zoom img.colorbox_hovered").click(); '."\n".
115                         '$("a.colorbox_zoom img.colorbox_hovered").removeClass(\'colorbox_hovered\');'."\n".
116                    '});'."\n".
117                    '$(\'a.colorbox_zoom img\').click(function ()'."\n". 
118                    '{ '."\n".
119                         '$(this).removeClass(\'colorbox_hovered\');'."\n".
120                    '});'."\n".
121                    '$("a.colorbox_zoom img").hover(function(){'."\n".
122                    'var p = $(this);'."\n".
123                    'p.addClass(\'colorbox_hovered\');'."\n".
124                    'var offset = p.offset();'."\n";
125
126               if (!$s->colorbox_position) {
127                    echo '$(\'img#colorbox_magnify\').css({\'top\' : offset.top, \'left\' : offset.left+p.outerWidth()-'.$icon_width.'});'."\n";
128               } else {
129                    echo '$(\'img#colorbox_magnify\').css({\'top\' : offset.top, \'left\' : offset.left});'."\n";
130               }
131               echo
132               '$(\'img#colorbox_magnify\').show();'."\n".
133               '},function(){'."\n".
134                    'var p = $(this);'."\n".
135                    'p.removeClass(\'colorbox_hovered\');'."\n".
136                    '$(\'img#colorbox_magnify\').hide();'."\n".
137               '});'."\n";
138          }
139         
140          foreach (unserialize($s->colorbox_advanced) as $k => $v) {
141               if ($v === '') {
142                    $opts[] = $k.': false';
143               }
144               elseif (is_bool($v)) {
145                    $opts[] = $k.': '.($v ? 'true' : 'false');
146               }
147               elseif (is_numeric($v)) {
148                    $opts[] = $k.": ".$v;
149               }
150               elseif (is_string($v)) {
151                    $opts[] = $k.": '".$v."'";
152               }
153          }
154         
155          echo 
156          "});\n".
157          '$("a[rel*=\'colorbox-\']").colorbox({'.implode(",\n",$opts).'});'."\n".
158          "});\n".
159          "\n//]]>\n".
160          "</script>\n";
161     }
162}
163
164?>
Note: See TracBrowser for help on using the repository browser.

Sites map