From: anthony Date: Wed, 13 Jun 2018 02:02:46 +0000 (-0400) Subject: separating the functions into a lib file X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=54411e4b429259afd0b895342d3ab6bca745481c;p=WP-Themes%2FglmOrigin.git separating the functions into a lib file --- diff --git a/setup/moduleLib.js b/setup/moduleLib.js new file mode 100644 index 0000000..cd6659a --- /dev/null +++ b/setup/moduleLib.js @@ -0,0 +1,98 @@ +const modLib = (function() { + return { + + setModules: function(modType,modName){ + appState[modType] = modName; + return appState; + }, + storeModules: function(appState){ + localStorage.setItem("app", JSON.stringify(appState)); + }, + getModuleTypes: function(modules){ + return Object.keys(modules) + }, + getModules: function(){ + return JSON.parse(localStorage.getItem("app")); + }, + updateModule: function(appState){ + let allMods = modLib.getModules(); + allMods[appState.modType].forEach(function(mod, index){ + if(mod.name === appState.name){ + allMods[appState.modType][index] = appState; + } + }) + localStorage.setItem("app", JSON.stringify(allMods)); + }, + getModuleByName: function(modName){ + let mods = JSON.parse(localStorage.getItem("app")), newMods = []; + for(modType in mods){ + newMods.push(modLib.getModulesByType(modType).filter(function(mod){ + return mod.name == modName; + })) + } + return newMods[0].concat(newMods[1])[0]; + }, + + // Returns an array of Modules + getModulesByType: function(moduleType){ + let appState = JSON.parse(localStorage.getItem("app")); + return appState[moduleType]; + }, + getDevDirs: function(){ + let fullPath = path.join(__dirname, `../dev`); + fs.readdir(fullPath, function(err, item) { + console.log(item) + }); + }, + generateListItems: function(modType){ + $(`

${modType}

`).appendTo( $("#module-list-container")); + $(`