/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ ///VARIABILI GLOBALI/// var FONTE = FONTE || {}; FONTE.dbName = "xm24"; FONTE.dbHandler; FONTE.tagsPageInitiated = false; FONTE.categoriesList = [8, 497]; FONTE.updatedCategoriesCount; FONTE.updatedPostsCount; FONTE.neededPostsCount; FONTE.hrefseguente = ""; FONTE.ajaxError = false; /* * data ultimo aggiornamento */ function ultimoAggiornamento() { var lastUpdate = window.localStorage.getItem('db_update_date'); if (lastUpdate) { var data = lastUpdate.split('T'); var datagiorno = data[0]; var dataora = data[1]; $("#datadiritti").empty(); $("#datadirittiora").empty(); 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"); switch (url) { case '#index': $("#navheader").addClass("hide"); $("#navfooter").addClass("hide"); break; case '#ilove': $("#navheader").removeClass("hide"); $("#navfooter").removeClass("hide"); myJsonCategory(497, "#mostralista"); /* myJsonPage(3452, '#prestitle', '#mostrapres');*/ break; case '#info': $("#navheader").removeClass("hide"); $("#navfooter").removeClass("hide"); myJsonCategory(8, "#mostralistainfo"); break; case '#events': $("#navheader").removeClass("hide"); $("#navfooter").removeClass("hide"); ai1ec.remote.getAllEvents(ai1ec.cats.single); ai1ec.remote.getLastEvents(ai1ec.cats.single); break; case '#aggiorna': $("#navheader").removeClass("hide"); $("#navfooter").removeClass("hide"); // ultimoAggiornamento(); break; case '#ultime': case '#tag': $("#navheader").removeClass("hide"); $("#navfooter").removeClass("hide"); break; case '#quotidiano': $("#navheader").removeClass("hide"); $("#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); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); } function display_results(contenitore, messaggio) { $(contenitore).text(messaggio); }; $(function () { $("form").submit(function () { return false; }); }); function benvenuta() { $("#benvenuta").popup("open"); }; //function aggiornaora() { // $("#aggiornaora").popup("open"); //}; function setFirstRun() { initStorage(); overlayblock(); if (window.localStorage.getItem('has_run') != 'true') { //do some stuff if has not loaded before overlayblock(); benvenuta(); if (checkConnection()) { partialUpdate(); //window.localStorage.setItem('has_run', 'true'); } } }; /*per link in browser di default */ document.addEventListener("deviceready", onDeviceReady, false); //le cose all'inizio function onDeviceReady() { // console.log('deviceready'); createDB(); setFirstRun(); $("#navheader").addClass("hide"); $("#navfooter").addClass("hide"); $("a.nav").on("click", function (event) { // Prevent the usual navigation behavior event.preventDefault(); hrefseguente = $(this).attr("href"); alterContent(hrefseguente); }); }; 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/"; var arrayTag = []; /*/////finite variabili globali////////*/ function intercettaUrl() { // LETTURA - Log the results of the navigate event $(window).on("navigate", function (event, data) { idPost = getParameterByName('id'); if (idPost != "") { myJsonPost(idPost, "#titolosingle", "#mostracontentsingle"); } }); }; function postInList() { //SCRITTURA $("body").on('click', '.listevoci li > a', function (event) { // console.log("HUU_post in list"); var idOra = $(this).attr("data-post"); $("#titolosingle").empty(); $("#mostracontentsingle").empty(); //console.log(idOra); myJsonPost(idOra, "#titolosingle", "#mostracontentsingle"); // Prevent the usual navigation behavior event.preventDefault(); /*se serve idTAg, mettiamolo nell'url!! e anche nella page!*/ $("#singleQpost").attr("id", '#singleQpost?id=' + idOra) $(":mobile-pagecontainer").pagecontainer("load", '#singleQpost' + idOra, { showLoadMsg: false }); 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 initTag(div) { // $.mobile.loading('show'); // FONTE.dbHandler.executeSql("SELECT * FROM xm24_tags ORDER BY date COLLATE NOCASE DESC;", [], function (resultSet) { // var items = []; // for (var i = 0; i < resultSet.rows.length; i++) { // var val = JSON.parse(resultSet.rows.item(i).tag); // var name = val.name; // var slug = val.slug; // var id = val.id; // items.push("
  • " + name + "
  • "); // } // $(div).empty(); // $("