From 183db30ce4d01bd7321f6b4e476e8486f978c0cb Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Sun, 3 May 2015 22:03:06 -0500 Subject: [PATCH] rename webview to engine --- ionic/components/tabs/test/basic/main.js | 24 +++--- ionic/{webview => engine}/cordova/cordova.js | 29 ++++--- ionic/engine/electron/electron.js | 37 ++++++++ ionic/engine/engine.js | 73 ++++++++++++++++ ionic/ionic.js | 7 +- ionic/ionic.scss | 4 - ionic/webview/cordova/cordova.scss | 0 ionic/webview/node-webkit/node-webkit.js | 28 ------ ionic/webview/node-webkit/node-webkit.scss | 0 ionic/webview/webview.js | 89 -------------------- 10 files changed, 140 insertions(+), 151 deletions(-) rename ionic/{webview => engine}/cordova/cordova.js (61%) create mode 100644 ionic/engine/electron/electron.js create mode 100644 ionic/engine/engine.js delete mode 100644 ionic/webview/cordova/cordova.scss delete mode 100644 ionic/webview/node-webkit/node-webkit.js delete mode 100644 ionic/webview/node-webkit/node-webkit.scss delete mode 100644 ionic/webview/webview.js diff --git a/ionic/components/tabs/test/basic/main.js b/ionic/components/tabs/test/basic/main.js index 30c22497a2..5378e2759e 100644 --- a/ionic/components/tabs/test/basic/main.js +++ b/ionic/components/tabs/test/basic/main.js @@ -1,8 +1,6 @@ import {Component, View as NgView, bootstrap} from 'angular2/angular2' import {View, Tabs, Tab} from 'ionic/ionic' -import {webview} from 'ionic/webview/webview' -import {cordova} from 'ionic/webview/cordova/cordova' -import {nodeWebkit} from 'ionic/webview/node-webkit/node-webkit' +import {engine} from 'ionic/engine/engine' import * as util from 'ionic/util' @@ -13,23 +11,23 @@ import * as util from 'ionic/util' }) class IonicApp { constructor() { - console.log('IonicApp Start') + console.log('IonicApp Start'); - console.log(webview.getName(), webview.is('cordova')) + console.log(engine.getName(), engine.is('cordova')); - webview.ready().then(() => { - console.log('webviewready') - }) + engine.ready().then(() => { + console.log('engine ready') + }); - webview.fullScreen(true).then((isShown) => { + engine.fullScreen(true).then((isShown) => { console.log('fullScreen', isShown) - }) + }); - webview.showStatusBar(true).then((isShown) => { + engine.showStatusBar(true).then((isShown) => { console.log('showStatusBar', isShown) - }) + }); } } -bootstrap(IonicApp) +bootstrap(IonicApp); diff --git a/ionic/webview/cordova/cordova.js b/ionic/engine/cordova/cordova.js similarity index 61% rename from ionic/webview/cordova/cordova.js rename to ionic/engine/cordova/cordova.js index 30eba2c3e4..dd6a41e945 100644 --- a/ionic/webview/cordova/cordova.js +++ b/ionic/engine/cordova/cordova.js @@ -1,32 +1,33 @@ -import {webview} from '../webview' +import {engine} from '../engine'; -webview.register({ + +engine.register({ name: 'cordova', isMatch() { - return !(!window.cordova && !window.PhoneGap && !window.phonegap) + return !(!window.cordova && !window.PhoneGap && !window.phonegap); }, ready() { return new Promise(resolve => { - setTimeout(resolve, 1000) - }) + setTimeout(resolve, 1000); + }); }, fullScreen(shouldShow) { return new Promise(resolve => { setTimeout(function() { - resolve(shouldShow) - }, 1000) - }) + resolve(shouldShow); + }, 1000); + }); }, showStatusBar(shouldShow) { return new Promise(resolve => { setTimeout(function() { - resolve(shouldShow) - }, 1000) - }) + resolve(shouldShow); + }, 1000); + }); }, exitApp() { return new Promise(resolve => { - setTimeout(resolve, 1000) - }) + setTimeout(resolve, 1000); + }); } -}) +}); diff --git a/ionic/engine/electron/electron.js b/ionic/engine/electron/electron.js new file mode 100644 index 0000000000..78040a6994 --- /dev/null +++ b/ionic/engine/electron/electron.js @@ -0,0 +1,37 @@ +import * as util from 'ionic/util'; +import {engine} from '../engine'; + + +engine.register({ + name: 'electron', + isMatch() { + try { + return util.isDefined(process) && util.isDefined(require) && util.isDefined(require('nw.gui')); + } catch (e) {} + return false; + }, + ready() { + return new Promise(resolve => { + setTimeout(resolve, 1000); + }); + }, + fullScreen(shouldShow) { + return new Promise(resolve => { + setTimeout(function() { + resolve(shouldShow); + }, 1000); + }); + }, + showStatusBar(shouldShow) { + return new Promise(resolve => { + setTimeout(function() { + resolve(shouldShow); + }, 1000); + }); + }, + exitApp() { + return new Promise(resolve => { + setTimeout(resolve, 1000); + }); + } +}); diff --git a/ionic/engine/engine.js b/ionic/engine/engine.js new file mode 100644 index 0000000000..5cb07e66d7 --- /dev/null +++ b/ionic/engine/engine.js @@ -0,0 +1,73 @@ +import * as util from 'ionic/util'; + + +let registry = {}; +let defaultEngine; +let activeEngine; + +class EngineController { + + constructor() { + let self = this; + let proxyMethods = 'ready fullScreen showStatusBar exitApp'.split(' '); + for (let x = 0; x < proxyMethods.length; x++) { + this[proxyMethods[x]] = function() { + return self.proxy(proxyMethods[x], arguments); + } + } + } + + proxy(target, args) { + let eng = this.get() + if (eng && eng[target]) { + return eng[target].apply(this, args); + } + return new Promise(resolve => {}, reject => { + reject(); + }); + } + + is(name) { + return this.name === name; + } + + getName() { + return this.get().name; + } + + get() { + if (util.isUndefined(activeEngine)) { + this.set(this.detect()); + } + return activeEngine || defaultEngine; + } + + set(eng) { + activeEngine = eng; + } + + setDefault(eng) { + defaultEngine = eng; + } + + register(eng) { + registry[eng.name] = eng; + } + + detect() { + for (let name in registry) { + if (registry[name].isMatch()) { + return registry[name]; + } + } + return null; + } + +} + +export let engine = new EngineController(); + +engine.setDefault({ + name: 'default', + ready: util.dom.windowLoad +}); diff --git a/ionic/ionic.js b/ionic/ionic.js index d55a80e28b..190ee40d98 100644 --- a/ionic/ionic.js +++ b/ionic/ionic.js @@ -19,8 +19,9 @@ Object.defineProperties(ViewContainer.prototype, { export * from 'ionic/components' export * from 'ionic/platform/platform' export * from 'ionic/routing/router' -export * from 'ionic/webview/webview' -export * from 'ionic/webview/cordova/cordova' -export * from 'ionic/webview/node-webkit/node-webkit' export * from 'ionic/util/focus' export * from 'ionic/collide/animation' + +export * from 'ionic/engine/engine' +export * from 'ionic/engine/cordova/cordova' +export * from 'ionic/engine/electron/electron' diff --git a/ionic/ionic.scss b/ionic/ionic.scss index a2d7d49c57..64f6b02f65 100644 --- a/ionic/ionic.scss +++ b/ionic/ionic.scss @@ -78,7 +78,3 @@ "components/icon/icon"; -// Web View Adaptors -@import - "webview/cordova/cordova", - "webview/node-webkit/node-webkit"; diff --git a/ionic/webview/cordova/cordova.scss b/ionic/webview/cordova/cordova.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ionic/webview/node-webkit/node-webkit.js b/ionic/webview/node-webkit/node-webkit.js deleted file mode 100644 index af131461ac..0000000000 --- a/ionic/webview/node-webkit/node-webkit.js +++ /dev/null @@ -1,28 +0,0 @@ -import {webview} from '../webview' - -webview.register({ - name: 'node-webkit', - isMatch() { - try { - return util.isDefined(process) && util.isDefined(require) && util.isDefined(require('nw.gui')) - } catch (e) {} - return false - }, - ready() { - return new Promise(resolve => { - setTimeout(resolve, 1000) - }) - }, - fullScreen(shouldShow) { - return new Promise(resolve => { - setTimeout(function() { - resolve(shouldShow) - }, 1000) - }) - }, - exitApp() { - return new Promise(resolve => { - setTimeout(resolve, 1000) - }) - } -}) diff --git a/ionic/webview/node-webkit/node-webkit.scss b/ionic/webview/node-webkit/node-webkit.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ionic/webview/webview.js b/ionic/webview/webview.js deleted file mode 100644 index a6299ae373..0000000000 --- a/ionic/webview/webview.js +++ /dev/null @@ -1,89 +0,0 @@ - -import * as util from 'ionic/util' - -class WebView { - constructor(options) { - util.extend(this, options) - } -} - -let registry = {} -let defaultWebView; -let activeWebView; - -class WebViewController { - - constructor() { - let self = this - let proxyMethods = 'ready fullScreen showStatusBar exitApp'.split(' ') - for (let x = 0; x < proxyMethods.length; x++) { - this[proxyMethods[x]] = function() { - return self.proxy(proxyMethods[x], arguments) - } - } - } - - proxy(target, args) { - let webview = this.get() - if (webview && webview[target]) { - return webview[target].apply(this, args) - } - return new Promise(resolve => {}, reject => { - reject() - }) - } - - is(name) { - return this.getName() === name - } - - isWebView() { - return !!this.get().isWebView - } - - getName() { - return this.get().name - } - - get() { - if (util.isUndefined(activeWebView)) { - this.set(this.detect()) - } - return activeWebView || defaultWebView - } - - set(webview) { - activeWebView = webview - } - - setDefault(webview) { - if (!webview instanceof WebView) webview = new WebView(webview) - defaultWebView = webview - } - - register(webview) { - if (!webview instanceof WebView) webview = new WebView(webview) - webview.isWebView = true - registry[webview.name] = webview - } - - detect() { - for (let name in registry) { - if (registry[name].isMatch()) { - return registry[name] - } - } - return null - } - -} - -export let webview = new WebViewController() - - -webview.setDefault({ - name: 'default', - ready: util.dom.windowLoad -}) - -