Coder Social home page Coder Social logo

w3bridge's Introduction

'w3bridge' is iOS framework bridges between native web view and HTML javascript. It provides bridge web view that make the web page looks like native view. This framework control the native web view and included web page each other.

Usage

Implementation of native web view

Inheritance

#import <UIKit/UIKit.h>
#import <w3bridge/w3bridge.h>

@interface ViewController : UIBridgeWebViewController
@end

#import "ViewController.h"

#define URLOfSample @"http://pisces.jdsn.net/w3bridgeDemo/html/w3bridge-sample-main.html"

@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.destination = [NSURL URLWithString:URLOfSample];
}
@end

Composition

#import <UIKit/UIKit.h>
#import <w3bridge/w3bridge.h>

@interface ViewController : UIViewController
@end

#import "ViewController.h"

#define URLOfSample @"http://pisces.jdsn.net/w3bridgeDemo/html/w3bridge-sample-main.html"

@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIBridgeWebViewController *controller = [[UIBridgeWebViewController alloc] init];
    controller.destination = [NSURL URLWithString:URLOfSample];
    
    [self.navigationController pushViewController:controller animated:YES];
}
@end

Implementation of html web page

w3bridge-sample-main.html

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="initial-scale=1,maximum-scale=2,user-scalable=no" />
    <title>w3bridge Sample</title>
    
    <style type="text/css">
    	body {padding:0;margin:0;width:100%;height:100%;}
    	ul {list-style:none;padding:0 0 20px 0;margin:0;}
    	ul li {margin-left:20px;}
    </style>
</head>

<body onload="onBodyLoad();">
<ul>
	<li><button onclick="openAsPush();" style="width:120px;height:30px;margin-top:30px;">open as push</button></li>
	<li><button onclick="openAsPop();" style="width:120px;height:30px;margin-top:30px;">open as pop</button></li>
	<li><button onclick="postNotification();" style="width:120px;height:30px;margin-top:30px;">post notification</button></li>
	<li><button onclick="multiplePopUpView();" style="width:120px;height:30px;margin-top:30px;">multiple popup view</button></li>
	<li><button onclick="openLayerBridgeWebView();" style="width:120px;height:30px;margin-top:30px;">open layer bridge webview</button></li>
</ul>
		
<script type="text/javascript" src="http://pisces.jdsn.net/w3bridgeDemo/w3bridge-1.0.0.min.js"></script>
<script type="text/javascript">
    
    var urlOfP1 = "http://pisces.jdsn.net/w3bridgeDemo/html/w3bridge-sample-p1.html";
    var urlOfLayer = "http://pisces.jdsn.net/w3bridgeDemo/html/w3bridge-sample-layer.html";
	
	//--------------------------------------------------------------------------
	// Methods
	//--------------------------------------------------------------------------
    
    function multiplePopUpView(){
    	navigator.bridge.view.open(urlOfP1, "pop");
    }
    
    function openAsPush(){
    	navigator.bridge.view.open(urlOfP1, "push", {closeEnabled: 0});
    }
    
    function openAsPop(){
    	navigator.bridge.view.open(urlOfP1, "pop");
    }
    
    function openLayerBridgeWebView(){
    	navigator.bridge.view.openLayerBridgeWebView(urlOfLayer, {width: 300, height: 400, modal: 1});
    }
    
    function postNotification(){
    	navigator.bridge.notification.postNotification("init", {});
    }

	//--------------------------------------------------------------------------
	//  Event handlers
	//--------------------------------------------------------------------------
	
	function onBodyLoad(){
		document.addEventListener("deviceready", onDeviceReady, false);
    }

    function onDeviceReady(){
    	debugconsoleTest();
    	externalInterfaceCallTest();
    	externalInterfaceAddCallbackTest();
    	notificationTest();
    }

	//--------------------------------------------------------------------------
	//  Test Functions
	//--------------------------------------------------------------------------
	
	function debugconsoleTest(){
    	console.log(DeviceInfo);
	}

	function externalInterfaceCallTest(){
    	navigator.bridge.externalInterface.call("alert", {message: "mesage", title: "ext call"}, function(result){
    		console.log("result -> " + result);
    	}, function(error){
    		console.log("error -> " + error);
    	});
    	

    	navigator.bridge.externalInterface.call("alert", {message: "mesage", title: "ext call"}, successHandler, function(error){
    		console.log("error -> " + error);
    	});
	}
	
	function successHandler(result)
	{
		console.log("successHandler");
	}
	
	function externalInterfaceAddCallbackTest(){
		navigator.bridge.externalInterface.addCallback("rightBarButtonClick", function(result){
    		console.log("called rightBarButtonClick callback function");
		});
	}

	function notificationTest(){
    	navigator.bridge.notification.addObserver("select", "selectHandler");
    	navigator.bridge.notification.addObserver("viewWillAppear", "viewWillAppear");
    	navigator.bridge.notification.addObserver("viewWillDisappear", "viewWillDisappear");
	}
  
	//--------------------------------------------------------------------------
	//  Callback Functions
	//--------------------------------------------------------------------------

    function selectHandler(){
    	console.log("selectHandler");
    }
    
    function viewWillAppear(){
    	console.log("viewWillAppear");
    }

    function viewWillDisappear(){
    	console.log("viewWillDisappear");
    }
</script>
</body>
</html>

Result

w3bridge's People

Contributors

pisces avatar

Stargazers

 avatar

Watchers

 avatar hika, maeng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.