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