1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # |
---|
4 | # This file is part of ColorBox, a plugin for Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2010 Philippe aka amalgame and Tomtom |
---|
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 | $core->addBehavior('publicFooterContent',array('colorboxPublic','publicFooterContent')); |
---|
15 | |
---|
16 | class colorboxPublic |
---|
17 | { |
---|
18 | public static function publicHeadContent($core) |
---|
19 | { |
---|
20 | # Settings |
---|
21 | |
---|
22 | $s =& $core->blog->settings->colorbox; |
---|
23 | |
---|
24 | if (!$s->colorbox_enabled) { |
---|
25 | return; |
---|
26 | } |
---|
27 | |
---|
28 | $url = $core->blog->getQmarkURL().'pf='.basename(dirname(__FILE__)); |
---|
29 | |
---|
30 | echo |
---|
31 | '<style type="text/css">'."\n". |
---|
32 | '@import url('.$url.'/css/colorbox_common.css);'."\n". |
---|
33 | "</style>\n". |
---|
34 | '<style type="text/css">'."\n". |
---|
35 | '@import url('.$url.'/themes/'.$s->colorbox_theme.'/colorbox_theme.css);'."\n". |
---|
36 | "</style>\n"; |
---|
37 | |
---|
38 | if ($s->colorbox_user_files) { |
---|
39 | $public_path = $core->blog->public_path; |
---|
40 | $public_url = $core->blog->settings->system->public_url; |
---|
41 | $colorbox_user_path = $public_path.'/colorbox/themes/'; |
---|
42 | $colorbox_user_url = $public_url.'/colorbox/themes/'; |
---|
43 | |
---|
44 | if (file_exists($colorbox_user_path.$s->colorbox_theme.'/colorbox_user.css')){ |
---|
45 | echo |
---|
46 | '<style type="text/css">'."\n". |
---|
47 | '@import url('.$colorbox_user_url.$s->colorbox_theme.'/colorbox_user.css);'."\n". |
---|
48 | "</style>\n"; |
---|
49 | } |
---|
50 | } else { |
---|
51 | $theme_path = path::fullFromRoot($core->blog->settings->system->themes_path."/".$core->blog->settings->system->theme,DC_ROOT);; |
---|
52 | $theme_url = $core->blog->settings->system->themes_url."/".$core->blog->settings->system->theme; |
---|
53 | $colorbox_user_path = $theme_path.'/colorbox/themes/'.$s->colorbox_theme.'/colorbox_user.css'; |
---|
54 | $colorbox_user_url = $theme_url.'/colorbox/themes/'.$s->colorbox_theme.'/colorbox_user.css'; |
---|
55 | if (file_exists($colorbox_user_path)){ |
---|
56 | echo |
---|
57 | '<style type="text/css">'."\n". |
---|
58 | '@import url('.$colorbox_user_url.');'."\n". |
---|
59 | "</style>\n"; |
---|
60 | }; |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | } |
---|
65 | public static function publicFooterContent($core) |
---|
66 | { |
---|
67 | # Settings |
---|
68 | |
---|
69 | $s =& $core->blog->settings->colorbox; |
---|
70 | |
---|
71 | if (!$s->colorbox_enabled) { |
---|
72 | return; |
---|
73 | } |
---|
74 | |
---|
75 | $url = $core->blog->getQmarkURL().'pf='.basename(dirname(__FILE__)); |
---|
76 | |
---|
77 | $icon_name = 'zoom.png'; |
---|
78 | $icon_width = '16'; |
---|
79 | $icon_height = '16'; |
---|
80 | |
---|
81 | echo |
---|
82 | '<script type="text/javascript" src="'.$url.'/js/jquery.colorbox-min.js"></script>'."\n". |
---|
83 | '<script type="text/javascript">'."\n". |
---|
84 | "//<![CDATA[\n"; |
---|
85 | |
---|
86 | $selectors = 'div.post'.($s->colorbox_selectors !== '' ? ','.$s->colorbox_selectors : ''); |
---|
87 | |
---|
88 | echo |
---|
89 | '$(window).load(function(){'. |
---|
90 | 'var count = 0; '. |
---|
91 | '$("'.$selectors.'").each(function() {'."\n". |
---|
92 | 'count++;'."\n". |
---|
93 | '$(this).find("a[href$=.jpg],a[href$=.jpeg],a[href$=.png],a[href$=.gif],'. |
---|
94 | 'a[href$=.JPG],a[href$=.JPEG],a[href$=.PNG],a[href$=.GIF]").addClass("colorbox_zoom");'."\n". |
---|
95 | '$(this).find("a[href$=.jpg],a[href$=.jpeg],a[href$=.png],a[href$=.gif],'. |
---|
96 | 'a[href$=.JPG],a[href$=.JPEG],a[href$=.PNG],a[href$=.GIF]").attr("rel", "colorbox-"+count);'."\n"; |
---|
97 | |
---|
98 | echo |
---|
99 | '$(this).find("a.colorbox_zoom").each(function(){'."\n". |
---|
100 | 'var p = $(this).find("img");'."\n". |
---|
101 | 'if (p.attr("title") != 0 && $(this).attr("title") == 0){'."\n". |
---|
102 | '$(this).attr("title", p.attr("title"));'."\n". |
---|
103 | '}'."\n". |
---|
104 | '});'."\n"; |
---|
105 | |
---|
106 | if ($s->colorbox_zoom_icon_permanent) |
---|
107 | { |
---|
108 | echo |
---|
109 | '$(this).find("a.colorbox_zoom").each(function(){'."\n". |
---|
110 | 'var p = $(this).find("img");'."\n". |
---|
111 | 'if (p.length != 0){'."\n". |
---|
112 | 'var offset = p.offset();'."\n". |
---|
113 | 'var parent = p.offsetParent();'."\n". |
---|
114 | 'var offsetparent = parent.offset();'."\n". |
---|
115 | 'var parenttop = offsetparent.top;'."\n". |
---|
116 | 'var parentleft = offsetparent.left;'."\n". |
---|
117 | 'var top = offset.top-parenttop;'."\n"; |
---|
118 | |
---|
119 | if ($s->colorbox_position) { |
---|
120 | echo 'var left = offset.left-parentleft;'."\n"; |
---|
121 | } else { |
---|
122 | echo 'var left = offset.left-parentleft+p.outerWidth()-'.$icon_width.';'."\n"; |
---|
123 | } |
---|
124 | |
---|
125 | 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". |
---|
126 | '}'."\n". |
---|
127 | '});'."\n"; |
---|
128 | } |
---|
129 | |
---|
130 | if ($s->colorbox_zoom_icon && !$s->colorbox_zoom_icon_permanent) |
---|
131 | { |
---|
132 | echo |
---|
133 | '$(\'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". |
---|
134 | '$(\'img#colorbox_magnify\').click(function ()'."\n". |
---|
135 | '{ '."\n". |
---|
136 | '$("a.colorbox_zoom img.colorbox_hovered").click(); '."\n". |
---|
137 | '$("a.colorbox_zoom img.colorbox_hovered").removeClass(\'colorbox_hovered\');'."\n". |
---|
138 | '});'."\n". |
---|
139 | '$(\'a.colorbox_zoom img\').click(function ()'."\n". |
---|
140 | '{ '."\n". |
---|
141 | '$(this).removeClass(\'colorbox_hovered\');'."\n". |
---|
142 | '});'."\n". |
---|
143 | '$("a.colorbox_zoom img").hover(function(){'."\n". |
---|
144 | 'var p = $(this);'."\n". |
---|
145 | 'p.addClass(\'colorbox_hovered\');'."\n". |
---|
146 | 'var offset = p.offset();'."\n"; |
---|
147 | |
---|
148 | if (!$s->colorbox_position) { |
---|
149 | echo '$(\'img#colorbox_magnify\').css({\'top\' : offset.top, \'left\' : offset.left+p.outerWidth()-'.$icon_width.'});'."\n"; |
---|
150 | } else { |
---|
151 | echo '$(\'img#colorbox_magnify\').css({\'top\' : offset.top, \'left\' : offset.left});'."\n"; |
---|
152 | } |
---|
153 | echo |
---|
154 | '$(\'img#colorbox_magnify\').show();'."\n". |
---|
155 | '},function(){'."\n". |
---|
156 | 'var p = $(this);'."\n". |
---|
157 | 'p.removeClass(\'colorbox_hovered\');'."\n". |
---|
158 | '$(\'img#colorbox_magnify\').hide();'."\n". |
---|
159 | '});'."\n"; |
---|
160 | } |
---|
161 | |
---|
162 | foreach (unserialize($s->colorbox_advanced) as $k => $v) { |
---|
163 | if ($v === '') { |
---|
164 | $opts[] = $k.': false'; |
---|
165 | } |
---|
166 | elseif (is_bool($v)) { |
---|
167 | $opts[] = $k.': '.($v ? 'true' : 'false'); |
---|
168 | } |
---|
169 | elseif (is_numeric($v)) { |
---|
170 | $opts[] = $k.": ".$v; |
---|
171 | } |
---|
172 | elseif (is_string($v)) { |
---|
173 | $opts[] = $k.": '".$v."'"; |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | echo |
---|
178 | "});\n". |
---|
179 | '$("a[rel*=\'colorbox-\']").colorbox({'.implode(",\n",$opts).'});'."\n". |
---|
180 | "});\n". |
---|
181 | "\n//]]>\n". |
---|
182 | "</script>\n"; |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | ?> |
---|