forked from mgcrea/angular-strap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
152 lines (113 loc) · 3.72 KB
/
Copy pathapp.js
File metadata and controls
152 lines (113 loc) · 3.72 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
'use strict';
angular.module('mgcrea.ngStrapDocs', [
'mgcrea.ngStrap',
'mgcrea.ngPlunkr',
'ngRoute',
'ngAnimate'
])
.constant('version', 'v2.1.6')
.config(function($plunkrProvider, version) {
angular.extend($plunkrProvider.defaults, {
plunkrTitle: 'AngularStrap Example Plunkr',
plunkrTags: ['angular', 'angular-strap'],
plunkrPrivate: false,
contentHtmlUrlPrefix: 'https://rawgit.com/mgcrea/angular-strap/' + version + '/src/',
contentJsUrlPrefix: 'https://rawgit.com/mgcrea/angular-strap/' + version + '/src/'
});
})
.config(function($routeProvider, $compileProvider, $locationProvider, $sceProvider) {
// Configure html5 to get links working on jsfiddle
$locationProvider.html5Mode(false);
// Disable strict context
$sceProvider.enabled(false);
// Disable scope debug data
$compileProvider.debugInfoEnabled(false);
})
.controller('MainCtrl', function ($scope, $rootScope, $location, $anchorScroll, $plunkr) {
$scope.$location = $location;
$scope.$scrollTo = function(hash) {
$location.hash(hash);
$anchorScroll();
};
$scope.createPlunkr = function() {
var myPlunkr = $plunkr();
};
})
.run(function($window, $rootScope, $location, $anchorScroll, version) {
$rootScope.version = version;
// FastClick
$window.FastClick.attach($window.document.body);
// Support simple anchor id scrolling
var bodyElement = angular.element($window.document.body);
bodyElement.on('click', function(evt) {
var el = angular.element(evt.target);
var hash = el.attr('href');
if(!hash || hash[0] !== '#') return;
if(hash.length > 1 && hash[1] === '/') return;
if(evt.which !== 1) return;
$location.hash(hash.substr(1));
$anchorScroll();
});
// Initial $anchorScroll()
setTimeout(function() {
$anchorScroll();
}, 0);
})
.directive('code', function() {
return {
restrict: 'E',
terminal: true
};
})
.directive('appendSource', function($window, $compile, indent) {
return {
compile: function(element, attr) {
// Directive options
var options = {placement: 'after'};
angular.forEach(['placement', 'hlClass'], function(key) {
if(angular.isDefined(attr[key])) options[key] = attr[key];
});
var hlElement = angular.element('<div class="highlight" ng-non-bindable><pre><code class="html" style="margin:0"></code></pre></div>');
var codeElement = hlElement.children('pre').children('code');
var elementHtml = indent(element.html());
codeElement.text(elementHtml);
if(options.hlClass) codeElement.addClass(options.hlClass);
element[options.placement](hlElement);
$window.hljs.highlightBlock(codeElement[0]);
}
};
})
.directive('highlightBlock', function($window, indent) {
return {
compile: function(element, attr) {
element.html(indent(element.html()));
return function postLink(scope, element, attr) {
$window.hljs.highlightBlock(element[0]);
};
}
};
})
.value('indent', 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();
// Calculate proper indent
var minIndent = 999;
for(i = 0; i < lines.length; i++) {
var line = lines[0];
var indent = line.match(/^\s*/)[0];
if(indent !== line && indent.length < minIndent) {
minIndent = indent.length;
}
}
for(i = 0; i < lines.length; i++) {
lines[i] = prefix + lines[i].substring(minIndent).replace(/=""/g, '');
}
lines.push('');
return lines.join('\n');
});