diff --git a/.gitignore b/.gitignore index 6e829d9..a0cc0c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,29 @@ -node_modules .project +.idea/* +__index.html +_index.html +div_bgs.html +img/thermo_bg_2.png +img/thermo_fg_2.png +img/logo/logo_full_8bit.png +img/logo/logo_small BACKUP.png +img/logo/logo_small_8bit.png +img/logo/logo_smaller.png +img/logo/logo_smaller_8bit.png +img/logo/logo_smaller_wide_8bit.png +img/logo/logo_smallest.png +css/_backup20131010/* +css/_backup20131011/* +d3d_btns.css +index.html.orig +js/Thermometer.js.orig +js/buttonbehaviors.js.orig +js/gcodeGenerating_v01.js.orig +js/init_layout backup20130918.js +js/main.js.orig +js/previewRendering_v02.js.orig +less/verticalshapes.css +less/verticalshapes_backup.css +__settings.html +css/_settings.css +node_modules/* diff --git a/Gruntfile.js b/Gruntfile.js index 41b4be6..110852f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -16,21 +16,22 @@ module.exports = function(grunt) { }, dist: { src: [ - 'www/js/SettingsWindow.js', - 'www/js/d3dServerInterfacing.js', - 'www/js/verticalShapes.js', - 'www/js/buttonbehaviors.js', - 'www/js/canvasDrawing.js', - 'www/js/previewRendering.js', - 'www/js/gcodeGenerating.js', - 'www/js/init_layout.js', - 'www/js/Printer.js', - 'www/js/Progressbar.js', - 'www/js/Thermometer.js', - 'www/js/utils.js', - 'www/js/sidebar.js', - 'www/js/message.js', - 'www/js/main.js' + 'js_src/SettingsWindow.js', + 'js_src/UpdatePanel.js', + 'js_src/d3dServerInterfacing.js', + 'js_src/verticalShapes.js', + 'js_src/buttonbehaviors.js', + 'js_src/canvasDrawing.js', + 'js_src/previewRendering.js', + 'js_src/gcodeGenerating.js', + 'js_src/init_layout.js', + 'js_src/Printer.js', + 'js_src/Progressbar.js', + 'js_src/Thermometer.js', + 'js_src/utils.js', + 'js_src/sidebar.js', + 'js_src/Message.js', + 'js_src/main.js' ], dest: 'www/js/<%= pkg.name %>.js' } @@ -38,15 +39,21 @@ module.exports = function(grunt) { uglify: { options: { // banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n', - mangle: false, + mangle: true, beautify: false, compress: {}, report: 'min', preserveComments: 'false' }, build: { - src: ['www/js/*.js', '!www/js/<%= pkg.name %>.min.js'], - dest: 'www/js/<%= pkg.name %>.min.js' + files: { +// 'www/js/<%= pkg.name %>.min.js' : ['www/js/*.js', '!www/js/<%= pkg.name %>.min.js', '!www/js/<%= pkg.name %>.js'] + 'www/js/<%= pkg.name %>.min.js' : ['www/js/<%= pkg.name %>.js'] + } +// src: 'www/js/*.js', +// dest: 'www/js/min/blabla.js' +// src: ['www/js/*.js', '!www/js/<%= pkg.name %>.min.js'], +// dest: 'www/js/<%= pkg.name %>.min.js' } }, jshint: { @@ -85,11 +92,11 @@ module.exports = function(grunt) { } }, watch: { -// javascript: { -// files: ["www/js/*", '!www/js/*.min.js'], -// // tasks: ["less", "css_prefix"] -// tasks: ["uglify"] -// }, + javascript: { + files: ["js_src/*", '!www/js/<%= pkg.name %>.min.js', '!www/js/<%= pkg.name %>.js'], + tasks: ["concat", "uglify"] +// tasks: ["jshint", "concat", "uglify"] + }, styles: { files: ["less/*"], tasks: ["less", "autoprefixer", "cssmin"] @@ -133,8 +140,8 @@ module.exports = function(grunt) { 'less', 'autoprefixer', 'cssmin', -// 'concat', -// 'uglify', + 'concat', + 'uglify', // 'jshint', 'watch' ]); diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..33b5598 --- /dev/null +++ b/Makefile @@ -0,0 +1,64 @@ +################################################ +# OpenWrt Makefile for Doodle3D Print3D driver # +################################################ +include $(TOPDIR)/rules.mk + +PKG_NAME := doodle3d-client +PKG_VERSION := 0.9.0 +PKG_RELEASE := 1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/doodle3d-client + SECTION:=mods + CATEGORY:=Doodle3D + TITLE:=Doodle3D web client + DEPENDS:= +endef + +define Package/doodle3d-client/description + This package provides the Doodle3D web client, which interacts with the wifibox package using a REST API. +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) + $(CP) less $(PKG_BUILD_DIR)/ + $(CP) www $(PKG_BUILD_DIR)/ + $(CP) Gruntfile.js $(PKG_BUILD_DIR)/ + $(CP) README.md $(PKG_BUILD_DIR)/ + $(CP) ___settings.html $(PKG_BUILD_DIR)/ + $(CP) lesstocss.sh $(PKG_BUILD_DIR)/ + $(CP) package.json $(PKG_BUILD_DIR)/ +endef + +define Build/Compile + npm install + grunt less autoprefixer cssmin concat uglify +endef + +define Package/doodle3d-client/install + $(INSTALL_DIR) $(1)/www + $(INSTALL_DIR) $(1)/www/css + $(INSTALL_DIR) $(1)/www/img + #$(INSTALL_DIR) $(1)/www/js + $(INSTALL_DIR) $(1)/www/js/libs + + $(CP) $(PKG_BUILD_DIR)/www/favicon* $(1)/www/ + $(CP) $(PKG_BUILD_DIR)/www/index.html $(1)/www/ + $(CP) $(PKG_BUILD_DIR)/www/settings.html $(1)/www/ + + $(CP) $(PKG_BUILD_DIR)/www/css/debug.min.css $(1)/www/css/ + $(CP) $(PKG_BUILD_DIR)/www/css/settings.min.css $(1)/www/css/ + $(CP) $(PKG_BUILD_DIR)/www/css/styles.min.css $(1)/www/css/ + + $(CP) $(PKG_BUILD_DIR)/www/img/* $(1)/www/img/ + + $(CP) $(PKG_BUILD_DIR)/www/js/doodle3d-client.min.js $(1)/www/js/ + $(CP) $(PKG_BUILD_DIR)/www/js/libs/* $(1)/www/js/libs/ + + $(CP) $(PKG_BUILD_DIR)/www/library $(1)/www/ +endef + +$(eval $(call BuildPackage,doodle3d-client)) diff --git a/README.md b/README.md index 8a4ef7a..d86cc3a 100644 --- a/README.md +++ b/README.md @@ -1 +1,13 @@ -Doodle3D client app \ No newline at end of file +Doodle3D client app +=================== + + +# How to build + +## Prerequisites +- get `npm`, the Node.js package manager, for instance using macports on OSX. +- (prerequisite) install Grunt: `npm install -g grunt-cli`. +- run npm install in the project root to install project dependencies + +Finally run grunt to build minified css and js files. By default, it will keep +running to automatically rebuild when source files are changed. diff --git a/___settings.html b/___settings.html old mode 100755 new mode 100644 diff --git a/img_old/icon.png b/img_old/icon.png new file mode 100755 index 0000000..434f30f Binary files /dev/null and b/img_old/icon.png differ diff --git a/img_old/logo/logo_full.png b/img_old/logo/logo_full.png new file mode 100755 index 0000000..47415d8 Binary files /dev/null and b/img_old/logo/logo_full.png differ diff --git a/img_old/logo/logo_small.png b/img_old/logo/logo_small.png new file mode 100644 index 0000000..1ea8163 Binary files /dev/null and b/img_old/logo/logo_small.png differ diff --git a/img_old/logo/logo_smaller.png b/img_old/logo/logo_smaller.png new file mode 100644 index 0000000..f000e5c Binary files /dev/null and b/img_old/logo/logo_smaller.png differ diff --git a/img_old/logo/logo_smallest.png b/img_old/logo/logo_smallest.png new file mode 100644 index 0000000..17f2799 Binary files /dev/null and b/img_old/logo/logo_smallest.png differ diff --git a/www/img/webpage_icons/apple-touch-icon-114x114-precomposed.png b/img_old/webpage_icons/apple-touch-icon-114x114-precomposed.png similarity index 100% rename from www/img/webpage_icons/apple-touch-icon-114x114-precomposed.png rename to img_old/webpage_icons/apple-touch-icon-114x114-precomposed.png diff --git a/img_old/webpage_icons/apple-touch-icon-144x144-precomposed.png b/img_old/webpage_icons/apple-touch-icon-144x144-precomposed.png new file mode 100644 index 0000000..585036f Binary files /dev/null and b/img_old/webpage_icons/apple-touch-icon-144x144-precomposed.png differ diff --git a/www/img/webpage_icons/apple-touch-icon-72x72-precomposed.png b/img_old/webpage_icons/apple-touch-icon-72x72-precomposed.png similarity index 100% rename from www/img/webpage_icons/apple-touch-icon-72x72-precomposed.png rename to img_old/webpage_icons/apple-touch-icon-72x72-precomposed.png diff --git a/www/img/webpage_icons/apple-touch-icon-precomposed.png b/img_old/webpage_icons/apple-touch-icon-precomposed.png similarity index 100% rename from www/img/webpage_icons/apple-touch-icon-precomposed.png rename to img_old/webpage_icons/apple-touch-icon-precomposed.png diff --git a/www/js/message.js b/js_src/Message.js similarity index 100% rename from www/js/message.js rename to js_src/Message.js diff --git a/www/js/Printer.js b/js_src/Printer.js similarity index 100% rename from www/js/Printer.js rename to js_src/Printer.js diff --git a/www/js/Progressbar.js b/js_src/Progressbar.js similarity index 100% rename from www/js/Progressbar.js rename to js_src/Progressbar.js diff --git a/www/js/SettingsWindow.js b/js_src/SettingsWindow.js similarity index 96% rename from www/js/SettingsWindow.js rename to js_src/SettingsWindow.js index 846ca07..9eb7191 100644 --- a/www/js/SettingsWindow.js +++ b/js_src/SettingsWindow.js @@ -49,7 +49,7 @@ function SettingsWindow() { this.clientModeState = SettingsWindow.NOT_CONNECTED; this.currentAP; this.apModeState = SettingsWindow.NO_AP; - + // after switching wifi network or creating a access point we delay the status retrieval // because the webserver needs time to switch this.retrieveNetworkStatusDelay; // setTimout delay @@ -68,7 +68,6 @@ function SettingsWindow() { SettingsWindow.NO_AP = "no ap"; SettingsWindow.AP = "ap"; SettingsWindow.CREATING_AP = "creating ap"; - SettingsWindow.API_CONNECTING_FAILED = -1 SettingsWindow.API_NOT_CONNECTED = 0 @@ -77,6 +76,15 @@ function SettingsWindow() { SettingsWindow.API_CREATING = 3 SettingsWindow.API_CREATED = 4 + // network mode + SettingsWindow.NETWORK_MODE_NEITHER = "neither"; + SettingsWindow.NETWORK_MODE_CLIENT = "clientMode"; + SettingsWindow.NETWORK_MODE_ACCESS_POINT = "accessPointMode"; + + this.networkMode = SettingsWindow.NETWORK_MODE_NEITHER; + + this.updatePanel = new UpdatePanel(); + var self = this; this.init = function(wifiboxURL,wifiboxCGIBinURL) { @@ -108,6 +116,10 @@ function SettingsWindow() { btnConnect.on('touchstart mousedown',self.connectToNetwork); btnCreate.on('touchstart mousedown',self.createAP); networkSelector.change(self.networkSelectorChanged); + + // update panel + var $updatePanelElement = self.form.find("#updatePanel"); + self.updatePanel.init(wifiboxURL,$updatePanelElement); }); } this.submitwindow = function(e) { @@ -360,6 +372,8 @@ function SettingsWindow() { //console.log(" not connected & not a access point"); self.apFieldSet.show(); self.clientFieldSet.show(); + + self.networkMode = SettingsWindow.NETWORK_MODE_NEITHER; break; case SettingsWindow.API_CONNECTING_FAILED: case SettingsWindow.API_CONNECTING: @@ -380,7 +394,7 @@ function SettingsWindow() { } else { self.currentLocalIP = "" } - + self.networkMode = SettingsWindow.NETWORK_MODE_CLIENT; break; case SettingsWindow.API_CREATING: case SettingsWindow.API_CREATED: @@ -398,8 +412,10 @@ function SettingsWindow() { if(data.ssid && data.status == SettingsWindow.API_CREATED) { self.currentAP = data.ssid; } + self.networkMode = SettingsWindow.NETWORK_MODE_ACCESS_POINT; break; } + self.updatePanel.setNetworkMode(self.networkMode); // update status message switch(data.status) { @@ -456,6 +472,8 @@ function SettingsWindow() { this.selectNetwork = function(ssid) { console.log("select network: ",ssid); + if(ssid == "") return; + console.log(" checked"); this.selectedNetwork = ssid; if(this.networks == undefined || ssid == SettingsWindow.NOT_CONNECTED) { this.hideWiFiPassword(); diff --git a/www/js/Thermometer.js b/js_src/Thermometer.js similarity index 100% rename from www/js/Thermometer.js rename to js_src/Thermometer.js diff --git a/js_src/UpdatePanel.js b/js_src/UpdatePanel.js new file mode 100644 index 0000000..5c9558c --- /dev/null +++ b/js_src/UpdatePanel.js @@ -0,0 +1,230 @@ +function UpdatePanel() { + this.wifiboxURL; + this.element; + + this.statusCheckInterval = 1000; + this.statusCheckDelayer; // setTimout instance + this.installedDelay = 60*1000; // Since we can't retrieve status during installation we show the installed text after a fixed delay + this.installedDelayer; // setTimout instance + this.retryDelay = 1000; + this.retryDelayer; // setTimout instance + //this.timeoutTime = 3000; + + this.canUpdate = false; + this.currentVersion = ""; + this.newestVersion; + this.progress; + this.imageSize; + + // states from api, see Doodle3D firmware src/script/d3d-updater.lua + UpdatePanel.NONE = 1; // default state + UpdatePanel.DOWNLOADING = 2; + UpdatePanel.DOWNLOAD_FAILED = 3; + UpdatePanel.IMAGE_READY = 4; // download successfull and checked + UpdatePanel.INSTALLING = 5; + UpdatePanel.INSTALLED = 6; + UpdatePanel.INSTALL_FAILED = 7; + + this.state; // update state from api + this.stateText = ""; // update state text from api + + this.networkMode; // network modes from SettingsWindow + + var self = this; + + this.init = function(wifiboxURL,updatePanelElement) { + + this.wifiboxURL = wifiboxURL; + + this.element = updatePanelElement; + this.btnUpdate = this.element.find("#update"); + this.statusDisplay = this.element.find("#updateState"); + this.infoDisplay = this.element.find("#updateInfo"); + + this.btnUpdate.click(this.update); + + this.checkStatus(false); + } + + this.update = function() { + console.log("UpdatePanel:update"); + self.downloadUpdate(); + } + this.downloadUpdate = function() { + console.log("UpdatePanel:downloadUpdate"); + $.ajax({ + url: self.wifiboxURL + "/update/download", + type: "POST", + dataType: 'json', + success: function(response){ + console.log("UpdatePanel:downloadUpdate response: ",response); + } + }).fail(function() { + console.log("UpdatePanel:downloadUpdate: failed"); + }); + self.setState(UpdatePanel.DOWNLOADING); + self.startCheckingStatus(); + } + this.installUpdate = function() { + console.log("UpdatePanel:installUpdate"); + self.stopCheckingStatus(); + $.ajax({ + url: self.wifiboxURL + "/update/install", + type: "POST", + dataType: 'json', + success: function(response){ + console.log("UpdatePanel:installUpdate response: ",response); + } + }).fail(function() { + console.log("UpdatePanel:installUpdate: no respons (there shouldn't be)"); + }); + self.setState(UpdatePanel.INSTALLING); + + clearTimeout(self.installedDelayer); + self.installedDelayer = setTimeout(function() { self.setState(UpdatePanel.INSTALLED) },self.installedDelay); + } + + this.startCheckingStatus = function() { + clearTimeout(self.statusCheckDelayer); + clearTimeout(self.retryDelayer); + self.statusCheckDelayer = setTimeout(function() { self.checkStatus(true) },self.statusCheckInterval); + } + this.stopCheckingStatus = function() { + clearTimeout(self.statusCheckDelayer); + clearTimeout(self.retryDelayer); + } + this.checkStatus = function(keepChecking) { + if (!communicateWithWifibox) return; + $.ajax({ + url: self.wifiboxURL + "/update/status", + type: "GET", + dataType: 'json', + //timeout: self.timeoutTime, + success: function(response){ + console.log("UpdatePanel:checkStatus response: ",response); + + // Keep checking ? + if(keepChecking) { + switch(self.state){ + case UpdatePanel.DOWNLOADING: + case UpdatePanel.INSTALLING: + clearTimeout(self.statusCheckDelayer); + self.statusCheckDelayer = setTimeout(function() { self.checkStatus(keepChecking) },self.statusCheckInterval); + break; + } + } + + if(response.status != "error") { + var data = response.data; + self.handleStatusData(data); + } + } + }).fail(function() { + //console.log("UpdatePanel:checkStatus: failed"); + if(keepChecking) { + clearTimeout(self.retryDelayer); + self.retryDelayer = setTimeout(function() { self.checkStatus(keepChecking) },self.retryDelay); // retry after delay + } + }); + } + + this.handleStatusData = function(data) { + //console.log("UpdatePanel:handleStatusData"); + self.canUpdate = data.can_update; + + if(self.currentVersion != data.current_version || self.newestVersion != data.newest_version) { + self.currentVersion = data.current_version; + self.newestVersion = data.newest_version; + self.updateInfoDisplay(); + } + + self.stateText = data.state_text; + self.progress = data.progress; // not always available + self.imageSize = data.image_size; // not always available + + self.setState(data.state_code); + + switch(this.state){ + case UpdatePanel.IMAGE_READY: + self.installUpdate(); + break; + } + } + this.setState = function(newState) { + if(this.state == newState) return; + console.log("UpdatePanel:setState: ",this.state," > ",newState,"(",this.stateText,") (networkMode: ",self.networkMode,") (newestVersion: ",self.newestVersion,")"); + this.state = newState; + + // download button + // if there isn't newestVersion data something went wrong, + // probably accessing the internet + if(self.newestVersion != undefined) { + switch(this.state){ + case UpdatePanel.NONE: + case UpdatePanel.DOWNLOAD_FAILED: + case UpdatePanel.INSTALL_FAILED: + if(self.canUpdate) { + self.btnUpdate.removeAttr("disabled"); + } else { + self.btnUpdate.attr("disabled", true); + } + break; + default: + self.btnUpdate.attr("disabled", true); + break; + } + } else { + self.btnUpdate.attr("disabled", true); + } + this.updateStatusDisplay(); + } + this.updateStatusDisplay = function() { + var text = ""; + if(self.newestVersion != undefined) { + switch(this.state){ + case UpdatePanel.NONE: + if(self.canUpdate) { + text = "Update(s) available."; + } else { + text = "You're up to date."; + } + break; + case UpdatePanel.DOWNLOADING: + text = "Downloading update..."; + break; + case UpdatePanel.DOWNLOAD_FAILED: + text = "Downloading update failed."; + break; + case UpdatePanel.IMAGE_READY: + text = "Update downloaded."; + break; + case UpdatePanel.INSTALLING: + text = "Installing update... (will take a minute)"; + break; + case UpdatePanel.INSTALLED: + text = "Update complete, please refresh Page."; + break; + case UpdatePanel.INSTALL_FAILED: + text = "Installing update failed."; + break; + } + } else { + if(self.networkMode == SettingsWindow.NETWORK_MODE_ACCESS_POINT) { + text = "Can't access internet in access point mode."; + } else { + text = "Can't access internet."; + } + } + this.statusDisplay.html(text); + } + this.updateInfoDisplay = function() { + var text = "Current version: "+self.currentVersion+". "; + if(self.canUpdate) { + text += "Latest version: "+self.newestVersion+"."; + } + self.infoDisplay.text(text); + } + this.setNetworkMode = function(networkMode) { + self.networkMode = networkMode; + } +} \ No newline at end of file diff --git a/www/js/buttonbehaviors.js b/js_src/buttonbehaviors.js similarity index 100% rename from www/js/buttonbehaviors.js rename to js_src/buttonbehaviors.js diff --git a/www/js/canvasDrawing.js b/js_src/canvasDrawing.js similarity index 100% rename from www/js/canvasDrawing.js rename to js_src/canvasDrawing.js diff --git a/www/js/d3dServerInterfacing.js b/js_src/d3dServerInterfacing.js similarity index 100% rename from www/js/d3dServerInterfacing.js rename to js_src/d3dServerInterfacing.js diff --git a/www/js/gcodeGenerating.js b/js_src/gcodeGenerating.js similarity index 94% rename from www/js/gcodeGenerating.js rename to js_src/gcodeGenerating.js index 6dd50be..8cd3a4c 100644 --- a/www/js/gcodeGenerating.js +++ b/js_src/gcodeGenerating.js @@ -49,6 +49,7 @@ function generate_gcode() { var layerHeight = settings["printer.layerHeight"]; var maxObjectHeight = settings["printer.maxObjectHeight"]; var temperature = settings["printer.temperature"]; + var bedTemperature = settings["printer.bed.temperature"]; var useSubLayers = settings["printer.useSubLayers"]; var enableTraveling = settings["printer.enableTraveling"]; var retractionEnabled = settings["printer.retraction.enabled"]; @@ -56,15 +57,14 @@ function generate_gcode() { var retractionminDistance = settings["printer.retraction.minDistance"]; var retractionamount = settings["printer.retraction.amount"]; var preheatTemperature = settings["printer.heatup.temperature"]; + var preheatBedTemperature = settings["printer.heatup.bed.temperature"]; var startGcode = settings["printer.startgcode"]; - startGcode = startGcode.replace("{printingTemp}",temperature); - startGcode = startGcode.replace("{preheatTemp}",preheatTemperature); + startGcode = subsituteVariables(startGcode,temperature,bedTemperature,preheatTemperature,preheatBedTemperature); startGcode = startGcode.split("\n"); var endGcode = settings["printer.endgcode"]; - endGcode = endGcode.replace("{printingTemp}",temperature); - endGcode = endGcode.replace("{preheatTemp}",preheatTemperature); + endGcode = subsituteVariables(endGcode,temperature,bedTemperature,preheatTemperature,preheatBedTemperature); endGcode = endGcode.split("\n"); /* @@ -260,6 +260,16 @@ function generate_gcode() { return gcode; } +function subsituteVariables(gcode,temperature,bedTemperature,preheatTemperature,preheatBedTemperature) { + + gcode = gcode.replace(/{printingTemp}/gi ,temperature); + gcode = gcode.replace(/{printingBedTemp}/gi ,bedTemperature); + gcode = gcode.replace(/{preheatTemp}/gi ,preheatTemperature); + gcode = gcode.replace(/{preheatBedTemp}/gi ,preheatBedTemperature); + + return gcode; +} + function scaleFunction(percent) { var r = 1.0; diff --git a/js_src/init_layout.js b/js_src/init_layout.js new file mode 100644 index 0000000..4191375 --- /dev/null +++ b/js_src/init_layout.js @@ -0,0 +1,62 @@ +// TODO refactor this stuff, there's much to wipe +var drawAreaContainerMinHeight = 300; +var drawAreaContainerMaxHeight = 450; + +function doOnResize() { + // console.log("doOnResize() >> " + new Date().getTime()); + canvas.width = $canvas.width(); + canvas.height = $canvas.height(); // canvas.clientHeight; + + preview.width = $preview.width(); + preview.height = $drawAreaContainer.height(); + + canvasWidth = canvas.width; + canvasHeight = canvas.height; + + console.log(" preview.width: " + preview.width + ", $preview.width(): " + $preview.width()); + + calcPreviewCanvasProperties(); + + drawCanvasTopLeftCoords[0] = drawCanvas.offset().left; + drawCanvasTopLeftCoords[1] = drawCanvas.offset().top; + + redrawDoodle(); + redrawPreview(); + +} + +function initLayouting() { + console.log("f:initLayouting()"); + + $drawAreaContainer = $(".drawareacontainer"); + + canvas.width = $canvas.width(); + canvas.height = $canvas.height(); // canvas.clientHeight; + + preview.width = $preview.width(); + preview.height = $drawAreaContainer.height(); + + canvasWidth = canvas.width; + canvasHeight = canvas.height; + + $drawAreaContainer.show(); + + // window.innerHeight + console.log("window.innerHeight: " + window.innerHeight); + console.log("window.innerWidth: " + window.innerWidth); + console.log("$drawAreaContainer.innerHeight(): " + $drawAreaContainer.innerHeight()); + console.log("$drawAreaContainer.offset().top: " + $drawAreaContainer.offset().top); + + // timeout because it SEEMS to be beneficial for initting the layout + // 2013-09-18 seems beneficial since when? + setTimeout(_startOrientationAndChangeEventListening, 1000); +} + +function _startOrientationAndChangeEventListening() { + // Initial execution if needed + + $(window).on('resize', doOnResize); + + // is it necessary to call these? Aren't they called by the above eventhandlers? + doOnResize(); +} diff --git a/www/js/libs/excanvas.js b/js_src/libs/excanvas.js similarity index 100% rename from www/js/libs/excanvas.js rename to js_src/libs/excanvas.js diff --git a/js_src/libs/imagesloaded.pkgd.js b/js_src/libs/imagesloaded.pkgd.js new file mode 100644 index 0000000..65c5f14 --- /dev/null +++ b/js_src/libs/imagesloaded.pkgd.js @@ -0,0 +1,836 @@ +/*! + * imagesLoaded PACKAGED v3.0.4 + * JavaScript is all like "You images are done yet or what?" + * MIT License + */ + +/*! + * EventEmitter v4.2.4 - git.io/ee + * Oliver Caldwell + * MIT license + * @preserve + */ + +(function () { + 'use strict'; + + /** + * Class for managing events. + * Can be extended to provide event functionality in other classes. + * + * @class EventEmitter Manages event registering and emitting. + */ + function EventEmitter() {} + + // Shortcuts to improve speed and size + + // Easy access to the prototype + var proto = EventEmitter.prototype; + + /** + * Finds the index of the listener for the event in it's storage array. + * + * @param {Function[]} listeners Array of listeners to search through. + * @param {Function} listener Method to look for. + * @return {Number} Index of the specified listener, -1 if not found + * @api private + */ + function indexOfListener(listeners, listener) { + var i = listeners.length; + while (i--) { + if (listeners[i].listener === listener) { + return i; + } + } + + return -1; + } + + /** + * Alias a method while keeping the context correct, to allow for overwriting of target method. + * + * @param {String} name The name of the target method. + * @return {Function} The aliased method + * @api private + */ + function alias(name) { + return function aliasClosure() { + return this[name].apply(this, arguments); + }; + } + + /** + * Returns the listener array for the specified event. + * Will initialise the event object and listener arrays if required. + * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them. + * Each property in the object response is an array of listener functions. + * + * @param {String|RegExp} evt Name of the event to return the listeners from. + * @return {Function[]|Object} All listener functions for the event. + */ + proto.getListeners = function getListeners(evt) { + var events = this._getEvents(); + var response; + var key; + + // Return a concatenated array of all matching events if + // the selector is a regular expression. + if (typeof evt === 'object') { + response = {}; + for (key in events) { + if (events.hasOwnProperty(key) && evt.test(key)) { + response[key] = events[key]; + } + } + } + else { + response = events[evt] || (events[evt] = []); + } + + return response; + }; + + /** + * Takes a list of listener objects and flattens it into a list of listener functions. + * + * @param {Object[]} listeners Raw listener objects. + * @return {Function[]} Just the listener functions. + */ + proto.flattenListeners = function flattenListeners(listeners) { + var flatListeners = []; + var i; + + for (i = 0; i < listeners.length; i += 1) { + flatListeners.push(listeners[i].listener); + } + + return flatListeners; + }; + + /** + * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful. + * + * @param {String|RegExp} evt Name of the event to return the listeners from. + * @return {Object} All listener functions for an event in an object. + */ + proto.getListenersAsObject = function getListenersAsObject(evt) { + var listeners = this.getListeners(evt); + var response; + + if (listeners instanceof Array) { + response = {}; + response[evt] = listeners; + } + + return response || listeners; + }; + + /** + * Adds a listener function to the specified event. + * The listener will not be added if it is a duplicate. + * If the listener returns true then it will be removed after it is called. + * If you pass a regular expression as the event name then the listener will be added to all events that match it. + * + * @param {String|RegExp} evt Name of the event to attach the listener to. + * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.addListener = function addListener(evt, listener) { + var listeners = this.getListenersAsObject(evt); + var listenerIsWrapped = typeof listener === 'object'; + var key; + + for (key in listeners) { + if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) { + listeners[key].push(listenerIsWrapped ? listener : { + listener: listener, + once: false + }); + } + } + + return this; + }; + + /** + * Alias of addListener + */ + proto.on = alias('addListener'); + + /** + * Semi-alias of addListener. It will add a listener that will be + * automatically removed after it's first execution. + * + * @param {String|RegExp} evt Name of the event to attach the listener to. + * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.addOnceListener = function addOnceListener(evt, listener) { + return this.addListener(evt, { + listener: listener, + once: true + }); + }; + + /** + * Alias of addOnceListener. + */ + proto.once = alias('addOnceListener'); + + /** + * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad. + * You need to tell it what event names should be matched by a regex. + * + * @param {String} evt Name of the event to create. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.defineEvent = function defineEvent(evt) { + this.getListeners(evt); + return this; + }; + + /** + * Uses defineEvent to define multiple events. + * + * @param {String[]} evts An array of event names to define. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.defineEvents = function defineEvents(evts) { + for (var i = 0; i < evts.length; i += 1) { + this.defineEvent(evts[i]); + } + return this; + }; + + /** + * Removes a listener function from the specified event. + * When passed a regular expression as the event name, it will remove the listener from all events that match it. + * + * @param {String|RegExp} evt Name of the event to remove the listener from. + * @param {Function} listener Method to remove from the event. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.removeListener = function removeListener(evt, listener) { + var listeners = this.getListenersAsObject(evt); + var index; + var key; + + for (key in listeners) { + if (listeners.hasOwnProperty(key)) { + index = indexOfListener(listeners[key], listener); + + if (index !== -1) { + listeners[key].splice(index, 1); + } + } + } + + return this; + }; + + /** + * Alias of removeListener + */ + proto.off = alias('removeListener'); + + /** + * Adds listeners in bulk using the manipulateListeners method. + * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added. + * You can also pass it a regular expression to add the array of listeners to all events that match it. + * Yeah, this function does quite a bit. That's probably a bad thing. + * + * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once. + * @param {Function[]} [listeners] An optional array of listener functions to add. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.addListeners = function addListeners(evt, listeners) { + // Pass through to manipulateListeners + return this.manipulateListeners(false, evt, listeners); + }; + + /** + * Removes listeners in bulk using the manipulateListeners method. + * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. + * You can also pass it an event name and an array of listeners to be removed. + * You can also pass it a regular expression to remove the listeners from all events that match it. + * + * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once. + * @param {Function[]} [listeners] An optional array of listener functions to remove. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.removeListeners = function removeListeners(evt, listeners) { + // Pass through to manipulateListeners + return this.manipulateListeners(true, evt, listeners); + }; + + /** + * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level. + * The first argument will determine if the listeners are removed (true) or added (false). + * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. + * You can also pass it an event name and an array of listeners to be added/removed. + * You can also pass it a regular expression to manipulate the listeners of all events that match it. + * + * @param {Boolean} remove True if you want to remove listeners, false if you want to add. + * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once. + * @param {Function[]} [listeners] An optional array of listener functions to add/remove. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) { + var i; + var value; + var single = remove ? this.removeListener : this.addListener; + var multiple = remove ? this.removeListeners : this.addListeners; + + // If evt is an object then pass each of it's properties to this method + if (typeof evt === 'object' && !(evt instanceof RegExp)) { + for (i in evt) { + if (evt.hasOwnProperty(i) && (value = evt[i])) { + // Pass the single listener straight through to the singular method + if (typeof value === 'function') { + single.call(this, i, value); + } + else { + // Otherwise pass back to the multiple function + multiple.call(this, i, value); + } + } + } + } + else { + // So evt must be a string + // And listeners must be an array of listeners + // Loop over it and pass each one to the multiple method + i = listeners.length; + while (i--) { + single.call(this, evt, listeners[i]); + } + } + + return this; + }; + + /** + * Removes all listeners from a specified event. + * If you do not specify an event then all listeners will be removed. + * That means every event will be emptied. + * You can also pass a regex to remove all events that match it. + * + * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.removeEvent = function removeEvent(evt) { + var type = typeof evt; + var events = this._getEvents(); + var key; + + // Remove different things depending on the state of evt + if (type === 'string') { + // Remove all listeners for the specified event + delete events[evt]; + } + else if (type === 'object') { + // Remove all events matching the regex. + for (key in events) { + if (events.hasOwnProperty(key) && evt.test(key)) { + delete events[key]; + } + } + } + else { + // Remove all listeners in all events + delete this._events; + } + + return this; + }; + + /** + * Alias of removeEvent. + * + * Added to mirror the node API. + */ + proto.removeAllListeners = alias('removeEvent'); + + /** + * Emits an event of your choice. + * When emitted, every listener attached to that event will be executed. + * If you pass the optional argument array then those arguments will be passed to every listener upon execution. + * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately. + * So they will not arrive within the array on the other side, they will be separate. + * You can also pass a regular expression to emit to all events that match it. + * + * @param {String|RegExp} evt Name of the event to emit and execute listeners for. + * @param {Array} [args] Optional array of arguments to be passed to each listener. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.emitEvent = function emitEvent(evt, args) { + var listeners = this.getListenersAsObject(evt); + var listener; + var i; + var key; + var response; + + for (key in listeners) { + if (listeners.hasOwnProperty(key)) { + i = listeners[key].length; + + while (i--) { + // If the listener returns true then it shall be removed from the event + // The function is executed either with a basic call or an apply if there is an args array + listener = listeners[key][i]; + + if (listener.once === true) { + this.removeListener(evt, listener.listener); + } + + response = listener.listener.apply(this, args || []); + + if (response === this._getOnceReturnValue()) { + this.removeListener(evt, listener.listener); + } + } + } + } + + return this; + }; + + /** + * Alias of emitEvent + */ + proto.trigger = alias('emitEvent'); + + /** + * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on. + * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it. + * + * @param {String|RegExp} evt Name of the event to emit and execute listeners for. + * @param {...*} Optional additional arguments to be passed to each listener. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.emit = function emit(evt) { + var args = Array.prototype.slice.call(arguments, 1); + return this.emitEvent(evt, args); + }; + + /** + * Sets the current value to check against when executing listeners. If a + * listeners return value matches the one set here then it will be removed + * after execution. This value defaults to true. + * + * @param {*} value The new value to check for when executing listeners. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.setOnceReturnValue = function setOnceReturnValue(value) { + this._onceReturnValue = value; + return this; + }; + + /** + * Fetches the current value to check against when executing listeners. If + * the listeners return value matches this one then it should be removed + * automatically. It will return true by default. + * + * @return {*|Boolean} The current value to check for or the default, true. + * @api private + */ + proto._getOnceReturnValue = function _getOnceReturnValue() { + if (this.hasOwnProperty('_onceReturnValue')) { + return this._onceReturnValue; + } + else { + return true; + } + }; + + /** + * Fetches the events object and creates one if required. + * + * @return {Object} The events storage object. + * @api private + */ + proto._getEvents = function _getEvents() { + return this._events || (this._events = {}); + }; + + // Expose the class either via AMD, CommonJS or the global object + if (typeof define === 'function' && define.amd) { + define(function () { + return EventEmitter; + }); + } + else if (typeof module === 'object' && module.exports){ + module.exports = EventEmitter; + } + else { + this.EventEmitter = EventEmitter; + } +}.call(this)); + +/*! + * eventie v1.0.3 + * event binding helper + * eventie.bind( elem, 'click', myFn ) + * eventie.unbind( elem, 'click', myFn ) + */ + +/*jshint browser: true, undef: true, unused: true */ +/*global define: false */ + +( function( window ) { + +'use strict'; + +var docElem = document.documentElement; + +var bind = function() {}; + +if ( docElem.addEventListener ) { + bind = function( obj, type, fn ) { + obj.addEventListener( type, fn, false ); + }; +} else if ( docElem.attachEvent ) { + bind = function( obj, type, fn ) { + obj[ type + fn ] = fn.handleEvent ? + function() { + var event = window.event; + // add event.target + event.target = event.target || event.srcElement; + fn.handleEvent.call( fn, event ); + } : + function() { + var event = window.event; + // add event.target + event.target = event.target || event.srcElement; + fn.call( obj, event ); + }; + obj.attachEvent( "on" + type, obj[ type + fn ] ); + }; +} + +var unbind = function() {}; + +if ( docElem.removeEventListener ) { + unbind = function( obj, type, fn ) { + obj.removeEventListener( type, fn, false ); + }; +} else if ( docElem.detachEvent ) { + unbind = function( obj, type, fn ) { + obj.detachEvent( "on" + type, obj[ type + fn ] ); + try { + delete obj[ type + fn ]; + } catch ( err ) { + // can't delete window object properties + obj[ type + fn ] = undefined; + } + }; +} + +var eventie = { + bind: bind, + unbind: unbind +}; + +// transport +if ( typeof define === 'function' && define.amd ) { + // AMD + define( eventie ); +} else { + // browser global + window.eventie = eventie; +} + +})( this ); + +/*! + * imagesLoaded v3.0.4 + * JavaScript is all like "You images are done yet or what?" + * MIT License + */ + +( function( window ) { + +'use strict'; + +var $ = window.jQuery; +var console = window.console; +var hasConsole = typeof console !== 'undefined'; + +// -------------------------- helpers -------------------------- // + +// extend objects +function extend( a, b ) { + for ( var prop in b ) { + a[ prop ] = b[ prop ]; + } + return a; +} + +var objToString = Object.prototype.toString; +function isArray( obj ) { + return objToString.call( obj ) === '[object Array]'; +} + +// turn element or nodeList into an array +function makeArray( obj ) { + var ary = []; + if ( isArray( obj ) ) { + // use object if already an array + ary = obj; + } else if ( typeof obj.length === 'number' ) { + // convert nodeList to array + for ( var i=0, len = obj.length; i < len; i++ ) { + ary.push( obj[i] ); + } + } else { + // array of single index + ary.push( obj ); + } + return ary; +} + +// -------------------------- -------------------------- // + +function defineImagesLoaded( EventEmitter, eventie ) { + + /** + * @param {Array, Element, NodeList, String} elem + * @param {Object or Function} options - if function, use as callback + * @param {Function} onAlways - callback function + */ + function ImagesLoaded( elem, options, onAlways ) { + // coerce ImagesLoaded() without new, to be new ImagesLoaded() + if ( !( this instanceof ImagesLoaded ) ) { + return new ImagesLoaded( elem, options ); + } + // use elem as selector string + if ( typeof elem === 'string' ) { + elem = document.querySelectorAll( elem ); + } + + this.elements = makeArray( elem ); + this.options = extend( {}, this.options ); + + if ( typeof options === 'function' ) { + onAlways = options; + } else { + extend( this.options, options ); + } + + if ( onAlways ) { + this.on( 'always', onAlways ); + } + + this.getImages(); + + if ( $ ) { + // add jQuery Deferred object + this.jqDeferred = new $.Deferred(); + } + + // HACK check async to allow time to bind listeners + var _this = this; + setTimeout( function() { + _this.check(); + }); + } + + ImagesLoaded.prototype = new EventEmitter(); + + ImagesLoaded.prototype.options = {}; + + ImagesLoaded.prototype.getImages = function() { + this.images = []; + + // filter & find items if we have an item selector + for ( var i=0, len = this.elements.length; i < len; i++ ) { + var elem = this.elements[i]; + // filter siblings + if ( elem.nodeName === 'IMG' ) { + this.addImage( elem ); + } + // find children + var childElems = elem.querySelectorAll('img'); + // concat childElems to filterFound array + for ( var j=0, jLen = childElems.length; j < jLen; j++ ) { + var img = childElems[j]; + this.addImage( img ); + } + } + }; + + /** + * @param {Image} img + */ + ImagesLoaded.prototype.addImage = function( img ) { + var loadingImage = new LoadingImage( img ); + this.images.push( loadingImage ); + }; + + ImagesLoaded.prototype.check = function() { + var _this = this; + var checkedCount = 0; + var length = this.images.length; + this.hasAnyBroken = false; + // complete if no images + if ( !length ) { + this.complete(); + return; + } + + function onConfirm( image, message ) { + if ( _this.options.debug && hasConsole ) { + console.log( 'confirm', image, message ); + } + + _this.progress( image ); + checkedCount++; + if ( checkedCount === length ) { + _this.complete(); + } + return true; // bind once + } + + for ( var i=0; i < length; i++ ) { + var loadingImage = this.images[i]; + loadingImage.on( 'confirm', onConfirm ); + loadingImage.check(); + } + }; + + ImagesLoaded.prototype.progress = function( image ) { + this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded; + // HACK - Chrome triggers event before object properties have changed. #83 + var _this = this; + setTimeout( function() { + _this.emit( 'progress', _this, image ); + if ( _this.jqDeferred ) { + _this.jqDeferred.notify( _this, image ); + } + }); + }; + + ImagesLoaded.prototype.complete = function() { + var eventName = this.hasAnyBroken ? 'fail' : 'done'; + this.isComplete = true; + var _this = this; + // HACK - another setTimeout so that confirm happens after progress + setTimeout( function() { + _this.emit( eventName, _this ); + _this.emit( 'always', _this ); + if ( _this.jqDeferred ) { + var jqMethod = _this.hasAnyBroken ? 'reject' : 'resolve'; + _this.jqDeferred[ jqMethod ]( _this ); + } + }); + }; + + // -------------------------- jquery -------------------------- // + + if ( $ ) { + $.fn.imagesLoaded = function( options, callback ) { + var instance = new ImagesLoaded( this, options, callback ); + return instance.jqDeferred.promise( $(this) ); + }; + } + + + // -------------------------- -------------------------- // + + var cache = {}; + + function LoadingImage( img ) { + this.img = img; + } + + LoadingImage.prototype = new EventEmitter(); + + LoadingImage.prototype.check = function() { + // first check cached any previous images that have same src + var cached = cache[ this.img.src ]; + if ( cached ) { + this.useCached( cached ); + return; + } + // add this to cache + cache[ this.img.src ] = this; + + // If complete is true and browser supports natural sizes, + // try to check for image status manually. + if ( this.img.complete && this.img.naturalWidth !== undefined ) { + // report based on naturalWidth + this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' ); + return; + } + + // If none of the checks above matched, simulate loading on detached element. + var proxyImage = this.proxyImage = new Image(); + eventie.bind( proxyImage, 'load', this ); + eventie.bind( proxyImage, 'error', this ); + proxyImage.src = this.img.src; + }; + + LoadingImage.prototype.useCached = function( cached ) { + if ( cached.isConfirmed ) { + this.confirm( cached.isLoaded, 'cached was confirmed' ); + } else { + var _this = this; + cached.on( 'confirm', function( image ) { + _this.confirm( image.isLoaded, 'cache emitted confirmed' ); + return true; // bind once + }); + } + }; + + LoadingImage.prototype.confirm = function( isLoaded, message ) { + this.isConfirmed = true; + this.isLoaded = isLoaded; + this.emit( 'confirm', this, message ); + }; + + // trigger specified handler for event type + LoadingImage.prototype.handleEvent = function( event ) { + var method = 'on' + event.type; + if ( this[ method ] ) { + this[ method ]( event ); + } + }; + + LoadingImage.prototype.onload = function() { + this.confirm( true, 'onload' ); + this.unbindProxyEvents(); + }; + + LoadingImage.prototype.onerror = function() { + this.confirm( false, 'onerror' ); + this.unbindProxyEvents(); + }; + + LoadingImage.prototype.unbindProxyEvents = function() { + eventie.unbind( this.proxyImage, 'load', this ); + eventie.unbind( this.proxyImage, 'error', this ); + }; + + // ----- ----- // + + return ImagesLoaded; +} + +// -------------------------- transport -------------------------- // + +if ( typeof define === 'function' && define.amd ) { + // AMD + define( [ + 'eventEmitter/EventEmitter', + 'eventie/eventie' + ], + defineImagesLoaded ); +} else { + // browser global + window.imagesLoaded = defineImagesLoaded( + window.EventEmitter, + window.eventie + ); +} + +})( window ); diff --git a/js_src/libs/jquery-tourbus.js b/js_src/libs/jquery-tourbus.js new file mode 100644 index 0000000..385e95e --- /dev/null +++ b/js_src/libs/jquery-tourbus.js @@ -0,0 +1,539 @@ +(function() { + var __slice = [].slice; + + (function($) { + var Bus, Leg, methods, tourbus, uniqueId, _addRule, _assemble, _busses, _dataProp, _include, _tours; + tourbus = $.tourbus = function() { + var args, method; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + method = args[0]; + if (methods.hasOwnProperty(method)) { + args = args.slice(1); + } else if (method instanceof $) { + method = 'build'; + } else if (typeof method === 'string') { + method = 'build'; + args[0] = $(args[0]); + } else { + $.error("Unknown method of $.tourbus --", args); + } + return methods[method].apply(this, args); + }; + $.fn.tourbus = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return this.each(function() { + args.unshift($(this)); + tourbus.apply(null, ['build'].concat(__slice.call(args))); + return this; + }); + }; + methods = { + build: function(el, options) { + var built; + if (options == null) { + options = {}; + } + options = $.extend(true, {}, tourbus.defaults, options); + built = []; + if (!(el instanceof $)) { + el = $(el); + } + el.each(function() { + return built.push(_assemble(this, options)); + }); + if (built.length === 0) { + $.error("" + el.selector + " was not found!"); + } + if (built.length === 1) { + return built[0]; + } + return built; + }, + destroyAll: function() { + var bus, index, _results; + _results = []; + for (index in _busses) { + bus = _busses[index]; + _results.push(bus.destroy()); + } + return _results; + }, + expose: function(global) { + return global.tourbus = { + Bus: Bus, + Leg: Leg + }; + } + }; + tourbus.defaults = { + debug: false, + autoDepart: false, + target: 'body', + startAt: 0, + onDepart: function() { + return null; + }, + onStop: function() { + return null; + }, + onLegStart: function() { + return null; + }, + onLegEnd: function() { + return null; + }, + leg: { + scrollTo: null, + scrollSpeed: 150, + scrollContext: 100, + orientation: 'bottom', + align: 'left', + width: 'auto', + margin: 10, + top: null, + left: null, + arrow: "35%" + } + }; + /* Internal + */ + + Bus = (function() { + + function Bus(el, options) { + this.id = uniqueId(); + this.$target = $(options.target); + this.$el = $(el); + this.$el.data({ + tourbus: this + }); + this.options = options; + this.currentLegIndex = null; + this.legs = null; + this.legEls = this.$el.children('li'); + this.totalLegs = this.legEls.length; + this._setupEvents(); + if (this.options.autoDepart) { + this.$el.trigger('depart.tourbus'); + } + this._log('built tourbus with el', el.toString(), 'and options', this.options); + } + + Bus.prototype.depart = function() { + this.running = true; + this.options.onDepart(this); + this._log('departing', this); + this.legs = this._buildLegs(); + this.currentLegIndex = this.options.startAt; + return this.showLeg(); + }; + + Bus.prototype.stop = function() { + if (!this.running) { + return; + } + if (this.legs) { + $.each(this.legs, $.proxy(this.hideLeg, this)); + } + this.currentLegIndex = this.options.startAt; + this.options.onStop(this); + return this.running = false; + }; + + Bus.prototype.on = function(event, selector, fn) { + return this.$target.on(event, selector, fn); + }; + + Bus.prototype.currentLeg = function() { + if (this.currentLegIndex === null) { + return null; + } + return this.legs[this.currentLegIndex]; + }; + + Bus.prototype.showLeg = function(index) { + var leg, preventDefault; + if (index == null) { + index = this.currentLegIndex; + } + leg = this.legs[index]; + this._log('showLeg:', leg); + preventDefault = this.options.onLegStart(leg, this); + if (preventDefault !== false) { + return leg.show(); + } + }; + + Bus.prototype.hideLeg = function(index) { + var leg, preventDefault; + if (index == null) { + index = this.currentLegIndex; + } + leg = this.legs[index]; + this._log('hideLeg:', leg); + preventDefault = this.options.onLegEnd(leg, this); + if (preventDefault !== false) { + return leg.hide(); + } + }; + + Bus.prototype.repositionLegs = function() { + if (this.legs) { + return $.each(this.legs, function() { + return this.reposition(); + }); + } + }; + + Bus.prototype.next = function() { + this.hideLeg(); + this.currentLegIndex++; + if (this.currentLegIndex > this.totalLegs - 1) { + return this.stop(); + } + return this.showLeg(); + }; + + Bus.prototype.prev = function(cb) { + this.hideLeg(); + this.currentLegIndex--; + if (this.currentLegIndex < 0) { + return this.stop(); + } + return this.showLeg(); + }; + + Bus.prototype.destroy = function() { + if (this.legs) { + $.each(this.legs, function() { + return this.destroy(); + }); + } + this.legs = null; + delete _busses[this.id]; + return this._teardownEvents(); + }; + + Bus.prototype._buildLegs = function() { + var _this = this; + if (this.legs) { + $.each(this.legs, function(_, leg) { + return leg.destroy(); + }); + } + return $.map(this.legEls, function(legEl, i) { + var $legEl, data, leg; + $legEl = $(legEl); + data = $legEl.data(); + leg = new Leg({ + content: $legEl.html(), + target: data.el || 'body', + bus: _this, + index: i, + rawData: data + }); + leg.render(); + _this.$target.append(leg.$el); + leg._position(); + leg.hide(); + return leg; + }); + }; + + Bus.prototype._log = function() { + if (!this.options.debug) { + return; + } + return console.log.apply(console, ["TOURBUS " + this.id + ":"].concat(__slice.call(arguments))); + }; + + Bus.prototype._setupEvents = function() { + this.$el.on('depart.tourbus', $.proxy(this.depart, this)); + this.$el.on('stop.tourbus', $.proxy(this.stop, this)); + this.$el.on('next.tourbus', $.proxy(this.next, this)); + return this.$el.on('prev.tourbus', $.proxy(this.prev, this)); + }; + + Bus.prototype._teardownEvents = function() { + return this.$el.off('.tourbus'); + }; + + return Bus; + + })(); + Leg = (function() { + + function Leg(options) { + this.bus = options.bus; + this.rawData = options.rawData; + this.content = options.content; + this.index = options.index; + this.options = options; + this.$target = $(options.target); + if (this.$target.length === 0) { + throw "" + this.$target.selector + " is not an element!"; + } + this._setupOptions(); + this._configureElement(); + this._configureTarget(); + this._configureScroll(); + this._setupEvents(); + this.bus._log("leg " + this.index + " made with options", this.options); + } + + Leg.prototype.render = function() { + var arrowClass, html; + arrowClass = this.options.orientation === 'centered' ? '' : 'tourbus-arrow'; + this.$el.addClass(" " + arrowClass + " tourbus-arrow-" + this.options.orientation + " "); + html = "
This is your first time starting the app. How about we show you around a bit?
+ Yes + No +Random text which makes it all seem like there's something to say...
+ + Next... +Random text which makes it all seem like there's something to say...
+ + Next... +Random text which makes it all seem like there's something to say...
+ + Next... +Random text which makes it all seem like there's something to say...
+ + Next... +Random text which makes it all seem like there's something to say...
+ + Next... +Random text which makes it all seem like there's something to say...
+ + Next... +Random text which makes it all seem like there's something to say...
+ + Next... +Random text which makes it all seem like there's something to say...
+ + Next... +Random text which makes it all seem like there's something to say...
+ + Next... +Random text which makes it all seem like there's something to say...
+ + Next... +Random text which makes it all seem like there's something to say...
+ + Got it... +check out the info here anytime..
+ Got it +