Skip to content

Commit

Permalink
fix(languageDirFactory): support compile
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyBGod committed Aug 25, 2015
1 parent 5af30a7 commit 13732cc
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/angular-highlightjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,31 @@ hljsDir = ['$compile', '$parse', function ($compile, $parse) {
* language directive
*/
languageDirFactory = function (dirName) {
return [function () {
return ['$compile', '$parse', function ($compile, $parse) {
return {
require: '?hljs',
restrict: 'A',
link: function (scope, iElm, iAttrs, ctrl) {
if (!ctrl) {
return;
}
}

var compileCheck;

if (angular.isDefined(iAttrs.compile)) {
compileCheck = $parse(iAttrs.compile);
}

iAttrs.$observe(dirName, function (lang) {
if (angular.isDefined(lang)) {
ctrl.setLanguage(lang);

if (compileCheck && compileCheck(scope)) {
// compile the new DOM and link it to the current scope.
// NOTE: we only compile .childNodes so that
// we don't get into infinite loop compiling ourselves
$compile(iElm.find('code').contents())(scope);
}
}
});
}
Expand Down Expand Up @@ -363,4 +377,4 @@ ngModule
.directive('hljs', hljsDir)
.directive('language', languageDirFactory('language'))
.directive('source', sourceDirFactory('source'))
.directive('include', includeDirFactory('include'));
.directive('include', includeDirFactory('include'));

0 comments on commit 13732cc

Please sign in to comment.