diff --git a/src/assets/js/app/directives.js b/src/assets/js/app/directives.js index 97d848d..20377ea 100644 --- a/src/assets/js/app/directives.js +++ b/src/assets/js/app/directives.js @@ -3,211 +3,210 @@ */ angular.module('tapestry.directives', []) - - .directive('compile', ['$compile', function ($compile) { - return function(scope, element, attrs) { - scope.$watch( - function(scope) { - return scope.$eval(attrs.compile); - }, - function(value) { - - var v = value? marked(value): value; - - element.html(v); - - $compile(element.contents())(scope); - } - ); - } - }]) - .directive('previewAndMarkup', function(){ - - return { - - restrict: 'A', - scope: { - patterns: '=' - }, - template: '
' - - } - }) - .directive('rawInclude', [ - '$http', '$templateCache', '$compile', '$q', '$timeout', - function ($http, $templateCache, $compile, $q, $timeout) { - - var totalcount = 0 - - return { - restrict: 'A', - terminal: true, - scope: { - patterns: '=' - }, - compile: function (telement, attr) { - - var srcExp = attr.src, count = 0; - - return function (scope, element) { - - scope.$watch('patterns', function(newValue){ - - if(newValue){ - if(scope.patterns && scope.patterns.children) totalcount = scope.patterns.children.length - } - }, true) - - var changeCounter = 0 - - - scope.$watch(srcExp, function (src) { - - var thisChangeId = ++changeCounter; - - if (src) { - - - $http.get(src, { cache: $templateCache }).success(function (response) { - - if (thisChangeId !== changeCounter) return; - - /* Increment counter */ - - count++; - - /** - * Parsing Markdown files - * @type {Object} - */ - - var parsedContent = { - yaml: '', - markdown: '', - html: '', - meta: {} - }; - - var re = /^(-{3}(?:\n|\r)([\w\W]+?)-{3})?([\w\W]*)*/ - , results = re.exec(response.trim()) - , conf = {} - , yamlOrJson, - name = "content" - - if((yamlOrJson = results[2])) { - - if(yamlOrJson.charAt(0) === '{') { - conf = JSON.parse(yamlOrJson); - } else { - conf = jsyaml.load(yamlOrJson); - } - } - - conf[name] = results[3] ? results[3] : ''; - - - /* Add description */ - - var $description = element.parent().next(); - - if(conf.description){ - - parsedContent.markdown = marked(conf.description); - - $description.html(parsedContent.markdown) - - }else{ - - /* If there is no description: Hide it */ - - $description.hide() - } - - /* Element preview */ - - element.html(conf.content) - /* Compile Angular directives */ - - $compile(element.contents())(scope); + .directive('compile', ['$compile', function ($compile) { + return function(scope, element, attrs) { + scope.$watch( + function(scope) { + return scope.$eval(attrs.compile); + }, + function(value) { - /* Trigger element added */ - - if(count == totalcount) { - - $timeout(function(){ + var v = value? marked(value): value; - angular.element('body').trigger('tapestry.completed') - },500) - - } + element.html(v); + $compile(element.contents())(scope); + } + ); + } + }]) + .directive('previewAndMarkup', function(){ - /* Element Syntax highlight */ + return { - var code = element.closest('.block--example').find('code'), - $element = element.clone(); - - /* Adds codes to the code block */ + restrict: 'A', + scope: { + patterns: '=' + }, + template: '' - code.text(conf.content.trim()); + } + }) + .directive('rawInclude', [ + '$http', '$templateCache', '$compile', '$q', '$timeout', + function ($http, $templateCache, $compile, $q, $timeout) { - /* Highlighting */ - - Prism.highlightElement(code[0]); + var totalcount = 0 + return { + restrict: 'A', + terminal: true, + scope: { + patterns: '=' + }, + compile: function (telement, attr) { - }).error(function () { - - if (thisChangeId === changeCounter) element.html(''); + var srcExp = attr.src, count = 0; - }); - } - - else element.html(''); - - }); - - - }; - - - - - }, - - link: function(scope, element, attrs){ - - if(scope.$last){ - console.log("hey") - } - - } - }; - }]) - - .directive('tapestryVersion', ['version', function(version) { - return function(scope, elm, attrs) { - elm.text(version); - }; - }]) - .directive('lastUpdated', ['lastUpdated', function(version) { - return function(scope, elm, attrs) { - elm.text(version); - }; - }]) -; \ No newline at end of file + return function (scope, element) { + + scope.$watch('patterns', function(newValue){ + + if(newValue){ + if(scope.patterns && scope.patterns.children) totalcount = scope.patterns.children.length + } + }, true) + + var changeCounter = 0 + + + scope.$watch(srcExp, function (src) { + + var thisChangeId = ++changeCounter; + + if (src) { + + + $http.get(src, { cache: $templateCache }).success(function (response) { + + if (thisChangeId !== changeCounter) return; + + /* Increment counter */ + + count++; + + /** + * Parsing Markdown files + * @type {Object} + */ + + var parsedContent = { + yaml: '', + markdown: '', + html: '', + meta: {} + }; + + var re = /^(-{3}(?:\n|\r)([\w\W]+?)-{3})?([\w\W]*)*/ + , results = re.exec(response.trim()) + , conf = {} + , yamlOrJson, + name = "content" + + if((yamlOrJson = results[2])) { + + if(yamlOrJson.charAt(0) === '{') { + conf = JSON.parse(yamlOrJson); + } else { + conf = jsyaml.load(yamlOrJson); + } + } + + conf[name] = results[3] ? results[3] : ''; + + + /* Add description */ + + var $description = element.parent().next(); + + if(conf.description){ + + parsedContent.markdown = marked(conf.description); + + $description.html(parsedContent.markdown) + + }else{ + + /* If there is no description: Hide it */ + + $description.hide() + } + + /* Element preview */ + + element.html(conf.content) + + /* Compile Angular directives */ + + $compile(element.contents())(scope); + + /* Trigger element added */ + + if(count == totalcount) { + + $timeout(function(){ + + angular.element('body').trigger('tapestry.completed') + },500) + + } + + + /* Element Syntax highlight */ + var code = element.parent().parent().find('.example-code code'), + $element = element.clone(); + + /* Adds codes to the code block */ + + code.text(conf.content.trim()); + + /* Highlighting */ + + Prism.highlightElement(code[0]); + + + }).error(function () { + + if (thisChangeId === changeCounter) element.html(''); + + }); + } + + else element.html(''); + + }); + + + }; + + + + + }, + + link: function(scope, element, attrs){ + + if(scope.$last){ + console.log("hey") + } + + } + }; + }]) + + .directive('tapestryVersion', ['version', function(version) { + return function(scope, elm, attrs) { + elm.text(version); + }; + }]) + .directive('lastUpdated', ['lastUpdated', function(version) { + return function(scope, elm, attrs) { + elm.text(version); + }; + }]) +;