Skip to content

Commit 2fb8399

Browse files
added options
1 parent 97a12fa commit 2fb8399

File tree

5 files changed

+27
-181
lines changed

5 files changed

+27
-181
lines changed

app/index.html

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title></title>
5+
<title>ui-accordion</title>
66
<meta name="description" content="">
77
<meta name="viewport" content="width=device-width">
88
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
@@ -14,63 +14,34 @@
1414
<link rel="stylesheet" href="styles/main.css">
1515
<!-- endbuild -->
1616
</head>
17-
<body ng-app="uiAccordionApp">
17+
<body ng-app="uiAccordion">
1818
<!--[if lte IE 8]>
1919
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
2020
<![endif]-->
2121

2222
<!-- Add your site or application content here -->
23-
<div class="header">
24-
<div class="navbar navbar-default" role="navigation">
25-
<div class="container">
26-
<div class="navbar-header">
27-
28-
<a class="navbar-brand" href="#/">uiAccordion</a>
29-
</div>
30-
31-
<div class="collapse">
32-
33-
<ul class="nav navbar-nav">
34-
<li class="active"><a href="#/">Home</a></li>
35-
<li><a ng-href="#/">About</a></li>
36-
<li><a ng-href="#/">Contact</a></li>
37-
</ul>
38-
</div>
39-
</div>
40-
</div>
41-
</div>
23+
4224

4325
<div class="container">
44-
<div ng-include="'views/main.html'" ng-controller="MainCtrl"></div>
45-
</div>
46-
47-
<div class="footer">
48-
<div class="container">
49-
<p><span class="glyphicon glyphicon-heart"></span> from the Yeoman team</p>
26+
<div ng-include="'views/main.html'" ng-controller="MainCtrl">
5027
</div>
5128
</div>
5229

53-
54-
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID -->
55-
<script>
56-
!function(A,n,g,u,l,a,r){A.GoogleAnalyticsObject=l,A[l]=A[l]||function(){
57-
(A[l].q=A[l].q||[]).push(arguments)},A[l].l=+new Date,a=n.createElement(g),
58-
r=n.getElementsByTagName(g)[0],a.src=u,r.parentNode.insertBefore(a,r)
59-
}(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
60-
61-
ga('create', 'UA-XXXXX-X');
62-
ga('send', 'pageview');
63-
</script>
64-
30+
6531
<!-- build:js(.) scripts/vendor.js -->
6632
<!-- bower:js -->
33+
<script src="bower_components/jquery/dist/jquery.js"></script>
6734
<script src="bower_components/angular/angular.js"></script>
6835
<!-- endbower -->
6936
<!-- endbuild -->
7037

7138
<!-- build:js({.tmp,app}) scripts/ui-accordion.js -->
7239
<script src="scripts/app.js"></script>
7340
<script src="scripts/controllers/main.js"></script>
41+
<script src="scripts/directives/ng-accordion.js"></script>
42+
<script src="scripts/directives/ng-accordion-group.js"></script>
43+
<script src="scripts/directives/ng-accordion-heading.js"></script>
44+
<script src="scripts/directives/ng-accordion-body.js"></script>
7445
<!-- endbuild -->
7546
</body>
7647
</html>

app/scripts/app.js

Lines changed: 11 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,16 @@
11
'use strict';
2-
(function(){
3-
angular.module('uiAccordion',[]);
4-
angular.module('uiAccordion')
5-
.directive('ngAccordion',function ($q,$log) {
6-
return {
7-
restrict: 'EA',
8-
controller: function () {
9-
var groups = [];
10-
this.addGroup = function(group) {
11-
groups.push(group);
12-
}
13-
this.getGroups=function(){
14-
return groups;
15-
}
16-
this.toggleState=function(group){
17-
for(var a=0;a<groups.length;a++){
18-
if(group==groups[a]){
19-
if(!group.open){
20-
group.beforeOpen().then(function(){
21-
group.body.show();
22-
group.open=!group.open;
23-
},function(error){
24-
$log.error(error);
25-
})
26-
}else{
27-
group.beforeHide().then(function(){
28-
group.open=false;
29-
group.body.hide();
30-
},function(error){
31-
$log.error(error);
32-
})
33-
}
34-
}else{
35-
(function(group){
36-
group.beforeHide().then(function(){
37-
group.open=false;
38-
group.body.hide();
39-
},function(error){
40-
$log.error(error);
41-
})
42-
})(groups[a]);
43-
}
44-
}
45-
}
46-
}
47-
};
48-
})
49-
.directive('ngAccordionGroup', function($q) {
50-
function defaultOptions(){
51-
return {
52-
beforeOpen:function(){
53-
var def=$q.defer();
54-
def.resolve();
55-
return def.promise;
56-
},
57-
beforeHide:function(){
58-
var def=$q.defer();
59-
def.resolve();
60-
return def.promise;
61-
},
62-
open:false
63-
}
2+
angular.module('uiAccordion',[]);
3+
function fetchFromObject(obj, prop) {
4+
5+
if(typeof obj === 'undefined' || typeof prop === 'undefined') {
6+
return ;
647
}
65-
return {
66-
require:['^ngAccordion','ngAccordionGroup'],
67-
restrict:'EA',
68-
controller:function(){
69-
var headerEl;
70-
var bodyEl;
71-
var headerDef=$q.defer();
72-
var bodyDef=$q.defer();
73-
this.setHeaderElement=function(element){
74-
headerDef.resolve(element);
75-
}
76-
this.getHeaderElement=function(){
77-
return headerDef.promise;
78-
}
79-
this.setBodyElement=function(element){
80-
bodyDef.resolve(element);
81-
}
82-
this.getBodyElement=function(){
83-
return bodyDef.promise;
84-
}
85-
},
86-
link: function(scope, element, attrs, controllers) {
87-
var controller=controllers[1];
88-
var accordionCtrl=controllers[0];
898

90-
var accordion=angular.extend(defaultOptions(),scope.$eval(attrs.options))
91-
$q.all([controller.getHeaderElement(),controller.getBodyElement()]).then(function(results){
92-
accordion.header=results[0];
93-
accordion.body=results[1];
94-
accordion.body.hide();
95-
accordion.header.on('click',function(){
96-
accordionCtrl.toggleState(accordion);
97-
});
98-
accordionCtrl.addGroup(accordion);
99-
})
9+
var _index = prop.indexOf('.')
10+
if(_index > -1) {
11+
return fetchFromObject(obj[prop.substring(0, _index)], prop.substr(_index + 1));
12+
}
10013

101-
}
102-
};
103-
})
104-
.directive('ngAccordionHeading', function() {
105-
return {
106-
require:'^ngAccordionGroup',
107-
restrict: 'EA',
108-
link: function(scope, element, attrs, accordionCtrl) {
109-
accordionCtrl.setHeaderElement(element);
110-
}
111-
};
112-
})
113-
.directive('ngAccordionBody', function() {
114-
return {
115-
require:'^ngAccordionGroup',
116-
restrict: 'EA',
117-
link: function(scope, element, attrs, accordionCtrl) {
118-
accordionCtrl.setBodyElement(element);
119-
}
120-
};
121-
})
122-
})()
14+
return obj[prop];
15+
}
12316

app/views/main.html

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
<div class="jumbotron">
2-
<h1>'Allo, 'Allo!</h1>
3-
<p class="lead">
4-
<img src="images/yeoman.png" alt="I'm Yeoman"><br>
5-
Always a pleasure scaffolding your apps.
6-
</p>
7-
<p><a class="btn btn-lg btn-success" ng-href="#/">Splendid!<span class="glyphicon glyphicon-ok"></span></a></p>
8-
</div>
9-
10-
<div class="row marketing">
11-
<h4>HTML5 Boilerplate</h4>
12-
<p>
13-
HTML5 Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites.
14-
</p>
15-
16-
<h4>Angular</h4>
17-
<p>
18-
AngularJS is a toolset for building the framework most suited to your application development.
19-
</p>
20-
21-
<h4>Karma</h4>
22-
<p>Spectacular Test Runner for JavaScript.</p>
1+
<div class="container" ng-controller="MainCtrl">
2+
<ng-include src="'views/simple-accordion.html'"></ng-include>
3+
<!--<ng-include src="'views/nested-accordion.html'"></ng-include>-->
234
</div>

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "ui-accordion",
33
"version": "1.0.6",
44
"dependencies": {
5-
"angular": "^1.3.0"
5+
"angular": "^1.3.0",
6+
"jquery": "~2.1.4"
67
},
78
"main": "dist/scripts/ui-accordion.js",
89
"devDependencies": {

test/spec/controllers/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe('Controller: MainCtrl', function () {
44

55
// load the controller's module
6-
beforeEach(module('uiGridApp'));
6+
beforeEach(module('uiAccordion'));
77

88
var MainCtrl,
99
scope;

0 commit comments

Comments
 (0)