Skip to content

Commit

Permalink
Initial adding of angular directives
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Oct 6, 2012
1 parent 8899523 commit 5467323
Show file tree
Hide file tree
Showing 14 changed files with 16,564 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ lib-cov
*.out
*.pid
*.gz
*.swp
*.swo

pids
logs
results

node_modules
npm-debug.log
npm-debug.log
157 changes: 157 additions & 0 deletions build/angular-ui-bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
angular.module('ui.bootstrap', []);

angular.module('ui.bootstrap').directive('bsDropdownToggle',['$document', '$location', '$window',
function ($document, $location, $window) {
var openElement = null, close;
return {
restrict: 'C',
link: function(scope, element, attrs) {
scope.$watch(function(){return $location.path();}, function() {
if (close) {
close();
}
});

element.parent().bind('click', function(event) {
if (close) {
close();
}
});

element.bind('click', function(event) {
event.preventDefault();
event.stopPropagation();

var iWasOpen = false;

if (openElement) {
iWasOpen = openElement === element;
close();
}

if (!iWasOpen){
element.parent().addClass('open');
openElement = element;

close = function (event) {
if (event) {
event.preventDefault();
event.stopPropagation();
}
$document.unbind('click', close);
element.parent().removeClass('open');
close = null;
openElement = null;
};

$document.bind('click', close);
}
});
}
};
}]);


angular.module('ui.bootstrap').directive('bsTabbable', [function() {
return {
restrict: 'C',
compile: function(element) {
var navTabs = angular.element('<ul class="nav nav-tabs"></ul>'),
tabContent = angular.element('<div class="tab-content"></div>');

tabContent.append(element.contents());
element.append(navTabs).append(tabContent);
},
controller: ['$scope', '$element', function($scope, $element) {
var navTabs = $element.contents().eq(0),
ngModel = $element.controller('ngModel') || {},
tabs = [],
selectedTab;

ngModel.$render = function() {
var $viewValue = this.$viewValue;

if (selectedTab ? (selectedTab.value != $viewValue) : $viewValue) {
if(selectedTab) {
selectedTab.paneElement.removeClass('active');
selectedTab.tabElement.removeClass('active');
selectedTab = null;
}
if($viewValue) {
for(var i = 0, ii = tabs.length; i < ii; i++) {
if ($viewValue == tabs[i].value) {
selectedTab = tabs[i];
break;
}
}
if (selectedTab) {
selectedTab.paneElement.addClass('active');
selectedTab.tabElement.addClass('active');
}
}

}
};

this.addPane = function(element, attr) {
var li = angular.element('<li><a href></a></li>'),
a = li.find('a'),
tab = {
paneElement: element,
paneAttrs: attr,
tabElement: li
};

tabs.push(tab);

attr.$observe('value', update)();
attr.$observe('title', function(){ update(); a.text(tab.title); })();

function update() {
tab.title = attr.title;
tab.value = attr.value || attr.title;
if (!ngModel.$setViewValue && (!ngModel.$viewValue || tab == selectedTab)) {
// we are not part of angular
ngModel.$viewValue = tab.value;
}
ngModel.$render();
}

navTabs.append(li);
li.bind('click', function(event) {
event.preventDefault();
event.stopPropagation();
if (ngModel.$setViewValue) {
$scope.$apply(function() {
ngModel.$setViewValue(tab.value);
ngModel.$render();
});
} else {
// we are not part of angular
ngModel.$viewValue = tab.value;
ngModel.$render();
}
});

return function() {
tab.tabElement.remove();
for(var i = 0, ii = tabs.length; i < ii; i++ ) {
if (tab == tabs[i]) {
tabs.splice(i, 1);
}
}
};
};
}]
};
}]);

angular.module('ui.bootstrap').directive('bsTabPane', [function() {
return {
require: '^tabbable',
restrict: 'C',
link: function(scope, element, attrs, tabsCtrl) {
element.bind('$remove', tabsCtrl.addPane(element, attrs));
}
};
}]);
1 change: 1 addition & 0 deletions common/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
angular.module('ui.bootstrap', []);
50 changes: 50 additions & 0 deletions directives/dropdownToggle/dropdownToggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
angular.module('ui.bootstrap').directive('bsDropdownToggle',['$document', '$location', '$window',
function ($document, $location, $window) {
var openElement = null, close;
return {
restrict: 'C',
link: function(scope, element, attrs) {
scope.$watch(function(){return $location.path();}, function() {
if (close) {
close();
}
});

element.parent().bind('click', function(event) {
if (close) {
close();
}
});

element.bind('click', function(event) {
event.preventDefault();
event.stopPropagation();

var iWasOpen = false;

if (openElement) {
iWasOpen = openElement === element;
close();
}

if (!iWasOpen){
element.parent().addClass('open');
openElement = element;

close = function (event) {
if (event) {
event.preventDefault();
event.stopPropagation();
}
$document.unbind('click', close);
element.parent().removeClass('open');
close = null;
openElement = null;
};

$document.bind('click', close);
}
});
}
};
}]);
Empty file.
Empty file added directives/popover/popover.js
Empty file.
Empty file.
9 changes: 9 additions & 0 deletions directives/tabbable/tabPane.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
angular.module('ui.bootstrap').directive('bsTabPane', [function() {
return {
require: '^tabbable',
restrict: 'C',
link: function(scope, element, attrs, tabsCtrl) {
element.bind('$remove', tabsCtrl.addPane(element, attrs));
}
};
}]);
93 changes: 93 additions & 0 deletions directives/tabbable/tabbable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
angular.module('ui.bootstrap').directive('bsTabbable', [function() {
return {
restrict: 'C',
compile: function(element) {
var navTabs = angular.element('<ul class="nav nav-tabs"></ul>'),
tabContent = angular.element('<div class="tab-content"></div>');

tabContent.append(element.contents());
element.append(navTabs).append(tabContent);
},
controller: ['$scope', '$element', function($scope, $element) {
var navTabs = $element.contents().eq(0),
ngModel = $element.controller('ngModel') || {},
tabs = [],
selectedTab;

ngModel.$render = function() {
var $viewValue = this.$viewValue;

if (selectedTab ? (selectedTab.value != $viewValue) : $viewValue) {
if(selectedTab) {
selectedTab.paneElement.removeClass('active');
selectedTab.tabElement.removeClass('active');
selectedTab = null;
}
if($viewValue) {
for(var i = 0, ii = tabs.length; i < ii; i++) {
if ($viewValue == tabs[i].value) {
selectedTab = tabs[i];
break;
}
}
if (selectedTab) {
selectedTab.paneElement.addClass('active');
selectedTab.tabElement.addClass('active');
}
}

}
};

this.addPane = function(element, attr) {
var li = angular.element('<li><a href></a></li>'),
a = li.find('a'),
tab = {
paneElement: element,
paneAttrs: attr,
tabElement: li
};

tabs.push(tab);

attr.$observe('value', update)();
attr.$observe('title', function(){ update(); a.text(tab.title); })();

function update() {
tab.title = attr.title;
tab.value = attr.value || attr.title;
if (!ngModel.$setViewValue && (!ngModel.$viewValue || tab == selectedTab)) {
// we are not part of angular
ngModel.$viewValue = tab.value;
}
ngModel.$render();
}

navTabs.append(li);
li.bind('click', function(event) {
event.preventDefault();
event.stopPropagation();
if (ngModel.$setViewValue) {
$scope.$apply(function() {
ngModel.$setViewValue(tab.value);
ngModel.$render();
});
} else {
// we are not part of angular
ngModel.$viewValue = tab.value;
ngModel.$render();
}
});

return function() {
tab.tabElement.remove();
for(var i = 0, ii = tabs.length; i < ii; i++ ) {
if (tab == tabs[i]) {
tabs.splice(i, 1);
}
}
};
};
}]
};
}]);
Loading

0 comments on commit 5467323

Please sign in to comment.