|
@@ -20,23 +20,24 @@
|
|
|
var FONTE = FONTE || {};
|
|
|
FONTE.dbName = "xm24";
|
|
|
FONTE.dbHandler;
|
|
|
+FONTE.updatedCategoriesCount;
|
|
|
+FONTE.updatedPostsCount;
|
|
|
+FONTE.neededPostsCount;
|
|
|
FONTE.tagsPageInitiated = false;
|
|
|
FONTE.categoriesList = [8, 497];
|
|
|
FONTE.categories = {
|
|
|
ilove : [497,647,590], //ilove, 4mar, solid
|
|
|
info : [8,42,68,3], //ilove, 4mar, solid
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
FONTE.page_loaded = {
|
|
|
ilove : 0,
|
|
|
info : 0,
|
|
|
};
|
|
|
|
|
|
-FONTE.updatedCategoriesCount;
|
|
|
-FONTE.updatedPostsCount;
|
|
|
-FONTE.neededPostsCount;
|
|
|
FONTE.hrefseguente = "";
|
|
|
FONTE.contentListId = '#mostralistainfo';
|
|
|
+FONTE.contentListClass = '.news';
|
|
|
FONTE.ajaxError = false;
|
|
|
/*
|
|
|
* data ultimo aggiornamento
|
|
@@ -49,39 +50,46 @@ function displayLastUpdateDate() {
|
|
|
var dataora = data[1];
|
|
|
$("#datadiritti").empty();
|
|
|
$("#datadirittiora").empty();
|
|
|
- display_results("#datadiritti", datagiorno)
|
|
|
- display_results("#datadirittiora", dataora)
|
|
|
+ display_results("#datadiritti", datagiorno);
|
|
|
+ display_results("#datadirittiora", dataora);
|
|
|
if (data) {
|
|
|
$("#boxdata").css("display", "block");
|
|
|
}
|
|
|
} else {
|
|
|
toastr.warning('Warn: manca la data del tuo ultimo aggiornamento. Aggiorna al più presto.');
|
|
|
}
|
|
|
-};
|
|
|
-var paginacorrente = "";
|
|
|
+}
|
|
|
|
|
|
function alterContent(url) {
|
|
|
- paginacorrente = $("body").pagecontainer("getActivePage").attr("id");
|
|
|
+ var paginacorrente = $("body").pagecontainer("getActivePage").attr("id");
|
|
|
+
|
|
|
switch (url) {
|
|
|
case '#index':
|
|
|
$("#navheader").addClass("hide");
|
|
|
$("#navfooter").addClass("hide");
|
|
|
break;
|
|
|
+ case '#about':
|
|
|
+ $("#navheader").removeClass("hide");
|
|
|
+ $("#navfooter").addClass("hide");
|
|
|
+ if(window.localStorage.getItem('app_firsttime') === "false") {
|
|
|
+ $("#init-btn").addClass("hide");
|
|
|
+ } else {
|
|
|
+ window.localStorage.setItem('app_firsttime', false);
|
|
|
+ }
|
|
|
+ break;
|
|
|
case '#ilove':
|
|
|
$("#navheader").removeClass("hide");
|
|
|
- $("#navfooter").removeClass("hide");
|
|
|
- myJsonCategory(497, "#mostralista");
|
|
|
- /* myJsonPage(3452, '#prestitle', '#mostrapres');*/
|
|
|
+ $("#navfooter").addClass("hide");
|
|
|
+ postsUpdate(FONTE.categories.ilove);
|
|
|
break;
|
|
|
case '#info':
|
|
|
$("#navheader").removeClass("hide");
|
|
|
$("#navfooter").addClass("hide");
|
|
|
- myJsonCategory(8, "#mostralistainfo");
|
|
|
+ postsUpdate(FONTE.categories.info);
|
|
|
break;
|
|
|
case '#events':
|
|
|
$("#navheader").removeClass("hide");
|
|
|
$("#navfooter").addClass("hide");
|
|
|
- //$("#navfooter").removeClass("hide");
|
|
|
EVENTS.render();
|
|
|
break;
|
|
|
case '#aggiorna':
|
|
@@ -99,17 +107,17 @@ function alterContent(url) {
|
|
|
$("#navfooter").removeClass("hide");
|
|
|
myJsonRandomPost('#titolosingleR', '#mostracontentsingleR');
|
|
|
break;
|
|
|
- };
|
|
|
+ }
|
|
|
// Alter the url according to the anchor's href attribute, and
|
|
|
// store the data-foo attribute information with the url
|
|
|
$.mobile.navigate(url);
|
|
|
-};
|
|
|
+}
|
|
|
/*///////////////utilities//////////////http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript*/
|
|
|
function getParameterByName(name, url) {
|
|
|
if (!url) url = window.location.href;
|
|
|
name = name.replace(/[\[\]]/g, "\\$&");
|
|
|
- var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)")
|
|
|
- , results = regex.exec(url);
|
|
|
+ var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
|
|
|
+ results = regex.exec(url);
|
|
|
if (!results) return null;
|
|
|
if (!results[2]) return '';
|
|
|
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
|
@@ -117,7 +125,7 @@ function getParameterByName(name, url) {
|
|
|
|
|
|
function display_results(contenitore, messaggio) {
|
|
|
$(contenitore).text(messaggio);
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
$(function () {
|
|
|
$("form").submit(function () {
|
|
@@ -127,28 +135,25 @@ $(function () {
|
|
|
|
|
|
function benvenuta() {
|
|
|
$("#benvenuta").popup("open");
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
//function aggiornaora() {
|
|
|
// $("#aggiornaora").popup("open");
|
|
|
//};
|
|
|
|
|
|
-function run() {
|
|
|
- initStorage();
|
|
|
- overlayblock();
|
|
|
+function initMainPage() {
|
|
|
if (checkConnection()) {
|
|
|
- partialUpdate(FONTE.categories['info']);
|
|
|
+ postsUpdate(FONTE.categories.info);
|
|
|
} else {
|
|
|
- renderLastNews(FONTE.contentListId, FONTE.categories['info']);
|
|
|
+ renderLastNews(FONTE.contentListClass, FONTE.categories.info);
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
/*per link in browser di default */
|
|
|
document.addEventListener("deviceready", onDeviceReady, false);
|
|
|
//le cose all'inizio
|
|
|
|
|
|
$(document).on("mobileinit", function () {
|
|
|
-
|
|
|
$("body").pagecontainer({
|
|
|
defaults: true
|
|
|
});
|
|
@@ -156,13 +161,13 @@ $(document).on("mobileinit", function () {
|
|
|
$(".ui-loader").loader({
|
|
|
defaults: true
|
|
|
});
|
|
|
+
|
|
|
$("input").button();
|
|
|
});
|
|
|
|
|
|
-$(document).on("pagecontainerchange", function () {
|
|
|
-
|
|
|
+$(document).on("pagecontainerchange", function () {
|
|
|
var current = $(".ui-page-active").prop("id"); // Remove active class from nav buttons
|
|
|
- if(current == 'info' || current == 'events'){
|
|
|
+ if(current == 'about' || current == 'info' || current == 'ilove' || current == 'events'){
|
|
|
$("#navfooter").addClass("hide");
|
|
|
} else {
|
|
|
$("#navfooter").removeClass("hide");
|
|
@@ -177,7 +182,6 @@ $(document).on("pagecontainerchange", function () {
|
|
|
$(this).addClass("ui-btn-active");
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
});
|
|
|
|
|
|
$(document).on("pagecreate", function () {
|
|
@@ -197,19 +201,15 @@ var Site = function () {
|
|
|
};
|
|
|
|
|
|
Site.prototype.init = function () {
|
|
|
-
|
|
|
var self = this;
|
|
|
-
|
|
|
$(document).ready(function () {
|
|
|
-
|
|
|
// default page if no hash given
|
|
|
// this changes the hash, so the event is fired
|
|
|
// no need to call self.navigate
|
|
|
-
|
|
|
-
|
|
|
window.location.hash = self.homepage;
|
|
|
});
|
|
|
};
|
|
|
+
|
|
|
// On document ready
|
|
|
$(function () {
|
|
|
// intercettaUrl();
|
|
@@ -220,45 +220,36 @@ $(function () {
|
|
|
function onDeviceReady() {
|
|
|
// console.log('deviceready');
|
|
|
createDB();
|
|
|
- run();
|
|
|
+ initStorage();
|
|
|
+
|
|
|
+ if(window.localStorage.getItem('app_firsttime') !== "false") {
|
|
|
+ alterContent('#about');
|
|
|
+ } else {
|
|
|
+ initMainPage();
|
|
|
+ }
|
|
|
+
|
|
|
+ overlayblock();
|
|
|
$("a.nav").on("click", function (event) {
|
|
|
// Prevent the usual navigation behavior
|
|
|
event.preventDefault();
|
|
|
- hrefseguente = $(this).attr("href");
|
|
|
- alterContent(hrefseguente);
|
|
|
+ alterContent($(this).attr("href"));
|
|
|
+ });
|
|
|
+
|
|
|
+ $("button.nav").on("click", function (event) {
|
|
|
+ alterContent($(this).attr("href"));
|
|
|
});
|
|
|
// eliminare le due righe:
|
|
|
$("body > [data-role='header']").toolbar();
|
|
|
$("[data-role='navbar']").navbar();
|
|
|
- alterContent("#info");
|
|
|
-};
|
|
|
+
|
|
|
+ //Non uso pageContent per non lanciare 2 volte il recupero dei dati da internet
|
|
|
+ $("#navheader").removeClass("hide");
|
|
|
+ $("#navfooter").addClass("hide");
|
|
|
+}
|
|
|
|
|
|
function overlayblock() {
|
|
|
$(".overlaynero").toggleClass("hide");
|
|
|
}
|
|
|
-/*per network info*/
|
|
|
-function checkConnection(code, msgConnect) {
|
|
|
- var msgTitle = "Non sei connesso";
|
|
|
- msgConnect = msgConnect || "Occore essere connessi per poter ricevere i nuovi articoli";
|
|
|
-
|
|
|
- var networkState = navigator.connection.type;
|
|
|
- var states = {};
|
|
|
- states[Connection.UNKNOWN] = 'Unknown connection';
|
|
|
- states[Connection.ETHERNET] = 'Ethernet connection';
|
|
|
- states[Connection.WIFI] = 'WiFi connection';
|
|
|
- states[Connection.CELL_2G] = 'Cell 2G connection';
|
|
|
- states[Connection.CELL_3G] = 'Cell 3G connection';
|
|
|
- states[Connection.CELL_4G] = 'Cell 4G connection';
|
|
|
- states[Connection.CELL] = 'Cell generic connection';
|
|
|
- states[Connection.NONE] = 'No network connection';
|
|
|
- if (states[networkState] == 'Unknown connection' || states[networkState] == 'No network connection') {
|
|
|
- toastr.warning(msgConnect, msgTitle);
|
|
|
- console.log(code);
|
|
|
- return false
|
|
|
- } else {
|
|
|
- return true
|
|
|
- }
|
|
|
-}
|
|
|
/*///////////////fine utilities//////////////*/
|
|
|
|
|
|
var weburl = "http://www.ecn.org/xm24/";
|
|
@@ -268,11 +259,11 @@ function intercettaUrl() {
|
|
|
// LETTURA - Log the results of the navigate event
|
|
|
$(window).on("navigate", function (event, data) {
|
|
|
idPost = getParameterByName('id');
|
|
|
- if (idPost != "") {
|
|
|
+ if (idPost !== "") {
|
|
|
myJsonPost(idPost, "#titolosingle", "#mostracontentsingle");
|
|
|
}
|
|
|
});
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
function postInList() {
|
|
|
//SCRITTURA
|
|
@@ -287,32 +278,14 @@ function postInList() {
|
|
|
// Prevent the usual navigation behavior
|
|
|
event.preventDefault();
|
|
|
/*se serve idTAg, mettiamolo nell'url!! e anche nella page!*/
|
|
|
- $("#singleQpost").attr("id", '#singleQpost?id=' + idOra)
|
|
|
+ $("#singleQpost").attr("id", '#singleQpost?id=' + idOra);
|
|
|
$(":mobile-pagecontainer").pagecontainer("load", '#singleQpost' + idOra, {
|
|
|
showLoadMsg: false
|
|
|
});
|
|
|
$("#navfooter").removeClass("hide");
|
|
|
location.hash = '#singleQpost?id=' + idOra;
|
|
|
});
|
|
|
-};
|
|
|
-
|
|
|
-function postInListTag(div) {
|
|
|
- $(div).on('click', 'li > a', function () {
|
|
|
- var idTag = $(this).attr("data-post");
|
|
|
- var titleTag = $(this).html();
|
|
|
- $("#tagpostlist").empty();
|
|
|
- myJsonPostByTagList(idTag, '#tagpostlist');
|
|
|
- $("#tagtitle").empty();
|
|
|
- $("#tagtitle").append(titleTag);
|
|
|
- // Prevent the usual navigation behavior
|
|
|
- event.preventDefault();
|
|
|
- $("#posttag").attr("id", '#posttag?idT=' + idTag)
|
|
|
- $(":mobile-pagecontainer").pagecontainer("load", '#posttag' + idTag, {
|
|
|
- showLoadMsg: false
|
|
|
- });
|
|
|
- location.hash = '#posttag?idT=' + idTag;
|
|
|
- });
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
function cercaMe() {
|
|
|
var input_text = $("input.cerca").val();
|
|
@@ -327,9 +300,9 @@ function cercaMe() {
|
|
|
var lastUpdateDate = Date.parse(lastUpdate);
|
|
|
|
|
|
$.ajax({
|
|
|
- dataType: "json"
|
|
|
- , url: jsonurl
|
|
|
- , success: function (data) {
|
|
|
+ dataType: "json",
|
|
|
+ url: jsonurl,
|
|
|
+ success: function (data) {
|
|
|
var items = [];
|
|
|
$.each(data, function (key, val) {
|
|
|
var id = val.id;
|
|
@@ -348,34 +321,18 @@ function cercaMe() {
|
|
|
}
|
|
|
});
|
|
|
$("<ul/>", {
|
|
|
- "class": "my-new-list"
|
|
|
- , html: items.join("")
|
|
|
+ "class": "my-new-list",
|
|
|
+ html: items.join("")
|
|
|
}).prependTo(".listresult");
|
|
|
$.mobile.loading('hide');
|
|
|
- }
|
|
|
- , error: JSONErrorHandler
|
|
|
+ },
|
|
|
+ error: JSONErrorHandler
|
|
|
});
|
|
|
} else {
|
|
|
toastr.error('Err: ERR_NOUPDATE');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function initTagsPage() {
|
|
|
- if (!FONTE.tagsPageInitiated) {
|
|
|
- initTag("#mostralistaTag"); // questo mostra i tag
|
|
|
- postInListTag("#mostralistaTag"); // questo ti sposta alla specifica lista dei post di un tag
|
|
|
- FONTE.tagsPageInitiated = true;
|
|
|
- }
|
|
|
-}
|
|
|
-/* scriversi le cose nel local storage*/
|
|
|
-function initStorage() {
|
|
|
- try {
|
|
|
- return 'localStorage' in window && window['localStorage'] !== null;
|
|
|
- } catch (e) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
function findImg(htmlString) {
|
|
|
var pos = htmlString.indexOf('<img ');
|
|
|
while (pos != -1) {
|
|
@@ -384,13 +341,13 @@ function findImg(htmlString) {
|
|
|
pos = htmlString.indexOf('<img ', pos);
|
|
|
}
|
|
|
return htmlString;
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
function imgNotFound(img) {
|
|
|
var parent = $(img).parent();
|
|
|
parent.empty();
|
|
|
- parent.append('<span>Immagine disponibile online.</span>')
|
|
|
-};
|
|
|
+ parent.append('<span>Immagine disponibile online.</span>');
|
|
|
+}
|
|
|
|
|
|
function JSONErrorHandler(jqXHR, textStatus, errorThrown) {
|
|
|
if (!FONTE.ajaxError) {
|
|
@@ -401,7 +358,7 @@ function JSONErrorHandler(jqXHR, textStatus, errorThrown) {
|
|
|
toastr.error(errMsg);
|
|
|
FONTE.ajaxError = true;
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
function cerca() {
|
|
|
var ret = checkConnection('ERR_CERCA');
|
|
@@ -411,11 +368,11 @@ function cerca() {
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
function segnalaBug() {
|
|
|
return checkConnection('ERR_SEGNALA');
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
function mostraEsperto() {
|
|
|
var ret = checkConnection('ERR_ESPERTO');
|
|
@@ -424,7 +381,7 @@ function mostraEsperto() {
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
function checkAndUpdate() {
|
|
|
var ret = checkConnection('ERR_ESPERTO');
|
|
@@ -433,7 +390,7 @@ function checkAndUpdate() {
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
function checkAndReset() {
|
|
|
var ret = checkConnection('ERR_ESPERTO');
|
|
@@ -442,4 +399,4 @@ function checkAndReset() {
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
-};
|
|
|
+}
|