aboutsummaryrefslogtreecommitdiffstats
path: root/docs/components/angular-bootstrap
diff options
context:
space:
mode:
Diffstat (limited to 'docs/components/angular-bootstrap')
-rw-r--r--docs/components/angular-bootstrap/bootstrap-prettify.js290
-rw-r--r--docs/components/angular-bootstrap/bootstrap.js212
2 files changed, 502 insertions, 0 deletions
diff --git a/docs/components/angular-bootstrap/bootstrap-prettify.js b/docs/components/angular-bootstrap/bootstrap-prettify.js
new file mode 100644
index 00000000..cbe7b53f
--- /dev/null
+++ b/docs/components/angular-bootstrap/bootstrap-prettify.js
@@ -0,0 +1,290 @@
+'use strict';
+
+var directive = {};
+var service = { value: {} };
+
+var DEPENDENCIES = {
+ 'angular.js': 'http://code.angularjs.org/' + angular.version.full + '/angular.min.js',
+ 'angular-resource.js': 'http://code.angularjs.org/' + angular.version.full + '/angular-resource.min.js',
+ 'angular-route.js': 'http://code.angularjs.org/' + angular.version.full + '/angular-route.min.js',
+ 'angular-sanitize.js': 'http://code.angularjs.org/' + angular.version.full + '/angular-sanitize.min.js',
+ 'angular-cookies.js': 'http://code.angularjs.org/' + angular.version.full + '/angular-cookies.min.js'
+};
+
+
+function escape(text) {
+ return text.
+ replace(/\&/g, '&').
+ replace(/\</g, '&lt;').
+ replace(/\>/g, '&gt;').
+ replace(/"/g, '&quot;');
+}
+
+/**
+ * http://stackoverflow.com/questions/451486/pre-tag-loses-line-breaks-when-setting-innerhtml-in-ie
+ * http://stackoverflow.com/questions/195363/inserting-a-newline-into-a-pre-tag-ie-javascript
+ */
+function setHtmlIe8SafeWay(element, html) {
+ var newElement = angular.element('<pre>' + html + '</pre>');
+
+ element.html('');
+ element.append(newElement.contents());
+ return element;
+}
+
+
+directive.jsFiddle = function(getEmbeddedTemplate, escape, script) {
+ return {
+ terminal: true,
+ link: function(scope, element, attr) {
+ var name = '',
+ stylesheet = '<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">\n',
+ fields = {
+ html: '',
+ css: '',
+ js: ''
+ };
+
+ angular.forEach(attr.jsFiddle.split(' '), function(file, index) {
+ var fileType = file.split('.')[1];
+
+ if (fileType == 'html') {
+ if (index == 0) {
+ fields[fileType] +=
+ '<div ng-app' + (attr.module ? '="' + attr.module + '"' : '') + '>\n' +
+ getEmbeddedTemplate(file, 2);
+ } else {
+ fields[fileType] += '\n\n\n <!-- CACHE FILE: ' + file + ' -->\n' +
+ ' <script type="text/ng-template" id="' + file + '">\n' +
+ getEmbeddedTemplate(file, 4) +
+ ' </script>\n';
+ }
+ } else {
+ fields[fileType] += getEmbeddedTemplate(file) + '\n';
+ }
+ });
+
+ fields.html += '</div>\n';
+
+ setHtmlIe8SafeWay(element,
+ '<form class="jsfiddle" method="post" action="http://jsfiddle.net/api/post/library/pure/" target="_blank">' +
+ hiddenField('title', 'AngularJS Example: ' + name) +
+ hiddenField('css', '</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ --> \n' +
+ stylesheet +
+ script.angular +
+ (attr.resource ? script.resource : '') +
+ '<style>\n' +
+ fields.css) +
+ hiddenField('html', fields.html) +
+ hiddenField('js', fields.js) +
+ '<button class="btn btn-primary"><i class="icon-white icon-pencil"></i> Edit Me</button>' +
+ '</form>');
+
+ function hiddenField(name, value) {
+ return '<input type="hidden" name="' + name + '" value="' + escape(value) + '">';
+ }
+ }
+ }
+};
+
+
+directive.code = function() {
+ return {restrict: 'E', terminal: true};
+};
+
+
+directive.prettyprint = ['reindentCode', function(reindentCode) {
+ return {
+ restrict: 'C',
+ terminal: true,
+ compile: function(element) {
+ element.html(window.prettyPrintOne(reindentCode(element.html()), undefined, true));
+ }
+ };
+}];
+
+
+directive.ngSetText = ['getEmbeddedTemplate', function(getEmbeddedTemplate) {
+ return {
+ restrict: 'CA',
+ priority: 10,
+ compile: function(element, attr) {
+ setHtmlIe8SafeWay(element, escape(getEmbeddedTemplate(attr.ngSetText)));
+ }
+ }
+}]
+
+
+directive.ngHtmlWrap = ['reindentCode', 'templateMerge', function(reindentCode, templateMerge) {
+ return {
+ compile: function(element, attr) {
+ var properties = {
+ head: '',
+ module: '',
+ body: element.text()
+ },
+ html = "<!doctype html>\n<html ng-app{{module}}>\n <head>\n{{head:4}} </head>\n <body>\n{{body:4}} </body>\n</html>";
+
+ angular.forEach((attr.ngHtmlWrap || '').split(' '), function(dep) {
+ if (!dep) return;
+ dep = DEPENDENCIES[dep] || dep;
+
+ var ext = dep.split(/\./).pop();
+
+ if (ext == 'css') {
+ properties.head += '<link rel="stylesheet" href="' + dep + '" type="text/css">\n';
+ } else if(ext == 'js') {
+ properties.head += '<script src="' + dep + '"></script>\n';
+ } else {
+ properties.module = '="' + dep + '"';
+ }
+ });
+
+ setHtmlIe8SafeWay(element, escape(templateMerge(html, properties)));
+ }
+ }
+}];
+
+
+directive.ngSetHtml = ['getEmbeddedTemplate', function(getEmbeddedTemplate) {
+ return {
+ restrict: 'CA',
+ priority: 10,
+ compile: function(element, attr) {
+ setHtmlIe8SafeWay(element, getEmbeddedTemplate(attr.ngSetHtml));
+ }
+ }
+}];
+
+
+directive.ngEvalJavascript = ['getEmbeddedTemplate', function(getEmbeddedTemplate) {
+ return {
+ compile: function (element, attr) {
+ var script = getEmbeddedTemplate(attr.ngEvalJavascript);
+
+ try {
+ if (window.execScript) { // IE
+ window.execScript(script || '""'); // IE complains when evaling empty string
+ } else {
+ window.eval(script);
+ }
+ } catch (e) {
+ if (window.console) {
+ window.console.log(script, '\n', e);
+ } else {
+ window.alert(e);
+ }
+ }
+ }
+ };
+}];
+
+
+directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location', '$sniffer',
+ function($templateCache, $browser, docsRootScope, $location, $sniffer) {
+ return {
+ terminal: true,
+ link: function(scope, element, attrs) {
+ var modules = [];
+
+ modules.push(['$provide', function($provide) {
+ $provide.value('$templateCache', $templateCache);
+ $provide.value('$anchorScroll', angular.noop);
+ $provide.value('$browser', $browser);
+ $provide.value('$sniffer', $sniffer);
+ $provide.provider('$location', function() {
+ this.$get = ['$rootScope', function($rootScope) {
+ docsRootScope.$on('$locationChangeSuccess', function(event, oldUrl, newUrl) {
+ $rootScope.$broadcast('$locationChangeSuccess', oldUrl, newUrl);
+ });
+ return $location;
+ }];
+ this.html5Mode = angular.noop;
+ });
+ $provide.decorator('$timeout', ['$rootScope', '$delegate', function($rootScope, $delegate) {
+ return angular.extend(function(fn, delay) {
+ if (delay && delay > 50) {
+ return setTimeout(function() {
+ $rootScope.$apply(fn);
+ }, delay);
+ } else {
+ return $delegate.apply(this, arguments);
+ }
+ }, $delegate);
+ }]);
+ $provide.decorator('$rootScope', ['$delegate', function(embedRootScope) {
+ docsRootScope.$watch(function embedRootScopeDigestWatch() {
+ embedRootScope.$digest();
+ });
+ return embedRootScope;
+ }]);
+ }]);
+ if (attrs.ngEmbedApp) modules.push(attrs.ngEmbedApp);
+
+ element.bind('click', function(event) {
+ if (event.target.attributes.getNamedItem('ng-click')) {
+ event.preventDefault();
+ }
+ });
+
+ angular.bootstrap(element, modules);
+ }
+ };
+}];
+
+service.reindentCode = function() {
+ return function (text, spaces) {
+ if (!text) return text;
+ var lines = text.split(/\r?\n/);
+ var prefix = ' '.substr(0, spaces || 0);
+ var i;
+
+ // remove any leading blank lines
+ while (lines.length && lines[0].match(/^\s*$/)) lines.shift();
+ // remove any trailing blank lines
+ while (lines.length && lines[lines.length - 1].match(/^\s*$/)) lines.pop();
+ var minIndent = 999;
+ for (i = 0; i < lines.length; i++) {
+ var line = lines[0];
+ var reindentCode = line.match(/^\s*/)[0];
+ if (reindentCode !== line && reindentCode.length < minIndent) {
+ minIndent = reindentCode.length;
+ }
+ }
+
+ for (i = 0; i < lines.length; i++) {
+ lines[i] = prefix + lines[i].substring(minIndent);
+ }
+ lines.push('');
+ return lines.join('\n');
+ }
+};
+
+service.templateMerge = ['reindentCode', function(indentCode) {
+ return function(template, properties) {
+ return template.replace(/\{\{(\w+)(?:\:(\d+))?\}\}/g, function(_, key, indent) {
+ var value = properties[key];
+
+ if (indent) {
+ value = indentCode(value, indent);
+ }
+
+ return value == undefined ? '' : value;
+ });
+ };
+}];
+
+service.getEmbeddedTemplate = ['reindentCode', function(reindentCode) {
+ return function (id) {
+ var element = document.getElementById(id);
+
+ if (!element) {
+ return null;
+ }
+
+ return reindentCode(angular.element(element).html(), 0);
+ }
+}];
+
+
+angular.module('bootstrapPrettify', []).directive(directive).factory(service);
diff --git a/docs/components/angular-bootstrap/bootstrap.js b/docs/components/angular-bootstrap/bootstrap.js
new file mode 100644
index 00000000..3e1c8d00
--- /dev/null
+++ b/docs/components/angular-bootstrap/bootstrap.js
@@ -0,0 +1,212 @@
+'use strict';
+
+var directive = {};
+
+directive.dropdownToggle =
+ ['$document', '$location', '$window',
+ function ($document, $location, $window) {
+ var openElement = null, close;
+ return {
+ restrict: 'C',
+ link: function(scope, element, attrs) {
+ scope.$watch(function dropdownTogglePathWatch(){return $location.path();}, function dropdownTogglePathWatchAction() {
+ close && close();
+ });
+
+ element.parent().bind('click', function(event) {
+ 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) {
+ event && event.preventDefault();
+ event && event.stopPropagation();
+ $document.unbind('click', close);
+ element.parent().removeClass('open');
+ close = null;
+ openElement = null;
+ }
+
+ $document.bind('click', close);
+ }
+ });
+ }
+ };
+ }];
+
+directive.syntax = function() {
+ return {
+ restrict: 'A',
+ link: function(scope, element, attrs) {
+ function makeLink(type, text, link, icon) {
+ return '<a href="' + link + '" class="btn syntax-' + type + '" target="_blank" rel="nofollow">' +
+ '<span class="' + icon + '"></span> ' + text +
+ '</a>';
+ };
+
+ var html = '';
+ var types = {
+ 'github' : {
+ text : 'View on Github',
+ key : 'syntaxGithub',
+ icon : 'icon-github'
+ },
+ 'plunkr' : {
+ text : 'View on Plunkr',
+ key : 'syntaxPlunkr',
+ icon : 'icon-arrow-down'
+ },
+ 'jsfiddle' : {
+ text : 'View on JSFiddle',
+ key : 'syntaxFiddle',
+ icon : 'icon-cloud'
+ }
+ };
+ for(var type in types) {
+ var data = types[type];
+ var link = attrs[data.key];
+ if(link) {
+ html += makeLink(type, data.text, link, data.icon);
+ }
+ };
+
+ var nav = document.createElement('nav');
+ nav.className = 'syntax-links';
+ nav.innerHTML = html;
+
+ var node = element[0];
+ var par = node.parentNode;
+ par.insertBefore(nav, node);
+ }
+ }
+}
+
+directive.tabbable = 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);
+ }
+ }
+ };
+ }
+ }]
+ };
+};
+
+directive.table = function() {
+ return {
+ restrict: 'E',
+ link: function(scope, element, attrs) {
+ element[0].className = 'table table-bordered table-striped code-table';
+ }
+ };
+};
+
+directive.tabPane = function() {
+ return {
+ require: '^tabbable',
+ restrict: 'C',
+ link: function(scope, element, attrs, tabsCtrl) {
+ element.bind('$remove', tabsCtrl.addPane(element, attrs));
+ }
+ };
+};
+
+
+angular.module('bootstrap', []).directive(directive);