Skip to content

Commit

Permalink
在.page 里面的js 会被执行
Browse files Browse the repository at this point in the history
  • Loading branch information
yudong22 committed Oct 31, 2014
1 parent 86fd238 commit 59c1ad9
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 25 deletions.
63 changes: 62 additions & 1 deletion dist/BlendWebUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -11973,6 +11973,55 @@ define(
}
);

define(
'src/common/loader',['require'],function(require) {

/**
* @class blend.loader
* @singleton
* @private
*/

//baidu-async-module,
//这里实现两个方法
//A. 加载页面源js
//B. 页面内嵌js

var loader = {};

var getScript = function(url,cb){
var script = document.createElement('script');
script.setAttribute('src', url);
document.head.appendChild(script);
script.onload = function(){
if(cb){cb(script);}
};
};


loader.getScript = function(layerid,jsarr,callback){
var getscript = 0;
for(var i = 0,len=jsarr.length;i<len;i++){
getScript(jsarr[i],function(){
getscript++;
if (getscript === len){
callback();
}
});
}
};
loader.runScript = function(dom){
if ($("script",dom).length){
$("script",dom).each(function(){
eval($(this).html());
});
}

};

return loader;

});
define(

/**
Expand All @@ -11983,7 +12032,7 @@ define(
* @inheritable
*/

'src/web/Layer.js',['require','../common/lib','./WebControl','./blend','./layer/layerapi'],function (require) {
'src/web/Layer.js',['require','../common/lib','./WebControl','./blend','./layer/layerapi','../common/loader'],function (require) {


var lib = require('../common/lib');
Expand All @@ -11994,6 +12043,7 @@ define(

var lowerAnimate = $("html").hasClass("android");

var loader = require('../common/loader');

/**
* @constructor
Expand Down Expand Up @@ -12141,6 +12191,13 @@ define(
// me.onhide && me.onhide(event);

// });
me.on('onrender',function(event){
var id = event['detail'];
var dom = Blend.ui.get(id).main;

loader.runScript(dom);

});

// me.onshow2 = me.onshow;
me.on('onshow',function(event){
Expand Down Expand Up @@ -12910,6 +12967,10 @@ define('src/web/LayerGroup.js',['require','./blend','../common/lib','./WebContro

me._layers[id].onshow = me.onshow;
}
if (me.onrender) {

me._layers[id].onrender = me.onrender;
}


console.log('start new layer', id, this._layers[id]);
Expand Down
8 changes: 4 additions & 4 deletions dist/BlendWebUI.min.js

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions src/common/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
define(
function(require) {

/**
* @class blend.loader
* @singleton
* @private
*/

//baidu-async-module,
//这里实现两个方法
//A. 加载页面源js
//B. 页面内嵌js

var loader = {};

var getScript = function(url,cb){
var script = document.createElement('script');
script.setAttribute('src', url);
document.head.appendChild(script);
script.onload = function(){
if(cb){cb(script);}
};
};


loader.getScript = function(layerid,jsarr,callback){
var getscript = 0;
for(var i = 0,len=jsarr.length;i<len;i++){
getScript(jsarr[i],function(){
getscript++;
if (getscript === len){
callback();
}
});
}
};
loader.runScript = function(dom){
if ($("script",dom).length){
$("script",dom).each(function(){
eval($(this).html());
});
}

};

return loader;

});
8 changes: 8 additions & 0 deletions src/web/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ define(

var lowerAnimate = $("html").hasClass("android");

var loader = require('../common/loader');

/**
* @constructor
Expand Down Expand Up @@ -166,6 +167,13 @@ define(
// me.onhide && me.onhide(event);

// });
me.on('onrender',function(event){
var id = event['detail'];
var dom = Blend.ui.get(id).main;

loader.runScript(dom);

});

// me.onshow2 = me.onshow;
me.on('onshow',function(event){
Expand Down
16 changes: 16 additions & 0 deletions usecase/item.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@
</ul>
</div>
</div>
<script>
console.log("info page......");
//console.log(blend.get);
var mylayer = blend.get("info");
$("a.back").click(function(e){
console.log("click.... back... out....")
mylayer.out();
return false;
});

$("a.reload").click(function(e){
mylayer.reload("item.html");
// e.preventDefault();
return false;
});
</script>
</div>
</div>

Expand Down
68 changes: 64 additions & 4 deletions usecase/js/BlendWebUI.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
(function () {/**
* @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
*
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/almond for details
*/
Expand Down Expand Up @@ -11509,6 +11507,7 @@ define(
$.ajax({
url: options.url,
type: 'get',
dataType:"html",
success: function(data) {
// console.log("--------",data);
//hybird版本的web页面是带有页头和页尾的,所以,需要进行.page筛选。
Expand Down Expand Up @@ -11974,6 +11973,55 @@ define(
}
);

define(
'src/common/loader',['require'],function(require) {

/**
* @class blend.loader
* @singleton
* @private
*/

//baidu-async-module,
//这里实现两个方法
//A. 加载页面源js
//B. 页面内嵌js

var loader = {};

var getScript = function(url,cb){
var script = document.createElement('script');
script.setAttribute('src', url);
document.head.appendChild(script);
script.onload = function(){
if(cb){cb(script);}
};
};


loader.getScript = function(layerid,jsarr,callback){
var getscript = 0;
for(var i = 0,len=jsarr.length;i<len;i++){
getScript(jsarr[i],function(){
getscript++;
if (getscript === len){
callback();
}
});
}
};
loader.runScript = function(dom){
if ($("script",dom).length){
$("script",dom).each(function(){
eval($(this).html());
});
}

};

return loader;

});
define(

/**
Expand All @@ -11984,7 +12032,7 @@ define(
* @inheritable
*/

'src/web/Layer.js',['require','../common/lib','./WebControl','./blend','./layer/layerapi'],function (require) {
'src/web/Layer.js',['require','../common/lib','./WebControl','./blend','./layer/layerapi','../common/loader'],function (require) {


var lib = require('../common/lib');
Expand All @@ -11995,6 +12043,7 @@ define(

var lowerAnimate = $("html").hasClass("android");

var loader = require('../common/loader');

/**
* @constructor
Expand Down Expand Up @@ -12142,6 +12191,13 @@ define(
// me.onhide && me.onhide(event);

// });
me.on('onrender',function(event){
var id = event['detail'];
var dom = Blend.ui.get(id).main;

loader.runScript(dom);

});

// me.onshow2 = me.onshow;
me.on('onshow',function(event){
Expand Down Expand Up @@ -12911,6 +12967,10 @@ define('src/web/LayerGroup.js',['require','./blend','../common/lib','./WebContro

me._layers[id].onshow = me.onshow;
}
if (me.onrender) {

me._layers[id].onrender = me.onrender;
}


console.log('start new layer', id, this._layers[id]);
Expand Down Expand Up @@ -13174,4 +13234,4 @@ require(['src/web/blend','src/web/dialog/alert','src/web/slider','src/web/Layer.

define("src/web/main", function(){});

}());
}());
33 changes: 17 additions & 16 deletions usecase/js/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

var layer = blend.Layer;

blend.layerInit("info",function(){
console.log("info page......");
//console.log(blend.get);
var mylayer = blend.get("info");
$("a.back").click(function(e){
console.log("click.... back... out....")
mylayer.out();
return false;
});
// blend.layerInit("info",function(){
// console.log("info page......");
// //console.log(blend.get);
// var mylayer = blend.get("info");
// $("a.back").click(function(e){
// console.log("click.... back... out....")
// mylayer.out();
// return false;
// });

$("a.reload").click(function(e){
mylayer.reload("item.html");
// e.preventDefault();
return false;
});
// $("a.reload").click(function(e){
// mylayer.reload("item.html");
// // e.preventDefault();
// return false;
// });

});
// });

blend.layerInit("0",function(){
$(document).click(function(e){
Expand All @@ -28,7 +28,8 @@
// var _layer = window._layer;
var $t = $(e.target).closest('a');
if (!$t.length) return true;

if ($t.attr("href")=='#')return ;
// console.log($t.attr("href"))
e.preventDefault();
window._layer && window._layer.destroy();
window._layer = new layer({
Expand Down

0 comments on commit 59c1ad9

Please sign in to comment.