Skip to content

Commit ac2922c

Browse files
committed
commit code
1 parent d4ccf1e commit ac2922c

File tree

7 files changed

+599
-1
lines changed

7 files changed

+599
-1
lines changed

README.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,45 @@
11
# angular-mega-menu
2-
Base on angular-ui/bootstrap and geedmo/yamm3
2+
3+
This is angular mega menu, base on [angular-ui/bootstrap](https://github.com/angular-ui/bootstrap) dropdown directive and [geedmo/yamm3](This is angular mega menu, base on [angular-ui/bootstrap](https://github.com/angular-ui/bootstrap) dropdown directive and [geedmo/yamm3]().
4+
).
5+
6+
Angular mega menu is extend from dropdown directive, so you use it just like using dropdown directive.
7+
8+
### How to Use
9+
- Include JavaScript and CSS.
10+
11+
```html
12+
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
13+
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap-theme.min.css">
14+
<link rel="stylesheet" href="bower_components/yamm3/yamm/yamm.css">
15+
<script src="bower_components/jquery/dist/jquery.min.js"></script>
16+
<script src="bower_components/angular/angular.js"></script>
17+
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
18+
<script src="src/js/angular-mega-menu.js"></script>
19+
```
20+
21+
- Configure angular module
22+
23+
```js
24+
angular.module('test', ['mega-menu']);
25+
```
26+
27+
- Use bootstrap-ui dropdown directive
28+
- Use dropdown directive.
29+
- Set event-toggle attribute, default value is 'click', you can set value 'mouseover'.
30+
31+
```html
32+
...
33+
<li class="dropdown" dropdown>
34+
<a class="dropdown-toggle" dropdown-toggle event-toggle="mouseover" href="#">Classic<b class="caret"></b></a>
35+
<ul role="menu" class="dropdown-menu">
36+
<li><a tabindex="-1" href="#"> Action </a></li>
37+
<li><a tabindex="-1" href="#"> Another action </a></li>
38+
<li><a tabindex="-1" href="#"> Something else here </a></li>
39+
<li class="divider"></li>
40+
<li><a tabindex="-1" href="#"> Separated link </a></li>
41+
</ul>
42+
</li>
43+
...
44+
```
45+
### Example

bower.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "angular-mega-menu",
3+
"version": "0.0.0",
4+
"homepage": "https://github.com/hjzheng/angular-mega-menu",
5+
"authors": [
6+
"hjzheng <[email protected]>"
7+
],
8+
"description": "base on angular-ui/bootstrap and geedmo/yamm3",
9+
"license": "MIT",
10+
"ignore": [
11+
"**/.*",
12+
"node_modules",
13+
"bower_components",
14+
"test",
15+
"tests"
16+
],
17+
"dependencies": {
18+
"angular-bootstrap": "~0.13.0",
19+
"yamm3": "~1.1.0"
20+
}
21+
}

img/190.jpg

4.52 KB
Loading

img/260.jpg

10.1 KB
Loading

img/64x64.gif

239 Bytes
Loading

index.html

+375
Large diffs are not rendered by default.

src/js/angular-mega-menu.js

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
(function() {
2+
3+
angular.module("mega-menu", ["ui.bootstrap"]);
4+
5+
angular.module('mega-menu').config(ExtendDropdownToggleDirective);
6+
7+
ExtendDropdownToggleDirective.$inject = ['$provide'];
8+
9+
function ExtendDropdownToggleDirective($provide) {
10+
11+
$provide.decorator('dropdownToggleDirective', ["$delegate", "$document", function($delegate, $document) {
12+
13+
var directive = $delegate[0];
14+
15+
var link = directive.link;
16+
17+
directive.compile = function() {
18+
return function(scope, element, attrs, dropdownCtrl) {
19+
20+
if ( !dropdownCtrl ) {
21+
return;
22+
}
23+
24+
dropdownCtrl.toggleElement = element;
25+
26+
var toggleDropdown = function(evt) {
27+
evt.preventDefault();
28+
29+
if ( evt && element && element[0].parentElement.contains(evt.target) && dropdownCtrl.isOpen() && attrs.eventToggle == "mouseover" ) {
30+
return;
31+
}
32+
33+
if ( !element.hasClass('disabled') && !attrs.disabled ) {
34+
scope.$apply(function() {
35+
dropdownCtrl.toggle();
36+
});
37+
}
38+
};
39+
40+
if(attrs.eventToggle !== "mouseover"){
41+
element.bind('click', toggleDropdown);
42+
} else {
43+
element.bind('mouseover', toggleDropdown);
44+
}
45+
46+
// WAI-ARIA
47+
element.attr({ 'aria-haspopup': true, 'aria-expanded': false });
48+
scope.$watch(dropdownCtrl.isOpen, function( isOpen ) {
49+
element.attr('aria-expanded', !!isOpen);
50+
});
51+
52+
scope.$on('$destroy', function() {
53+
if(attrs.eventToggle !== "mouseover"){
54+
element.unbind('click', toggleDropdown);
55+
} else {
56+
element.unbind('mouseover', toggleDropdown);
57+
}
58+
});
59+
60+
};
61+
};
62+
63+
return $delegate;
64+
}]);
65+
66+
$provide.decorator('dropdownService', ['$delegate', '$document', '$rootScope', function ($delegate, $document, $rootScope) {
67+
//var openBackup = $delegate.open;
68+
//var closeBackup = $delegate.close;
69+
70+
//override open method
71+
$delegate.open = function () {
72+
open.apply($delegate, arguments);
73+
};
74+
75+
//override close method
76+
$delegate.close = function () {
77+
close.apply($delegate, arguments);
78+
};
79+
80+
81+
var openScope = null;
82+
83+
var open = function( dropdownScope ) {
84+
85+
var toggleElement = dropdownScope.getToggleElement();
86+
var eventToggle = toggleElement.attr("event-toggle");
87+
88+
if ( !openScope ) {
89+
if(eventToggle == 'mouseover'){
90+
$document.bind('mouseover', closeDropdown);
91+
} else{
92+
$document.bind('click', closeDropdown);
93+
$document.bind('keydown', keybindFilter);
94+
}
95+
}
96+
97+
if ( openScope && openScope !== dropdownScope ) {
98+
openScope.isOpen = false;
99+
}
100+
101+
openScope = dropdownScope;
102+
};
103+
104+
var close = function( dropdownScope ) {
105+
var toggleElement = dropdownScope.getToggleElement();
106+
var eventToggle = toggleElement.attr("event-toggle");
107+
108+
if ( openScope === dropdownScope ) {
109+
openScope = null;
110+
if(eventToggle == 'mouseover'){
111+
$document.unbind('mouseover', closeDropdown);
112+
} else{
113+
$document.unbind('click', closeDropdown);
114+
$document.unbind('keydown', keybindFilter);
115+
}
116+
}
117+
};
118+
119+
var closeDropdown = function( evt ) {
120+
// This method may still be called during the same mouse event that
121+
// unbound this event handler. So check openScope before proceeding.
122+
if (!openScope) { return; }
123+
124+
if( evt && openScope.getAutoClose() === 'disabled' ) { return ; }
125+
126+
var toggleElement = openScope.getToggleElement();
127+
if ( evt && toggleElement && toggleElement[0].parentElement.contains(evt.target) ) {
128+
return;
129+
}
130+
131+
var $element = openScope.getElement();
132+
if( evt && openScope.getAutoClose() === 'outsideClick' && $element && $element[0].contains(evt.target) ) {
133+
return;
134+
}
135+
136+
openScope.isOpen = false;
137+
138+
if (!$rootScope.$$phase) {
139+
openScope.$apply();
140+
}
141+
};
142+
143+
var keybindFilter = function( evt ) {
144+
if ( evt.which === 27 ) {
145+
openScope.focusToggleElement();
146+
closeDropdown();
147+
}
148+
else if ( openScope.isKeynavEnabled() && /(38|40)/.test(evt.which) && openScope.isOpen ) {
149+
evt.preventDefault();
150+
evt.stopPropagation();
151+
openScope.focusDropdownEntry(evt.which);
152+
}
153+
};
154+
155+
return $delegate;
156+
}]);
157+
}
158+
159+
})();

0 commit comments

Comments
 (0)