Skip to content

Instantly share code, notes, and snippets.

@JasonMore
Created August 26, 2011 16:24
Show Gist options
  • Save JasonMore/1173795 to your computer and use it in GitHub Desktop.
Save JasonMore/1173795 to your computer and use it in GitHub Desktop.
javascript namespacing
/// <reference path="..\jquery-1.6.1-vsdoc.js"/>
/// <reference path="..\Calldirector.base.js"/>
//javascript namespacing
var CallDirector_application = {};
(function () {
//same as private
var messageWindow;
//same as public method
this.messageWindow = function(msgWindow) {
messageWindow = msgWindow;
}
//private
var menuTree;
var selectedNode;
var selectedNodeId;
//public method
this.onLoad = function (e){
menuTree = $(e.target).data('tTreeView');
}
this.onSelect = function (e) {
selectedNodeId = menuTree.getItemValue(e.item);
selectedNode = $(e.item).children('div');
}
var getFirstMenuItem = function (){
var menuTreeDomElement = $(menuTree)[0].element;
selectedNode = $(menuTreeDomElement).find('li.t-item').first();
selectedNodeId = menuTree.getItemValue(selectedNode);
}
var $selectedMenuAction;
this.selectedMenuActionId = function (id) {
$selectedMenuAction = $('#' + id);
}
var $selectedMenuOption;
this.selectedMenuOptionId = function (id) {
$selectedMenuOption = $('#' + id);
}
var navigate = function (method) {
if (!selectedNodeId) {
selectedNodeId = getFirstMenuItem();
}
$selectedMenuOption.val(selectedNodeId);
$selectedMenuAction.val(method);
$('#btnSave').click();
}
this.newMenu = function () {
if (!selectedNode) {
getFirstMenuItem();
}
//if selectedNodeId is not sub-menu
if ($(selectedNode).is(':has(span.icon-submenu)') == false) {
messageWindow.center();
messageWindow.open();
return;
}
navigate('Create');
}
this.editMenu = function () {
navigate('Edit');
}
this.deleteMenu = function () {
navigate('Delete');
}
//the magic
}).apply(CallDirector_application);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment