-
Notifications
You must be signed in to change notification settings - Fork 1
/
EIconizedMenu.php
62 lines (56 loc) · 1.6 KB
/
EIconizedMenu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
Yii::import('zii.widgets.CMenu');
/**
* EIconizedMenu
*
* Automatically adds favicons in front of menu links.
*
* @author Alexander Makarov
* @version 1.2.1
*/
class EIconizedMenu extends CMenu {
public $useSprites = true;
public $yandexBaseUrl = 'http://favicon.yandex.net/favicon/';
public $iconizerBaseUrl = 'http://www.google.com/s2/favicons?domain=';
function init(){
parent::init();
if(!empty($this->htmlOptions['class']))
$this->htmlOptions['class'].=' iconized';
else
$this->htmlOptions['class']='iconized';
Yii::app()->clientScript->registerCss('iconized_menu_css',
<<<CSS
.iconized a {
padding-left: 20px;
background: no-repeat 0 50%;
height: 16px;
display:-moz-inline-stack;
display:inline-block;
_overflow:hidden;
*zoom:1;
*display:inline;
}
CSS
);
if($this->useSprites){
$domains = array();
foreach($this->items as $item){
$components = parse_url($item['url']);
$domains[] = $components['host'];
}
$spriteUrl = $this->yandexBaseUrl.implode('/', $domains);
$offset = 0;
foreach($this->items as &$item){
$item['linkOptions']['style'] = "background-image: url($spriteUrl); background-position: 0 {$offset}px";
$offset -= 16;
}
}
else {
foreach($this->items as &$item){
$components = parse_url($item['url']);
$iconUrl = $this->iconizerBaseUrl.$components['host'];
$item['linkOptions']['style'] = "background-image: url($iconUrl)";
}
}
}
}