#选择客户组件测试页面分析
http://192.168.8.23:8001/jstest/js-sdk/tests/contentProvider.html
bootstrap
twiter推出的样式库,页面的alert info用了这个样式库的样式
JS和相关流程
<script>
var ContentProvider = function(element, type, callback){
var _self = this;
var _element = element;
var _callback = callback;
var _type = type;
if(XRKClientAPI){
//do in api context.
XRKClientAPI.do(function(api){
//listen to event
api.on("onReceiveContent", function(res){
if(res && res.type === "customer"){
_callback(res);
}
});
//bind behavior
_element.href = "javascript:void(0);";
_element.addEventListener("click", function(){ // 3、添加元素点击事件
api.openContentProvider(_type, null); // 4、api调起app的openContentProvider方法
return false;
});
//get default content
api.getContent(_type, _callback);
});
}
}
// 1、页面元素动态增加provider属性,
HTMLAnchorElement.prototype.provide = function(type, callback){
return new ContentProvider(this, type, callback);
}
</script>
<script>
$(function(){
// 2、定义页面中的第一个css:myCustomerSelector元素的provide属性
$("#myCustomerSelector").get(0).provide("customer", function(data){
$('#myCurrentCustomer').text(JSON.stringify(data));
});
});
</script>