portal.js
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
define([
'fastclick',
'mobilebone',
'utils',
'portal/classify',
'portal/list',
'portal/detail',
'portal/comment'
], function (FastClick, Mobilebone, _u) {
var pclassify = require("portal/classify");
var plist = require("portal/list");
var pdetail = require('portal/detail');
var pcomment = require('portal/comment');
var currPageId = "";
var root = {
initClassify: pclassify.init,
initList: function (pageInto, pageOut, options, back) {
if(back) return;
plist.init();
},
initDetail: function(pageInto, pageOut, options, back){
if(back && pcomment.isSend()) { // 发送完评论, 只刷新评论列表
return pdetail.renderComment();
}
pdetail.init(options.formdata, back);
},
initComment: pcomment.init,
resetComment: function(pageInto, pageOut, options) {
pcomment.reset(options.formdata);
}
};
FastClick.attach(document.body);
Mobilebone.rootTransition = root;
Mobilebone.callback = function(pageIn, pageout, opts, back) {
currPageId = pageIn.id;
_u.showBackBtn(back);
};
Mobilebone.init();
$("body").on("click.tab", ".tab", _u.toggleTab);
$("body").on("click", ".switch", function() {
var $switch = $(this);
var inuse = $(this).hasClass("switch-checked") ? 1 : 0, appid;
var deferreds = [];
$switch.toggleClass("switch-checked");
if(currPageId == "page-detail") {
deferreds.push(pdetail.toggleSwitch(inuse));
appid = pdetail.getAppid();
}
deferreds.push( plist.toggleSwitch(appid || this, inuse) );
$.when.apply(null, deferreds)
.then(function() {
pclassify.init();
});
return false; // 阻止mobilebone的a标签点击事件
});
});