angular-docs-cn/public/resources/js/controllers/app-controller.js

79 lines
2.0 KiB
JavaScript
Raw Normal View History

2015-05-01 09:48:52 -04:00
/*
* Application Controller
2015-10-15 17:16:35 -04:00
*
*/
2015-05-01 09:48:52 -04:00
angularIO.controller('AppCtrl', ['$mdDialog', '$timeout', '$http', '$sce', function ($mdDialog, $timeout, $http, $sce) {
var vm = this;
vm.showDocsNav = false;
vm.showMainNav = false;
vm.showMenu = false;
2015-05-01 09:48:52 -04:00
// TOGGLE MAIN NAV (TOP) ON MOBILE
vm.toggleDocsMenu = function () {
vm.showDocsNav = !vm.showDocsNav;
2015-05-01 09:48:52 -04:00
};
// TOGGLE DOCS NAV
vm.toggleMainMenu = function () {
vm.showMainNav = !vm.showMainNav;
2015-05-01 09:48:52 -04:00
};
// TOGGLE DOCS VERSION & LANGUAGE
vm.toggleVersionMenu = function () {
vm.showMenu = !vm.showMenu;
2015-05-01 09:48:52 -04:00
};
vm.openFeedback = function () {
var configuration = {
'productId': '410509',
'authuser': '1',
'bucket': 'angulario'
};
userfeedback.api.startFeedback(configuration);
};
// URL hash keeps track of which method the user wants to view in the API doc.
// Refer to _api.scss (.anchor-focused) and class.template.html (where ng-class is used) for details.
vm.isApiDocMemberFocused = function (memberName) {
var apiDocFocusedMember = window.location.hash.replace('#!#', '').replace('-anchor', '');
return apiDocFocusedMember === memberName;
};
/*
2015-10-15 17:16:35 -04:00
* Prettify Code
*
* Finish Rendereding code directives then prettify code
*/
// GRAB ALL TAGS NOT USING DIRECTIVES
var preTags = angular.element(document.body).find('pre');
// LOOP THROUGH AND ADD PRETTIFY CLASS
2015-10-15 17:16:35 -04:00
_.each(preTags, function (element) {
var preTag = angular.element(element);
// IF NOT FORMATTED, ADD PRETTY PRINT
2015-10-15 17:16:35 -04:00
if (!preTag.hasClass('prettyprint')) {
2015-05-03 23:29:54 -04:00
preTag.addClass('prettyprint linenums');
}
});
// TRIGGER PRETTYPRINT AFTER DIGEST LOOP COMPLETE
$timeout(prettyPrint, 1);
vm.sourceVisible = debugging;
vm.toggleSource = function ($event) {
$event.preventDefault();
vm.sourceVisible = !vm.sourceVisible;
var nodes = document.querySelectorAll('.original-english');
var $nodes = angular.element(nodes);
if (vm.sourceVisible) {
$nodes.removeClass('hidden');
} else {
$nodes.addClass('hidden');
}
};
}]);