var docsApp = { controller: {}, directive: {}, serviceFactory: {} }; docsApp.controller.DocsNavigationCtrl = ['$scope', 'fullTextSearch', '$location', function($scope, fullTextSearch, $location) { fullTextSearch.init(); $scope.search = function(q) { fullTextSearch.search(q, function(results) { if(q && q.length >= 4) { $scope.results = results; var totalSections = 0; for(var i in results) { ++totalSections; } if(totalSections > 0) { $scope.colClassName = 'cols-' + totalSections; $scope.hasResults = true; } else { $scope.hasResults = false; } } else { $scope.hasResults = false; } if(!$scope.$$phase) $scope.$apply(); }); }; $scope.submit = function() { var result; for(var i in $scope.results) { result = $scope.results[i][0]; if(result) { break; } } if(result) { $location.path(result.url); $scope.hideResults(); } }; $scope.hideResults = function() { $scope.hasResults = false; $scope.q = ''; }; }]; docsApp.serviceFactory.fullTextSearch = ['$q', '$rootScope', function($q, $rootScope) { return { dbName : 'docs', indexName : 'docsindex', init : function(onReady) { this.init = function() {}; var self = this; this.deferReady = $q.defer(); this.readyPromise = this.deferReady.promise; this.engine = lunr(function () { this.ref('id'); this.field('title', {boost: 50}); this.field('description', { boost : 20 }); }); this.prepare(); this.onReady(); }, onReady : function() { this.ready = true; var self = this; self.deferReady.resolve(); if(!$rootScope.$$phase) { $rootScope.$apply(); } }, whenReady : function(fn) { if(this.ready) { fn(); } else { this.init(); this.readyPromise.then(fn); } }, prepare : function(injector, callback) { for(var i=0;i' + '' + ' Edit' + '' + '' + '', scope: true, controller: function($scope, $attrs, openJsFiddle, openPlunkr) { var sources = { module: $attrs.sourceEdit, deps: read($attrs.sourceEditDeps), html: read($attrs.sourceEditHtml), css: read($attrs.sourceEditCss), js: read($attrs.sourceEditJs), unit: read($attrs.sourceEditUnit), scenario: read($attrs.sourceEditScenario) }; $scope.fiddle = function(e) { e.stopPropagation(); openJsFiddle(sources); }; $scope.plunkr = function(e) { e.stopPropagation(); openPlunkr(sources); }; } }; function read(text) { var files = []; angular.forEach(text ? text.split(' ') : [], function(refId) { // refId is index.html-343, so we need to strip the unique ID when exporting the name files.push({name: refId.replace(/-\d+$/, ''), content: getEmbeddedTemplate(refId)}); }); return files; } }; docsApp.directive.docTutorialNav = function(templateMerge) { var pages = [ '', 'step_00', 'step_01', 'step_02', 'step_03', 'step_04', 'step_05', 'step_06', 'step_07', 'step_08', 'step_09', 'step_10', 'step_11', 'the_end' ]; return { compile: function(element, attrs) { var seq = 1 * attrs.docTutorialNav, props = { seq: seq, prev: pages[seq], next: pages[2 + seq], diffLo: seq ? (seq - 1): '0~1', diffHi: seq }; element.addClass('btn-group'); element.addClass('tutorial-nav'); element.append(templateMerge( '
  • Previous
  • \n' + '
  • Live Demo
  • \n' + '
  • Code Diff
  • \n' + '
  • Next
  • ', props)); } }; }; docsApp.directive.docTutorialReset = function() { function tab(name, command, id, step) { return '' + '
    \n' + '
      \n' + '
    1. Reset the workspace to step ' + step + '.

      ' + '
      ' + command + '
    2. \n' + '
    3. Refresh your browser or check the app out on Angular\'s server.

    4. \n' + '
    \n' + '
    \n'; } return { compile: function(element, attrs) { var step = attrs.docTutorialReset; element.html( '
    ' + '

    Workspace Reset Instructions āž¤

    ' + '
    \n' + '
    \n' + tab('Git on Mac/Linux', 'git checkout -f step-' + step, 'gitUnix', step) + tab('Git on Windows', 'git checkout -f step-' + step, 'gitWin', step) + '
    \n'); } }; }; docsApp.serviceFactory.angularUrls = function($document) { var urls = {}; angular.forEach($document.find('script'), function(script) { var match = script.src.match(/^.*\/(angular[^\/]*\.js)$/); if (match) { urls[match[1].replace(/(\-\d.*)?(\.min)?\.js$/, '.js')] = match[0]; } }); return urls; }; docsApp.serviceFactory.formPostData = function($document) { return function(url, fields) { var form = angular.element('
    '); angular.forEach(fields, function(value, name) { var input = angular.element(''); input.attr('value', value); form.append(input); }); $document.find('body').append(form); form[0].submit(); form.remove(); }; }; docsApp.serviceFactory.openPlunkr = function(templateMerge, formPostData, angularUrls) { return function(content) { var allFiles = [].concat(content.js, content.css, content.html); var indexHtmlContent = '\n' + '\n' + ' \n' + ' \n' + '{{scriptDeps}}\n' + ' \n' + ' \n\n' + '{{indexContents}}' + '\n\n \n' + '\n'; var scriptDeps = ''; angular.forEach(content.deps, function(file) { if (file.name !== 'angular.js') { scriptDeps += ' \n'; } }); indexProp = { angularJSUrl: angularUrls['angular.js'], scriptDeps: scriptDeps, indexContents: content.html[0].content }; var postData = {}; angular.forEach(allFiles, function(file, index) { if (file.content && file.name != 'index.html') { postData['files[' + file.name + ']'] = file.content; } }); postData['files[index.html]'] = templateMerge(indexHtmlContent, indexProp); postData['tags[]'] = "angularjs"; postData.private = true; postData.description = 'AngularJS Example Plunkr'; formPostData('http://plnkr.co/edit/?p=preview', postData); }; }; docsApp.serviceFactory.openJsFiddle = function(templateMerge, formPostData, angularUrls) { var HTML = '
    \n{{html:2}}
    ', CSS = ' \n' + '{{head:0}}