Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
fix issue #22 #23 #24 #25 #26
Browse files Browse the repository at this point in the history
  • Loading branch information
MerrickZ committed Jan 16, 2014
1 parent 5fe1811 commit 63a629b
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 122 deletions.
19 changes: 11 additions & 8 deletions src/www/calendar.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<div data-bb-type="screen" data-bb-indicator="true">
<div data-bb-type="round-panel">
<div data-bb-type="panel-header">可阅读的内容</div>
</div>
<div id="historyList" data-bb-type="image-list" data-bb-images="none" data-bb-style="arrowlist">
</div>
<div data-bb-type="screen">
<div data-bb-type="round-panel">
<div data-bb-type="panel-header">可阅读的内容</div>
</div>

<div id="spinner-4" class="center" data-bb-type="activity-indicator" data-bb-size="medium"></div>

<div id="historyList" data-bb-type="image-list" data-bb-images="none" data-bb-style="arrowlist">
</div>

<div data-bb-type="action-bar" data-bb-back-caption="返回">
</div>
<div data-bb-type="action-bar" data-bb-back-caption="返回">
</div>
</div>
2 changes: 1 addition & 1 deletion src/www/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="false" />
<preference name="WebSecurity" value="disable"/>
<preference name="AutoHideSplashScreen" value="false" />
<preference name="AutoHideSplashScreen" value="true" />

<rim:splash src="img/splash-1280x768.png"/>
<rim:splash src="img/splash-1280x720.png"/>
Expand Down
2 changes: 2 additions & 0 deletions src/www/css/one.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.center { margin: 0px auto 0px auto;}

1 change: 1 addition & 0 deletions src/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="css/bbui-min.css" />
<link rel="stylesheet" type="text/css" href="css/one.css" />
<title>One</title>
</head>
<body>
Expand Down
163 changes: 85 additions & 78 deletions src/www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ var app = {
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
//app.checkPlugin();
navigator.splashscreen.show();
try {
localStorage.removeItem('show');
} catch (e) {
}
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
Expand Down Expand Up @@ -65,12 +68,10 @@ var app = {
// 在DOM显示之后的配置
config.ondomready = function(element, id, params) {
if (id === 'showCalendar') {
loadAvailableMags(element, id);
loadAvailableMagsAsync(element);
}
if (id === 'menu') {
loadContent(element, id);


}
};

Expand All @@ -81,7 +82,6 @@ var app = {
document.body.style['background-color'] = darkScreenColor;
document.body.style['color'] = '#E6E6E6';
}
navigator.splashscreen.hide();
bb.pushScreen('main.html', 'menu');
}
};
Expand Down Expand Up @@ -137,93 +137,91 @@ function refreshTheme() {
window.location.reload();
}
}
;

function loadAvailableMags(element, id) {
/*
* 显示所有可看的杂志,包括缓存的和可下载的。
*/
var historylist = gg(element, "historyList");

var cached = findCachedMags();
var available = findAvailableMags();
/*
* 数据格式: {title:328,strdate:2013-01-01}
*/
var data;
if (available) {
data = removeDuplicatesInPlace(cached.concat(available)).sort(function(a, b) {
if (a["strdate"] > b["strdate"]) {
return -1;
} else if (a["strdate"] === b["strdate"]) {
return 0;
function loadAvailableMagsAsync(element) {
findCachedMagsAsync(function(cached) {
findAvailableMagsAsync(function(available) {
gg(element, 'spinner-4').hide();
var historylist = gg(element, "historyList");
var data;
if (available) {
data = removeDuplicatesInPlace(cached.concat(available)).sort(function(a, b) {
if (a["strdate"] > b["strdate"]) {
return -1;
} else if (a["strdate"] === b["strdate"]) {
return 0;
} else {
return 1;
}
});
} else {
return 1;
data = cached;
}
var items = [];
var item;
for (var i = 0; i < data.length; i++) {
item = document.createElement('div');
item.setAttribute('data-bb-type', 'item');
item.setAttribute('data-bb-title', data[i]["strdate"] + " : " + data[i]["title"]);
item.setAttribute('data-mrk-date', data[i]["strdate"]);
item.innerHTML = data[i]["status"];
item.onclick = function() {
displaySelected();
};
items.push(item);
}
historylist.refresh(items);
});
} else {
data = cached;
}
var items = [];
var item;
for (var i = 0; i < data.length; i++) {
item = document.createElement('div');
item.setAttribute('data-bb-type', 'item');
item.setAttribute('data-bb-title', data[i]["strdate"] + " : " + data[i]["title"]);
item.setAttribute('data-mrk-date', data[i]["strdate"]);
item.innerHTML = data[i]["status"];
item.onclick = function() {
displaySelected();
};
items.push(item);
}
historylist.refresh(items);
});

}
;

function findCachedMags() {
function findCachedMagsAsync(callback) {
/*
* 查找已缓存的杂志,根据本地存储中的2222-22-22title判断。
* 返回数据格式: {title:328,strdate:2013-01-01}
* 本地存储数据格式: 2014-01-08ask / 2014-01-18one / 2014-01-18home
*/
setTimeout(function() {

var data = [];
var itemkey;
var reg = /^\d{4}-\d{2}-\d{2}title$/i;
var data = [];
var itemkey;
var reg = /^\d{4}-\d{2}-\d{2}title$/i;


for (var i = 0; i < localStorage.length; i++) {
itemkey = localStorage.key(i);
if (reg.test(itemkey)) {
var itemdata = {};
itemdata["title"] = localStorage.getItem(itemkey);
itemdata["strdate"] = itemkey.substr(0, 10);
itemdata["status"] = "已缓存";
data.push(itemdata);
for (var i = 0; i < localStorage.length; i++) {
itemkey = localStorage.key(i);
if (reg.test(itemkey)) {
var itemdata = {};
itemdata["title"] = localStorage.getItem(itemkey);
itemdata["strdate"] = itemkey.substr(0, 10);
itemdata["status"] = "已缓存";
data.push(itemdata);
}
}
}
return data;
callback(data);
}, 0);

}

function findAvailableMags() {
/*
* 查找可下载的杂志
*/
var result = [];

var data = one.getHpAdMultiinfo();
if (data && (data["result"] === "SUCCESS")) {
var hplist = data["hpAdMulitEntity"]["lstEntHp"];
for (var i = 0; i < hplist.length; i++) {
var dataitem = {};
dataitem["title"] = hplist[i]["strHpTitle"];
dataitem["strdate"] = hplist[i]["strMarketTime"];
dataitem["status"] = "可下载";
result.push(dataitem);
function findAvailableMagsAsync(callback) {

one.getHpAdMultiInfoAsync(function(data) {
var result = [];
if (data && (data["result"] === "SUCCESS")) {
var hplist = data["hpAdMulitEntity"]["lstEntHp"];
for (var i = 0; i < hplist.length; i++) {
var dataitem = {};
dataitem["title"] = hplist[i]["strHpTitle"];
dataitem["strdate"] = hplist[i]["strMarketTime"];
dataitem["status"] = "可下载";
result.push(dataitem);
}
callback(result);
}
}
return result;
})

}

function displaySelected() {
Expand All @@ -233,7 +231,7 @@ function displaySelected() {
var selected = g('historyList').selected;
console.log(selected.getAttribute("data-mrk-date"));
currentdisplaydate = selected.getAttribute("data-mrk-date");
sessionStorage.setItem('show', currentdisplaydate);
localStorage.setItem('show', currentdisplaydate);
oneloaded = false;
homeloaded = false;
qloaded = false;
Expand Down Expand Up @@ -272,12 +270,12 @@ function getJSON(URL) {
function loadContent(element, id) {
//载入内容,strdate是要显示的日期,此处显示当前日期。
if (!currentdisplaydate) {
if (sessionStorage.getItem('show')) {
if (localStorage.getItem('show')) {
currentdisplaydate = localStorage.getItem('show');
} else {
var d = new Date();
currentdisplaydate = d.format('yyyy-MM-dd');
sessionStorage.setItem('show', currentdisplaydate);
localStorage.setItem('show', currentdisplaydate);
}
}

Expand Down Expand Up @@ -326,7 +324,7 @@ function loadhome(element, strdate) {
console.log("设置图片:" + u);
g('home-img').src = u;
});
})
});
}
var homeloaded, oneloaded, qloaded, imgurl;
function removeChildNodes(node) {
Expand Down Expand Up @@ -428,6 +426,15 @@ function saveFont(f) {
localStorage.setItem("fontsize", size);
}

function tabswitcher(){
function tabswitcher() {
//滚动时自动激活对应的TAB
var ruler = g('home').parentNode.parentNode;
if (ruler.scrollTop < g('content').offsetTop) {
bb.actionBar.highlightAction(g('a1'));
} else if (ruler.scrollTop < g('ask').offsetTop)
{
bb.actionBar.highlightAction(g('a2'));
} else {
bb.actionBar.highlightAction(g('a3'));
}
}
59 changes: 31 additions & 28 deletions src/www/js/one.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
} catch (e) {
callback(null);
}
}, 1);
}, 0);
},
getHpAdMultiinfo: function() {
//获取5天的广告与首页数据
Expand Down Expand Up @@ -143,15 +143,16 @@
},
getHomePageAsync: function(datestr, callback) {
// getJSONAsync: function(strdate, type, url, callback)
this.getJSONAsync(datestr, 'home', 'http://211.152.49.184:7001/OneForWeb/one/getHpinfo?strDate=' + datestr, function(u) {
try {
var cp = getJSON(u);
callback(cp);
} catch (e) {
console.log(e);
callback(null);
}
})
setTimeout(
this.getJSONAsync(datestr, 'home', 'http://211.152.49.184:7001/OneForWeb/one/getHpinfo?strDate=' + datestr, function(u) {
try {
var cp = getJSON(u);
callback(cp);
} catch (e) {
console.log(e);
callback(null);
}
}), 0);
},
getHomePage: function(datestr) {
/*
Expand Down Expand Up @@ -182,15 +183,16 @@
},
getOneContentInfoAsync: function(datestr, callback) {
// getJSONAsync: function(strdate, type, url, callback)
this.getJSONAsync(datestr, 'content', 'http://211.152.49.184:7001/OneForWeb/one/getOneContentInfo?strDate=' + datestr, function(u) {
try {
var cp = getJSON(u);
callback(cp);
} catch (e) {
console.log(e);
callback(null);
}
})
setTimeout(
this.getJSONAsync(datestr, 'content', 'http://211.152.49.184:7001/OneForWeb/one/getOneContentInfo?strDate=' + datestr, function(u) {
try {
var cp = getJSON(u);
callback(cp);
} catch (e) {
console.log(e);
callback(null);
}
}), 0);
},
getOneContentInfo: function(datestr) {
/*
Expand Down Expand Up @@ -225,15 +227,16 @@
},
getOneQuestionInfoAsync: function(datestr, callback) {
// getJSONAsync: function(strdate, type, url, callback)
this.getJSONAsync(datestr, 'question', 'http://211.152.49.184:7001/OneForWeb/one/getOneQuestionInfo?strDate=' + datestr, function(u) {
try {
var cp = getJSON(u);
callback(cp);
} catch (e) {
console.log(e);
callback(null);
}
})
setTimeout(
this.getJSONAsync(datestr, 'question', 'http://211.152.49.184:7001/OneForWeb/one/getOneQuestionInfo?strDate=' + datestr, function(u) {
try {
var cp = getJSON(u);
callback(cp);
} catch (e) {
console.log(e);
callback(null);
}
}), 0);
},
getOneQuestionInfo: function(datestr) {
/*
Expand Down
Loading

0 comments on commit 63a629b

Please sign in to comment.