javascriptイベントモニターモード
3887 ワード
OSDでは配ったことがありません.速度を試してみます.昨日はトレーナーが書いたばかりのものを貼り付けましょう.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>OMP SDK </title>
<script type="text/javascript">
/*
*@description OMP JavaScript SDK , WebApp 。
*@date 2012-12-13
*@wtsoftware
*/
;(function(){
/***
*
*@description SDK , ,
*/
//
var Event=function(name){
this.name=name;
this.listeners=new Array();
}
//
Event.prototype.AddEventFn=function(fn){
this.listeners.push(fn);
}
//
Event.prototype.GetEventName=function(){
return this.name;
}
//
//{data}
Event.prototype.FireEvent=function(data){
for(var key in this.listeners){
this.listeners[key](data);
}
}
//
//{data}
Event.prototype.FireEvent=function(data){
for(var key in this.listeners){
this.listeners[key](data);
}
}
// , 。
var Observer =function(){
this.events=new Array();
}
//
Observer .prototype.RegisterEvent=function(eventName){
e=new Event(eventName);
this.events.push(e);
}
//
Observer .prototype.AddListener=function(eventName,fn){
for(var key in this.events){
if (this.events[key].GetEventName()==eventName)
{
this.events[key].AddEventFn(fn);
return true;
}
}
return false;
}
Observer.prototype.getEventFns=function(eventName){
for(var key in this.events){
if (this.events[key].GetEventName()==eventName)
{
return this.events[key];
}
}
}
/**
*
* @param {} subClass
* @param {} superClass
*/
function extend(subClass, superClass) {
var F=function(){};
F.prototype=superClass.prototype;
subClass.prototype=new F();
subClass.prototype.constructor=subClass;
subClass.superclass=superClass.prototype;
if (superClass.prototype.constructor==Object.prototype.constructor){
superClass.prototype.constructor=superClass;
}
}
//omp SDK
var CmccSdk={};
//
var _locator=CmccSdk.FppLocator=function(){
CmccSdk.FppLocator.superclass.constructor.call(this);
// aclick
this.RegisterEvent('locator');
}
extend(CmccSdk.FppLocator,Observer);
/**
*@method: , 。 Wifi、 、GPS , 。
*
*@ :
*@param fppURL url
*@param appID ID
*@param appkey
*
*/
_locator.prototype.getLocation=function(){
// locator
var event=this.getEventFns("locator");
event.FireEvent({lon:"10001",lat:"3232"});
}
// SDK
window["CmccSdk"]=CmccSdk;
})(window);
</script>
<script>
/*
*@descripton ,
*
**/
function locSuccess(data){
alert("instance1 : :"+data.lon+", :"+data.lat+"");
}
function locSuccess2(data){
alert("instance1 : :"+data.lon+", :"+data.lat+"");
}
function locSucces3(data){
alert("instance2 : :"+data.lon+", :"+data.lat+"");
}
// ,
function exeLoc(){
var locatInstance=new CmccSdk.FppLocator();
locatInstance.AddListener("locator",locSuccess);
locatInstance.AddListener("locator",locSuccess2);
locatInstance.getLocation();
//console.log(locatInstance);
}
// ,
function exeLoc2(){
var locatInstance2=new CmccSdk.FppLocator();
locatInstance2.AddListener("locator",locSucces3);
locatInstance2.getLocation();
//console.log(locatInstance);
}
console.log(Event);
</script>
</head>
<body>
<button onclick="exeLoc()"> </button>
<button onclick="exeLoc2()"> 2</button>
</body>
</html>