diff --git a/www/index.html b/www/index.html
index 5c9b816..9e1f495 100644
--- a/www/index.html
+++ b/www/index.html
@@ -44,6 +44,7 @@
+
@@ -262,17 +263,12 @@
-
+
-
-
-
Questa voce è nuova ed è disponibile online. Aggiorna ora gli articoli locali della tua app:
-
-
diff --git a/www/js/main.js b/www/js/main.js
index 41eb362..d9dec80 100644
--- a/www/js/main.js
+++ b/www/js/main.js
@@ -133,14 +133,6 @@ $(function () {
});
});
-function benvenuta() {
- $("#benvenuta").popup("open");
-}
-
-//function aggiornaora() {
-// $("#aggiornaora").popup("open");
-//};
-
function initMainPage() {
if (checkConnection()) {
postsUpdate(FONTE.categories.info);
@@ -167,7 +159,7 @@ $(document).on("mobileinit", function () {
$(document).on("pagecontainerchange", function () {
var current = $(".ui-page-active").prop("id"); // Remove active class from nav buttons
- if(current == 'about' || current == 'info' || current == 'ilove' || current == 'events'){
+ if(current == 'about' || current == 'info' || current == 'ilove' || current == 'events' || current == 'cerca'){
$("#navfooter").addClass("hide");
} else {
$("#navfooter").removeClass("hide");
@@ -243,6 +235,7 @@ function onDeviceReady() {
$("[data-role='navbar']").navbar();
//Non uso pageContent per non lanciare 2 volte il recupero dei dati da internet
+ //per la pagina principale
$("#navheader").removeClass("hide");
$("#navfooter").addClass("hide");
}
@@ -269,6 +262,10 @@ function postInList() {
//SCRITTURA
$("body").on('click', '.listevoci li > a', function (event) {
// console.log("HUU_post in list");
+ if($(this).attr("rel") === 'external') {
+ return true;
+ }
+
var idOra = $(this).attr("data-post");
var _class = $(this).attr("class");
$("#titolosingle").empty();
@@ -287,52 +284,6 @@ function postInList() {
});
}
-function cercaMe() {
- var input_text = $("input.cerca").val();
- input_text = encodeURIComponent(input_text);
- var jsonurl = weburl + "wp-json/wp/v2/posts?per_page=10&search=" + input_text + "";
- $(".listresult").empty();
- $("body").pagecontainer("change", "#ricerca");
- $.mobile.loading('show');
-
- var lastUpdate = window.localStorage.getItem('db_update_date');
- if (lastUpdate) {
- var lastUpdateDate = Date.parse(lastUpdate);
-
- $.ajax({
- dataType: "json",
- url: jsonurl,
- success: function (data) {
- var items = [];
- $.each(data, function (key, val) {
- var id = val.id;
- var time = val.modified;
- var title = val.title.rendered;
- var url = val.guid.rendered;
- var tag = data.tags;
- var splitTime = time.split("T");
- var cleanTime = splitTime[0];
- var dTime = new Date(time);
- if (dTime.getTime() <= lastUpdateDate) {
- //key mi dice l'indice'
- items.push("
" + title + " " + cleanTime + " ");
- } else {
- items.push("
" + title + " " + cleanTime + "
");
- }
- });
- $("
", {
- "class": "my-new-list",
- html: items.join("")
- }).prependTo(".listresult");
- $.mobile.loading('hide');
- },
- error: JSONErrorHandler
- });
- } else {
- toastr.error('Err: ERR_NOUPDATE');
- }
-}
-
function findImg(htmlString) {
var pos = htmlString.indexOf('
" + title + " " + cleanTime + " " + tag + " |");
}
else {*/
- items.push("
" + title + " " + cleanTime + " ");
-
+ items.push(getLiPost(id, title, cleanTime));
}
$("
", {
"class": "my-new-list",
html: items.join("")
}).prependTo(div);
+ $.mobile.loading('hide');
});
- $.mobile.loading('hide');
}
+var getLiPostNotPresent = function(id, title, cleanTime, url, style){
+ //TODO:var onclick = " onclick='"+getWpPost()+ "' ";
+ var li = "
"+
+ "" +
+ title +
+ " "+
+ " "+
+ "" + cleanTime + " "+
+ " "+
+ " ";
+
+ return li;
+};
+
+var getLiPost = function(id, title, cleanTime){
+ var li = "
"+
+ "" +
+ title +
+ " "+
+ " "+
+ "" + cleanTime + " "+
+ " "+
+ " ";
+
+ return li;
+};
+
var drawListPost = function(div, resultSet, position) {
var items = [];
for (var i = 0; i < resultSet.rows.length; i++) {
@@ -46,16 +71,7 @@ var drawListPost = function(div, resultSet, position) {
var url = val.guid.rendered;
var cleanTime = EVENTS.formatDate(date, EVENTS.dateFormat.display.date);
- var li = "
"+
- "" +
- title +
- " "+
- " "+
- "" + cleanTime + " "+
- " "+
- " ";
-
- items.push(li);
+ items.push(getLiPost(id, title, cleanTime));
}
var ul = $("
", {
@@ -102,6 +118,7 @@ function drawNoPostsFound(div) {
}
function sqlErrHandler(error){
+ $.mobile.loading('hide');
console.log(error.message);
}
@@ -128,6 +145,8 @@ POST.sql = {
end : "ORDER BY date COLLATE NOCASE DESC LIMIT ?"
};
+POST.table = "xm24_posts";
+
var selectLastNews = function(div, categories) {
var catsWhere = getCategoryWhere(categories);
@@ -235,6 +254,21 @@ function myJsonCategoryPaginated(Qcategory, div, pageNumber) {
$.mobile.loading('hide');
}
+var renderShareButton = function(div_content, title, url, content){
+ $('.share-btn').remove();
+
+ content = content || '';
+
+ var shareButton = $('
', {
+ class : "share-btn ui-btn ui-shadow ui-corner-all",
+ text: "Condividi"
+ }).click(function(){
+ shareMeNow(title, content, url);
+ });
+
+ $(div_content).after(shareButton);
+};
+
function drawPost(div_title, div_content, resultSet){
for (var i = 0; i < resultSet.rows.length; i++) {
var val = JSON.parse(resultSet.rows.item(i).post);
@@ -247,17 +281,8 @@ function drawPost(div_title, div_content, resultSet){
content = findImg(content);
$(div_title).html(title);
-
- var shareButton = $('', {
- class : "share-btn ui-btn ui-shadow ui-corner-all",
- text: "Condividi"
- }).click(function(){
- shareMeNow(title, '',url);
- });
-
- $('.share-btn').remove();
$(div_content).html("" + content + "
");
- $(div_content).after(shareButton);
+ renderShareButton(div_content, title, url, '');
}
}
@@ -274,22 +299,13 @@ function drawEvent(div_title, div_content, resultSet){
var geo = val.geo;
$(div_title).html(title);
-
- var shareButton = $('', {
- class : "share-btn ui-btn ui-shadow ui-corner-all",
- text: "Condividi"
- }).click(function(){
- shareMeNow(title, evInitDate + " "+ evEndDate, url);
- });
-
- $('.share-btn').remove();
$(div_content).html("" + evInitDate +"-" + evEndDate +" " + content + "
");
- $(div_content).after(shareButton);
+ renderShareButton(div_content, title, url, evInitDate + " "+ evEndDate);
}
}
function myJsonPost(Qid, div_title, div_content, _class) {
- var table = "xm24_posts";
+ var table = POST.table;
if(_class){
table = EVENTS.table.single;
}
@@ -300,9 +316,7 @@ function myJsonPost(Qid, div_title, div_content, _class) {
} else {
drawEvent(div_title, div_content, resultSet);
}
- }, function (error) {
- console.log(error);
- });
+ }, sqlErrHandler);
}
function myJsonPage(Qid, div_title, div_content) {
@@ -317,7 +331,6 @@ function myJsonPage(Qid, div_title, div_content) {
var content = data.page;
content = findImg(content);
$(div_title).html(title);
- //key mi dice l'indice'
$(div_content).html("" + content + "
");
}
});
diff --git a/www/js/search.js b/www/js/search.js
new file mode 100644
index 0000000..c1178c3
--- /dev/null
+++ b/www/js/search.js
@@ -0,0 +1,89 @@
+var renderSearched = function(items, input_text){
+ var len = items.length;
+
+ //Forzo la chiusura del pannello che oogni tanto rimane aperto
+ $( "#outside" ).panel( "close" );
+
+ var htmlItems = items.join("");
+ var container = "";
+ if(len === 0) {
+ container = "";
+ htmlItems = "Non sono stati trovati articoli per la ricerca: " + input_text + ". ";
+ }
+
+ $(container, {
+ html: htmlItems
+ }).prependTo(".listresult");
+
+ $.mobile.loading('hide');
+
+ //In caso non ci sia contenuto lo scrivo già nel content,
+ // non c'è bisogno anche del toaster
+ if(len > 0)
+ toastr.info('Trovati ' + items.length + ' articoli.');
+};
+
+function searchWpPosts() {
+ var table = POST.table;
+
+ var input_text = $("input.cerca").val();
+ input_text = encodeURIComponent(input_text);
+ var jsonurl = weburl + REST_PARAMS.posts + REST_PARAMS.per_page + "&search=" + input_text + "";
+ $(".listresult").empty();
+ $("body").pagecontainer("change", "#cerca");
+
+ $.mobile.loading('show');
+ $.ajax({
+ dataType: "json",
+ url: jsonurl,
+ success: function (data) {
+ var items = [];
+ var n_error = 0;
+ FONTE.updatedPostsCount = 0;
+ FONTE.neededPostsCount = data.length;
+
+ if(FONTE.neededPostsCount === 0) {
+ renderSearched(items, input_text);
+ return false;
+ }
+
+ $.each(data, function (key, val) {
+ var id = val.id;
+ var date = val.date;
+ var title = val.title.rendered;
+ var tag = data.tags;
+ var cleanTime = EVENTS.formatDate(date, EVENTS.dateFormat.display.date);
+
+ FONTE.dbHandler.executeSql("SELECT * FROM " + table + " WHERE id = ?;", [id], function(resultSet) {
+ FONTE.updatedPostsCount++;
+ if(resultSet.rows.length > 0) {
+ items.push(getLiPost(id, title, cleanTime));
+ } else {
+ items.push(getLiPostNotPresent(id, title, cleanTime, val.link, 'color:#666;'));
+ }
+
+ if (n_error + FONTE.updatedPostsCount >= FONTE.neededPostsCount) {
+ renderSearched(items, input_text);
+ }
+ }, function (error) {
+ n_error++;
+ if (n_error + FONTE.updatedPostsCount >= FONTE.neededPostsCount && FONTE.updatedPostsCount > 0 ) {
+ renderSearched(items, input_text);
+ }
+ });
+ });
+ },
+
+ error: JSONErrorHandler
+ });
+}
+
+function cerca() {
+ var ret = checkConnection('ERR_CERCA');
+
+ if (ret) {
+ searchWpPosts();
+ }
+
+ return ret;
+}
\ No newline at end of file
diff --git a/www/js/update.js b/www/js/update.js
index 291d80a..2c9f5d0 100644
--- a/www/js/update.js
+++ b/www/js/update.js
@@ -1,9 +1,12 @@
var REST_PARAMS = REST_PARAMS || {};
+REST_PARAMS.api = "wp-json/wp/v2";
+REST_PARAMS.posts = REST_PARAMS.api + "/posts?";
+REST_PARAMS.pages = REST_PARAMS.api + "/pages?";
REST_PARAMS.max_page = 10;
REST_PARAMS.per_page = 'per_page=' + REST_PARAMS.max_page;
function aggiornaPages() {
- var jsonurl = weburl + "wp-json/wp/v2/pages/";
+ var jsonurl = weburl + REST_PARAMS.pages;
$.ajax({
dataType: "json",
url: jsonurl,
@@ -29,7 +32,7 @@ function aggiornaSingleCategory(category) {
//resetta la variabile d'errore per le chiamate ajax asincrone
FONTE.ajaxError = false;
- var jsonurl = weburl + "wp-json/wp/v2/posts?" + REST_PARAMS.per_page;
+ var jsonurl = weburl + REST_PARAMS.posts + REST_PARAMS.per_page;
var storage = window.localStorage;
var lastUpdate = storage.getItem('db_update_date');
@@ -38,10 +41,6 @@ function aggiornaSingleCategory(category) {
getSinglePageRecur(jsonurl, category, 1);
}
-function aggiornaora() {
- $("#aggiornaora").popup("open");
-}
-
function resetAndUpdate() {
var storage = window.localStorage;
//resetto la data e droppo le tabelle
@@ -65,7 +64,7 @@ function update() {
function postsUpdate(categories) {
var storage = window.localStorage;
var type = getObjKey(FONTE.categories, categories);
- var jsonurl = weburl + "wp-json/wp/v2/posts?" + REST_PARAMS.per_page + "&categories=" + categories.join(',');
+ var jsonurl = weburl + REST_PARAMS.posts + REST_PARAMS.per_page + "&categories=" + categories.join(',');
FONTE.updatedCategoriesCount = 0;
FONTE.updatedPostsCount = 0;
@@ -100,7 +99,7 @@ var updateLocalStorageDate = function(type){
var getPrevNews = function(div, categories, page) {
var storage = window.localStorage;
var type = getObjKey(FONTE.categories, categories);
- var jsonurl = weburl + "wp-json/wp/v2/posts?" + REST_PARAMS.per_page + "&categories=" + FONTE.categories[type].join(',');
+ var jsonurl = weburl + REST_PARAMS.posts + REST_PARAMS.per_page + "&categories=" + FONTE.categories[type].join(',');
FONTE.updatedCategoriesCount = 0;
FONTE.updatedPostsCount = 0;