refactor(docs-app): move `bold` directive out of the app controller file
This commit is contained in:
parent
72e6a79126
commit
b298b9c1af
|
@ -18,6 +18,7 @@ script(src="/resources/js/site.js")
|
|||
script(src="/resources/js/controllers/app-controller.js")
|
||||
script(src="/resources/js/directives/cheatsheet.js")
|
||||
script(src="/resources/js/directives/bio.js")
|
||||
script(src="/resources/js/directives/bold.js")
|
||||
script(src="/resources/js/directives/code.js")
|
||||
script(src="/resources/js/directives/code-tabs.js")
|
||||
script(src="/resources/js/directives/code-pane.js")
|
||||
|
@ -44,7 +45,7 @@ if current.path[0] == "docs"
|
|||
})(window,document,'script','//s.swiftypecdn.com/install/v1/st.js','_st');
|
||||
|
||||
_st('install','VsuU7kH5Hnnj9tfyNvfK');
|
||||
|
||||
|
||||
<!-- Google Feedback -->
|
||||
script(src="//www.gstatic.com/feedback/api.js" type="text/javascript")
|
||||
|
||||
|
|
|
@ -3,27 +3,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
angularIO.directive('bold', function ($timeout) {
|
||||
return {
|
||||
scope: { bold: '=bold' },
|
||||
link: postLink
|
||||
};
|
||||
function postLink (scope, element) {
|
||||
var bold = typeof scope.bold === 'string'
|
||||
? [ scope.bold ]
|
||||
: scope.bold;
|
||||
$timeout(function () {
|
||||
var html = element.html();
|
||||
angular.forEach(bold, function (bold) {
|
||||
html = html.replace(new RegExp(bold.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"), 'g'), '<b>$&</b>');
|
||||
});
|
||||
html = html.replace(/\n/g, '<br>');
|
||||
html = html.replace(/ /g, ' ');
|
||||
element.html(html);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
angularIO.controller('AppCtrl', ['$mdDialog', '$timeout', '$http', '$sce', function ($mdDialog, $timeout, $http, $sce) {
|
||||
var vm = this;
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
angularIO.directive('bold', function ($timeout) {
|
||||
return {
|
||||
scope: { bold: '=bold' },
|
||||
link: postLink
|
||||
};
|
||||
function postLink (scope, element) {
|
||||
var bold = typeof scope.bold === 'string'
|
||||
? [ scope.bold ]
|
||||
: scope.bold;
|
||||
$timeout(function () {
|
||||
var html = element.html();
|
||||
angular.forEach(bold, function (bold) {
|
||||
html = html.replace(new RegExp(bold.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"), 'g'), '<b>$&</b>');
|
||||
});
|
||||
html = html.replace(/\n/g, '<br>');
|
||||
html = html.replace(/ /g, ' ');
|
||||
element.html(html);
|
||||
});
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue