wip webview core

This commit is contained in:
Adam Bradley
2015-04-20 23:58:37 -05:00
parent 86e17b59c0
commit 25adc1d1f8
6 changed files with 107 additions and 5 deletions

View File

@ -1,6 +1,7 @@
import {bootstrap} from 'angular2/core'; import {bootstrap} from 'angular2/core';
import {Component, Template} from 'angular2/angular2'; import {Component, Template} from 'angular2/angular2';
import {View, Tabs, Tab} from 'ionic2/components'; import {View, Tabs, Tab} from 'ionic2/components';
import {webview} from 'ionic2/webview/webview'
@Component({ selector: '[ion-app]' }) @Component({ selector: '[ion-app]' })
@ -11,7 +12,11 @@ import {View, Tabs, Tab} from 'ionic2/components';
class IonicApp { class IonicApp {
constructor() { constructor() {
console.log('IonicApp Start') console.log('IonicApp Start')
console.log(webview.name, webview.isWebView)
} }
} }
bootstrap(IonicApp) bootstrap(IonicApp)

View File

@ -1,2 +1,4 @@
export * from 'ionic2/components' export * from 'ionic2/components'
export * from 'ionic2/platform/platform'
export * from 'ionic2/webview/webview'

View File

View File

@ -21,6 +21,7 @@ class PlatformController {
get() { get() {
return this.current return this.current
} }
getName() { getName() {
return this.current && this.current.name return this.current && this.current.name
} }
@ -43,7 +44,7 @@ class PlatformController {
detect() { detect() {
for (let name in this.registry) { for (let name in this.registry) {
if (this.registry[name].matcher()) { if (this.registry[name].isMatch()) {
return this.registry[name] return this.registry[name]
} }
} }
@ -59,14 +60,13 @@ var ua = window.navigator.userAgent
// TODO(ajoslin): move these to their own files // TODO(ajoslin): move these to their own files
platform.register({ platform.register({
name: 'android', name: 'android',
matcher() { isMatch() {
return queryPlatform == 'android' || /android/i.test(ua) return queryPlatform == 'android' || /android/i.test(ua)
} }
}) })
platform.register({ platform.register({
name: 'ios', name: 'ios',
// For now always default to ios isMatch() {
matcher() {
return queryPlatform === 'ios' || /ipad|iphone|ipod/i.test(ua) return queryPlatform === 'ios' || /ipad|iphone|ipod/i.test(ua)
} }
}) })

View File

@ -30,7 +30,8 @@ export function defaults(dest) {
export const isString = val => typeof val === 'string' export const isString = val => typeof val === 'string'
export const isFunction = val => typeof val === 'function' export const isFunction = val => typeof val === 'function'
export const isDefined = val => typeof val === 'undefined' export const isDefined = val => typeof val !== 'undefined'
export const isUndefined = val => typeof val === 'undefined'
export const isObject = val => typeof val === 'object' export const isObject = val => typeof val === 'object'
export const isArray = Array.isArray export const isArray = Array.isArray

View File

@ -22,3 +22,97 @@
// webview: returns cordova, trigger.io, browser // webview: returns cordova, trigger.io, browser
// isWebview: true if its cordova, trigger. False if its browser // isWebview: true if its cordova, trigger. False if its browser
import * as util from 'ionic2/util'
class WebView {
constructor(options) {
util.extend(this, options)
}
}
let registry = {}
class WebViewController {
current: WebView;
constructor() {
let defaultProperties = {
name: null,
isWebView: false
}
for (let target in defaultProperties) {
this.__defineGetter__(target, () => {
return this.proxy(target, null, defaultProperties[target])
})
}
let defaultMethods = {
exitApp: util.noop,
showStatusBar: util.noop,
fullScreen: util.noop
}
for (let target in defaultMethods) {
this[target] = () => {
return this.proxy(target, null, defaultMethods[target])
}
}
}
get() {
if (util.isUndefined(this.current)) {
this.set(this.detect())
}
return this.current
}
set(webview) {
this.current = webview
}
detect() {
for (let name in registry) {
if (registry[name].isMatch()) {
return registry[name]
}
}
return null
}
proxy(target, args, fallback) {
let webview = this.get()
if (webview && webview[target]) {
if (util.isFunction(webview[target])) {
return webview[target].apply(this, args)
}
return webview[target]
}
return fallback
}
register(webview) {
if (!webview instanceof WebView) webview = new WebView(webview)
registry[webview.name] = webview
}
}
export let webview = new WebViewController()
webview.register({
name: 'cordova',
isMatch() {
return true;//util.isDefined(window.cordova)
}
})
webview.register({
name: 'node-webkit',
isMatch() {
// if (util.isDefined(process) && util.isDefined(require)) {
// try {
// return util.isDefined(require('nw.gui'));
// } catch (e) {}
// }
return false
}
})