Files
youfang-app/fangija-zsyf/plus/njs.html
T
尹吉欢 ed180d40a5 add code
2018-03-13 10:16:16 +08:00

156 lines
5.2 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="HandheldFriendly" content="true"/>
<meta name="MobileOptimized" content="320"/>
<title>Hello H5+</title>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript">
// 保存iOS平台导入的类对象
var UIAlertView=null;
// 保存Android导入对象和全局环境对象
var AlertDialog=null,mainActivity=null;
// H5 plus事件处理
function plusReady(){
switch ( plus.os.name ) {
case "Android":
// 程序全局环境对象
mainActivity = plus.android.runtimeMainActivity();
// 导入AlertDialog类
AlertDialog = plus.android.importClass("android.app.AlertDialog");
break;
case "iOS":
// 导入UIAlertView类
UIAlertView = plus.ios.importClass("UIAlertView");
break;
default:
break;
}
}
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}
/**
* 在iOS平台通过NJS显示系统提示框
*/
function njsAlertForiOS(){
/*
* Objective-C 代码
*
  // 创建UIAlertView类的实例对象
  UIAlertView *view = [UIAlertView alloc];
  // 设置提示对话上的内容
  [view initWithTitle:@"自定义标题" // 提示框标题
   message:@"使用NJS的原生弹出框,可自定义弹出框的标题、按钮" // 提示框上显示的内容
   delegate:nil // 点击提示框后的通知代理对象,nil类似js的null,意为不设置
   cancelButtonTitle:@"确定(或者其他字符)" // 提示框上取消按钮的文字
   otherButtonTitles:nil]; // 提示框上其它按钮的文字,设置为nil表示不显示
  // 调用show方法显示提示对话框,在OC中使用[]语法调用对象的方法
  [view show];
*/
// 创建UIAlertView类的实例对象
var view = new UIAlertView();
// 设置提示对话上的内容
view.initWithTitlemessagedelegatecancelButtonTitleotherButtonTitles("自定义标题" // 提示框标题
, "使用NJS的原生弹出框,可自定义弹出框的标题、按钮" // 提示框上显示的内容
, null // 操作提示框后的通知代理对象,暂不设置
, "确定(或者其他字符)" // 提示框上取消按钮的文字
, null ); // 提示框上其它按钮的文字,设置为null表示不显示
// 调用show方法显示提示对话框
view.show();
}
/**
* 在Android平台通过NJS显示系统提示框
*/
function njsAlertForAndroid(){
/*
* Android平台 java代码
*
// 创建提示框构造对象,Builder是AlertDialog的内部类。参数this指代Android的主Activity对象,该对象启动应用时自动生成
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
// 设置提示框标题
dlg.setTitle("自定义标题");
// 设置提示框内容
dlg.setMessage("使用NJS的原生弹出框,可自定义弹出框的标题、按钮");
// 设置提示框按钮
dlg.setPositiveButton("确定(或者其他字符)", null);
// 显示提示框
dlg.show();
*/
// 创建提示框构造对象,构造函数需要提供程序全局环境对象,通过plus.android.runtimeMainActivity()方法获取
var dlg = new AlertDialog.Builder(mainActivity);
// 设置提示框标题
dlg.setTitle("自定义标题");
// 设置提示框内容
dlg.setMessage("使用NJS的原生弹出框,可自定义弹出框的标题、按钮");
// 设置提示框按钮
dlg.setPositiveButton("确定(或者其他字符)",null);
// 显示提示框
dlg.show();
}
function showNjsView(){
switch ( plus.os.name ) {
case "Android":
njsAlertForAndroid();
break;
case "iOS":
njsAlertForiOS();
break;
default:
alert( "此平台不支持!" );
break;
}
}
function gamecenter(){
if ( 'iOS' == plus.os.name ) {
clicked('njs_ios_gamecenter.html',true);
}else{
plus.nativeUI.alert( "此平台不支持!" );
}
}
function shortcut(){
if ( 'Android' == plus.os.name ) {
clicked('njs_android_shortcut.html',true);
}else{
plus.nativeUI.alert( "此平台不支持!" );
}
}
</script>
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
<style type="text/css">
</style>
</head>
<body>
<header id="header">
<div class="nvbt iback" onclick="back(true)"></div>
<div class="nvtt">Native.JS</div>
<div class="nvbt idoc" onclick="openDoc('Native.JS Document','/doc/native.js.html')"></div>
</header>
<div id="dcontent" class="dcontent">
<br/>
<!--div class="button" onclick="gamecenter()">Game Center</div>
<div class="button" onclick="shortcut()">Shortcut</div>
<br/-->
<ul class="dlist">
<li class="ditem" onclick="showNjsView()">native.js调用系统提示框</li>
<li class="ditem" onclick="clicked('njs_efficient.html')">native.js高级API</li>
</ul>
<br/>
<div class="button button-waring" onclick="plus.runtime.openURL('http://ask.dcloud.net.cn/article/114')">更多示例...</div>
</div>
<div id="output">
Native.JS一种把操作系统的原生对象转义,映射为JS对象,在JS里编写原生代码的技术。可通过plus.android.*和plus.ios.*提供的API分别调用Android和iOS平台的Native API。
</div>
</body>
<script type="text/javascript" src="../js/immersed.js" ></script>
</html>