js file reorganization, basic name spacing

This commit is contained in:
Jason White 2014-08-25 21:02:31 -04:00
parent 53b6c16fb6
commit 5f378a7520
6 changed files with 65 additions and 58 deletions

View File

@ -47,9 +47,10 @@
<script type="text/javascript">
var goat=angular.module("goatApp", ['ngAnimate','ui.bootstrap']);
</script>
<script type="text/javascript" src="js/ui-util.js"></script>
<script type="text/javascript" src="js/goat.js"></script>
<script type="text/javascript" src="js/goatConstants.js"></script>
<script type="text/javascript" src="js/goatUtil.js"></script>
<script type="text/javascript" src="js/goatData.js"></script>
<script type="text/javascript" src="js/goatControllers.js"></script>
<!-- end of JS -->
@ -211,7 +212,7 @@
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
}
makeFormsAjax();
goat.utils.makeFormsAjax();
}
</script>

View File

@ -1,9 +1,8 @@
//goatConstants
var goatConstants = {};
goatConstants.CATEGORYCLASS = 'fa-angle-right pull-right';
goatConstants.menuPrefix = [
var goatConstants = {
CATEGORYCLASS:'fa-angle-right pull-right',
menuPrefix : [
{
name:'LESSONS',
type:'STATIC',
@ -11,5 +10,7 @@ goatConstants.menuPrefix = [
link:'',
children:null,
class:'fa-bars static'
}
];
}],
lessonService: 'service/lessonmenu.mvc'
};

View File

@ -7,10 +7,10 @@
* prepares and updates menu topic items for the view
*/
goat.controller('goatLesson', function($scope, $http, $modal, $log) {
//TODO: implement via separate promise and use config for menu
$http({method: 'GET', url: 'service/lessonmenu.mvc'}).then(
//TODO: implement via separate promise and use config for menu (goat.data.loadMenuData())
$http({method: 'GET', url: goatConstants.lessonService}).then(
function(menuData) {
var menuItems = goat.addMenuClasses(goatConstants.menuPrefix.concat(menuData.data));
var menuItems = goat.utils.addMenuClasses(goatConstants.menuPrefix.concat(menuData.data));
$scope.menuTopics = menuItems;
},
function(error) {
@ -21,12 +21,12 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log) {
$scope.renderLesson = function(url) {
console.log(url + ' was passed in');
// use jquery to render lesson content to div
loadLessonContent(url).then(
goat.data.loadLessonContent(url).then(
function(reply) {
$("#lesson_content").html(reply);
// hook forms
makeFormsAjax();
$('#lessonTitle').text(extractLessonTitle($(reply)));
goat.utils.makeFormsAjax();
$('#lessonTitle').text(goat.utils.extractLessonTitle($(reply)));
// adjust menu to lessonContent size if necssary
if ($('div.panel-body').height() > 400) {
$('#leftside-navigation').height($(window).height());
@ -43,6 +43,7 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log) {
});
*/
};
//TODO: Move show Source into it's own angular controller
/*
* Function to load lesson source
* @returns {undefined}
@ -93,34 +94,6 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log) {
});
//TODO add recursion to handle arr[i].children objects
// ... in case lower-level's need classes as well ... don't right now
goat.addMenuClasses = function(arr) {
for (var i = 0; i < arr.length; i++) {
var menuItem = arr[i];
//console.log(menuItem);
if (menuItem.type && menuItem.type === 'CATEGORY') {
menuItem.class = 'fa-angle-right pull-right';
}
}
return arr;
};
/* ### GOAT DATA/PROMISES ### */
function loadLessonContent(_url) {
//TODO: switch to $http (angular) later
//return $http({method:'GET', url: _url});
return $.get(_url, {}, null, "html");
}
function loadMenuData() {
return $http({method: 'GET', url: 'service/lessonmenu.mvc'});
}
/* Controllers for modal instances */
var showSourceController = function($scope, $modalInstance, lessonSource) {

View File

@ -0,0 +1,13 @@
/* ### GOAT DATA/PROMISES ### */
goat.data = {
loadLessonContent: function (_url) {
//TODO: switch to $http (angular) later
//return $http({method:'GET', url: _url});
return $.get(_url, {}, null, "html");
},
loadMenuData: function() {
//TODO use goatConstants var for url
return $http({method: 'GET', url: 'service/lessonmenu.mvc'});
}
};

View File

@ -0,0 +1,34 @@
goat.utils = {
//TODO add recursion to handle arr[i].children objects
// ... in case lower-level's need classes as well ... don't right now
addMenuClasses: function(arr) {
for (var i = 0; i < arr.length; i++) {
var menuItem = arr[i];
//console.log(menuItem);
if (menuItem.type && menuItem.type === 'CATEGORY') {
menuItem.class = 'fa-angle-right pull-right';
}
}
return arr;
},
makeFormsAjax: function() {
//console.log("Hooking any lesson forms to make them ajax");
$("form").ajaxForm(options);
},
/**goatApp.extractLessonTitle
*pulls lesson title from html fragment returned (looks for it in h1 element)
*@param - html rendered to object passed in
*/
extractLessonTitle:function (el) {
var title = $('h1',el).text();
return title;
},
};
// ### GLOBAL FUNCTIONS ## //
$(window).resize(function() {
//$('#leftside-navigation').css('height',$('div.panel-body').height());
console.log($(window).height());
});

View File

@ -1,15 +0,0 @@
function makeFormsAjax() {
//console.log("Hooking any lesson forms to make them ajax");
$("form").ajaxForm(options);
}
function extractLessonTitle(el) {
var title = $('h1',el).text();
return title;
}
$(window).resize(function() {
//$('#leftside-navigation').css('height',$('div.panel-body').height());
console.log($(window).height());
});