angular.module('ngdocs.directives', [], function($compileProvider) { var angularJsUrl; var scripts = document.getElementsByTagName("script"); var angularJsRegex = /^(|.*\/)angular(-.*?)?(\.min)?.js(\?[^#]*)?(#(.*))?$/; for(var j = 0; j < scripts.length; j++) { var src = scripts[j].src; if (src && src.match(angularJsRegex)) { angularJsUrl = src.replace('docs.angularjs.org', 'code.angularjs.org'); continue; } } var HTML_TEMPLATE = '\n' + '\n' + ' \n' + '_SCRIPT_SOURCE_' + '
\n' + '_HTML_SOURCE_\n' + ' \n' + ''; $compileProvider.directive('docExample', ['$injector', '$log', '$browser', '$location', function($injector, $log, $browser, $location) { return { restrict: 'E', terminal: true, compile: function(element, attrs) { var module = attrs.module; //jQuery find() methods in this widget contain primitive selectors on purpose so that we can use //jqlite instead. jqlite's find() method currently supports onlt getElementsByTagName! var example = element.find('pre').eq(0), //doc-source scriptSrc = '', htmlSrc = example.text().replace(/\n' : ''). replace('_HTML_SOURCE_', indent(htmlSrc, ' ')). replace('_MODULE_', module ? '="' + module + '"' : '')); element.html(''); element.append(tabs); try { if (window.execScript) { // IE window.execScript(scriptSrc || '"stupid IE!"'); // IE complains when evaling empty string } else { window.eval(scriptSrc); } } catch (e) { alert(e); } return function(docsAppScope) { var modules = [ function($provide) { $provide.value('$browser', $browser); $provide.provider('$location', function() { this.$get = function() { return $location; }; this.hashPrefix = this.html5Mode = angular.noop; }); $provide.decorator('$defer', function($rootScope, $delegate) { return angular.extend(function(fn, delay) { if (delay && delay > 500) { return setTimeout(function() { $rootScope.$apply(fn); }, delay); } else { return $delegate.apply(this, arguments); } }, $delegate); }); } ]; module && modules.push(module); angular.bootstrap(livePreviewTab, modules). invoke(['$rootScope', function(example$rootScope) { element.bind('$destroy', docsAppScope.$root.$watch(function() { // this propagates the $watch from the docs app to the example app example$rootScope.$digest(); })); }]); }; function jsFiddleButton(jsfiddle) { var fixJsFiddleIssue132 = true; if (jsfiddle !== 'false') { if(jsfiddle === true) { //dynamically generate a fiddle var fiddleUrl = 'http://jsfiddle.net/api/post/library/pure/'; function jsFiddleEscape(text, prefix) { return indent(text.replace(/<\/textarea>/gi,'</textarea>'), prefix); } return '