/* * 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.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.hrefseguente = ""; FONTE.contentListId = '#mostralistainfo'; FONTE.contentListClass = '.news'; FONTE.ajaxError = false; /* * data ultimo aggiornamento */ function displayLastUpdateDate() { 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.'); } } function alterContent(url) { 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").addClass("hide"); postsUpdate(FONTE.categories.ilove); break; case '#info': $("#navheader").removeClass("hide"); $("#navfooter").addClass("hide"); postsUpdate(FONTE.categories.info); break; case '#events': $("#navheader").removeClass("hide"); $("#navfooter").addClass("hide"); EVENTS.render(); 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 initMainPage() { if (checkConnection()) { postsUpdate(FONTE.categories.info); } else { 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 }); $(".ui-loader").loader({ defaults: true }); $("input").button(); }); $(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'){ $("#navfooter").addClass("hide"); } else { $("#navfooter").removeClass("hide"); } console.log("current" + current); $("[data-role='navbar'] a.ui-btn-active").removeClass("ui-btn-active");     // Add active class to current nav button      $("[data-role='navbar'] a").each(function () { var href = $(this).prop("href");         if (href.indexOf(current, href.length - current.length) !== -1) {             $(this).addClass("ui-btn-active");         }     }); }); $(document).on("pagecreate", function () { $("body > [data-role='panel']").panel(); $("body > [data-role='panel'] [data-role='listview']").listview(); $("body > [data-role='header']").toolbar(); $("body > [data-role='footer']").toolbar(); $("body > [data-role='navbar']").navbar(); $("#navfooter").navbar(); postInList(); }); /*per inizio navigazione*/ var Site = function () { this.homepage = "#index"; // the default page that is loaded this.init(); }; 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(); // new Site(); // $(".minibox").click(function () {}); }); function onDeviceReady() { // console.log('deviceready'); createDB(); 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(); 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(); //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"); } /*///////////////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"); var _class = $(this).attr("class"); $("#titolosingle").empty(); $("#mostracontentsingle").empty(); //console.log(idOra); myJsonPost(idOra, "#titolosingle", "#mostracontentsingle", _class); // 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 }); $("#navfooter").removeClass("hide"); location.hash = '#singleQpost?id=' + idOra; }); } 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 + "

    "); } }); $("