diff --git a/README.md b/README.md index e168545..b6f86bc 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ This repo contains a menuing system for Internet in a Box ## IIAB Menu -iiab-menu is a menuing system that uses json files for each menu item, which are loaded by and rendered in javascript, -based on an html file that contains an array of the menu items to load. This file will usually be named index.html, but can have -any name. +iiab-menu is a menuing system that uses json files for each menu item, which are loaded by and rendered in javascript. +A menu is defined by a folder, which contains a two files: a copy of "index.html", and a "menuitems.json" file, which contains the list of the menu items to load. The html file will usually be named "index.html", but can have +any name, as long as it is accompanied in a folder by a "menuitems.json" file. -The menu files are nominally in /library/www/html/iiab-menu, but the index file can be anywhere as the path to supporting files is absolute. -Several sample files are included in the samples directory. +The menu files are nominally in /library/www/html/iiab-menu, but the index and json files can be anywhere as the path to supporting files is absolute. +Several sample json files are included in the samples directory. A menu item, a set of links to one piece of content such as the wikipedia, is defined by a 'menu-def' json file. There is a sample in the samples directory. There may also be an optional html file that contains free form html to be appended to the menu item entry. diff --git a/cp-menus b/cp-menus index 94a7466..5b22886 100755 --- a/cp-menus +++ b/cp-menus @@ -46,7 +46,12 @@ fi # copy sample index file if none exists in home if [ ! -e $WWWROOT/home/index.html ]; then - cp samples/sampler.html $WWWROOT/home/index.html + cp samples/index.html $WWWROOT/home/index.html +fi + +# copy sample menuIndex file if none exists in home +if [ ! -e $WWWROOT/home/menuitems.json ]; then + cp samples/menuitems.json $WWWROOT/home/menuitems.json fi # restore modified files from local diff --git a/menu-files/js/iiab-menu.js b/menu-files/js/iiab-menu.js index ea29ad1..80c3bd1 100644 --- a/menu-files/js/iiab-menu.js +++ b/menu-files/js/iiab-menu.js @@ -29,6 +29,7 @@ var apkBaseUrl = "/content/apk/"; var menuUrl = '/iiab-menu/menu-files/'; var configJson = '/iiab-menu/config.json'; var defUrl = menuUrl + 'menu-defs/'; +var menuItemFile = './menuitems.json'; var imageUrl = menuUrl + 'images/'; var menuServicesUrl = menuUrl + 'services/'; var iiabMeterUrl = "/iiab_meter.php" @@ -44,6 +45,7 @@ var mobilePortraitSize = baseFontSize + "px"; var mobileLscapeSize = baseFontSize / 2 + "px"; var menuHtml = ""; var menuDefs = {}; +var menuItems = {}; var zimVersions = {}; var scaffold = $.Deferred(); @@ -72,6 +74,32 @@ var getZimVersions = $.getJSON(zimVersionIdx) zimVersions = data;}) .fail(jsonErrhandler); +// Get the list of menuItems +$.ajax({ + type: 'GET', + async: false, + url: menuItemFile, + dataType: 'text' + }) +.done(function( data ) { + var html = ''; + var lines = String(data); + lines = lines.split("\n"); + cleaner = ''; + for (var i = 0, len = lines.length; i < len; i++) { + line = lines[i].trim(); + var n = line.search('//'); + if (n == 0) {continue;} + n = line.search('menuItems'); + if (n != -1) {cleaner += '[';continue;} + n = line.search(';'); + if (n != -1) {cleaner += ']';continue;} + cleaner += line; + } + //alert(cleaner); + menuItems = JSON.parse(cleaner); +}); + // This is the main processing if (dynamicHtml){ //$.when(scaffold, getZimVersions, getConfigJson).then(procMenu); diff --git a/samples/index.html b/samples/index.html new file mode 100644 index 0000000..c79b87b --- /dev/null +++ b/samples/index.html @@ -0,0 +1,102 @@ + + +
+
+