diff options
| author | Jules <jules@asdf.us> | 2016-10-25 21:02:46 -0400 |
|---|---|---|
| committer | Jules <jules@asdf.us> | 2016-10-25 21:02:46 -0400 |
| commit | 54e052d6f29756ba2ee94c31b85fd49e30e335a0 (patch) | |
| tree | aacc0ccd8ee014b36f59bfb4e90d1cd2068a5c35 /js | |
| parent | 0003c072cb83f48386c5e264d86b0aa3a9eaa20d (diff) | |
buttons for other courses
Diffstat (limited to 'js')
| -rwxr-xr-x[-rw-r--r--] | js/app.js | 33 | ||||
| -rwxr-xr-x[-rw-r--r--] | js/course.js | 10 | ||||
| -rwxr-xr-x[-rw-r--r--] | js/flatfile.js | 2 | ||||
| -rwxr-xr-x[-rw-r--r--] | js/jquery-2.0.3.min.js | 0 | ||||
| -rwxr-xr-x[-rw-r--r--] | js/loader.js | 3 | ||||
| -rwxr-xr-x[-rw-r--r--] | js/util.js | 0 |
6 files changed, 39 insertions, 9 deletions
diff --git a/js/app.js b/js/app.js index 847b9a7..fa2711e 100644..100755 --- a/js/app.js +++ b/js/app.js @@ -1,5 +1,6 @@ var config = {}; config.images = []; +window.mode = 'omnivore' function app(){}; app.init = function(){ @@ -15,9 +16,15 @@ app.load = function(){ , new Flatfile ("esoteric", "products.esoteric.txt") , new Flatfile ("meat", "products.meat.txt") , new Flatfile ("seafood", "products.seafood.txt") - , new Flatfile ("weird", "products.esoteric.txt") , new Flatfile ("techniques", "techniques.txt") , new Flatfile ("preparations", "preparations.txt") + , new Flatfile ("cereal", "cereal.txt") + , new Flatfile ("diseases", "diseases.txt") + , new Flatfile ("drugs", "drugs.txt") + , new Flatfile ("elements", "elements.txt") + , new Flatfile ("insects", "insects.txt") + , new Flatfile ("sf", "sf.txt") + , new Flatfile ("religions", "religions.txt") ]; app.loader.ready("loading"); @@ -31,20 +38,38 @@ app.ready = function(){ app.bind = function(){ $("#generate").click(app.generate); + $(".switch").click(app.switch_mode); +} + +app.switch_mode = function(){ + window.mode = $(this).html() + $('.active').removeClass('active') + $(this).addClass('active') + app.generate() } app.generate = function(){ - window.products = [].concat(vegan,meat,dairy,seafood); + if (mode == 'omnivore') { + window.products = [].concat(vegan,meat,dairy,seafood); + } else if (mode == 'vegan') { + window.products = [].concat(vegan); + } else if (mode == 'weirdo') { + window.products = [].concat(vegan,meat,dairy,seafood,esoteric); + } else { + window.products = [].concat(window[mode]) + } +console.log(window.products) var texts = []; for (var i = 0; i < courses.length; i++) { var courseName = courses[i][0]; var text = "<h2>" + courseName + "</h2>"; + var course = [] for (var j = 1; j < courses[i].length; j++) { - text += "<p>" + course(courses[i][j]) + "</p>"; + course.push( dish(courses[i][j]) ) } + text += "<p>" + course.join(", ") + "</p>" texts.push(text); } - console.log(texts) $("#result").html(texts.join("")); } diff --git a/js/course.js b/js/course.js index 2924eb6..2a35719 100644..100755 --- a/js/course.js +++ b/js/course.js @@ -14,11 +14,11 @@ function course(n) { var ds = [ dish() ]; return ds.join(", "); } -function dish(){ - var pcount = rand(3) + 1; +function dish(n){ + var pcount = n || rand(2) + 1; var ps = []; while (pcount-- > 0) ps.push(product()); - if (rand(100) > 60) { + if (rand(100) < 90) { var d = ps.join(" and ") + " " + choice(preparations); } else { @@ -28,7 +28,7 @@ function dish(){ } function product(){ var result; - if (rand(100) > 90) { + if (rand(100) > 1) { var technique = choice(techniques); if (technique[0] == '-') { result = choice(products) + technique + " " + choice(products); @@ -36,9 +36,11 @@ function product(){ result = technique + " " + choice(products) } } +/* else if (rand(100) > 0) { result = choice(products) + " " + choice(products) } +*/ else { result = choice(products) } diff --git a/js/flatfile.js b/js/flatfile.js index 1b6b132..89a6b17 100644..100755 --- a/js/flatfile.js +++ b/js/flatfile.js @@ -7,7 +7,7 @@ Flatfile.prototype.load = function(){ var _this = this; app.loader.register(this.key); $.get("data/" + this.filename, function(data) { - window[_this.key] = data.split("\n"); + window[_this.key] = data.split("\n").filter(function(a){ return a && a.length > 0 }); app.loader.ready(_this.key); }) }
\ No newline at end of file diff --git a/js/jquery-2.0.3.min.js b/js/jquery-2.0.3.min.js index 2be209d..2be209d 100644..100755 --- a/js/jquery-2.0.3.min.js +++ b/js/jquery-2.0.3.min.js diff --git a/js/loader.js b/js/loader.js index ddf4b7e..90f04c7 100644..100755 --- a/js/loader.js +++ b/js/loader.js @@ -21,6 +21,9 @@ app.load = function(){ } app.ready = function(){ } +// so basically he also puts a bunch of variables in the global namespace. Does that seem +// contradictory to an OOP approach? in global namespace where will be only app variable. no there are also +// ******************************************************/ function Loader (readyCallback){ diff --git a/js/util.js b/js/util.js index 5828a91..5828a91 100644..100755 --- a/js/util.js +++ b/js/util.js |
