var newsContent = new function() { this.pagination = null; this.getPageCount = function() { return ((null !== this.pagination) ? this.pagination.length : 0); }; this.excluir = function(id, itensFile) { var self = this; $.ajax({ url: '../gigi/news/delete.php', data: { id: id, itensFile: itensFile, c: new Date().getTime() }, dataType: 'json', type: 'POST', beforeSend: function() { }, complete: function() { }, error: function() { }, success: function(data) { if ((null !== data) && (0 === data.itens.length)) { self.pagination = null; self.loadNewsContentsByPage(0); } else { self.loadNewsContentsByFile(itensFile); } } }); }; this.loadNewsPagination = function() { var self = this; $.ajax({ url: "db/pages.json", data: { c: new Date().getTime() }, dataType: 'json', type: 'GET', beforeSend: function() { }, complete: function() { }, error: function() { }, success: function(data) { if ((null != data) && (null != data.pages)) { this.pagination = data.pages; } } }); }; this.loadNewsContentsByPage = function(currentPage) { var self = this; if (null !== this.pagination) { var pageCount = this.pagination.length; currentPage--; if ((-1 < currentPage) && (pageCount > currentPage)) { this.loadNewsContentsByFile(this.pagination[currentPage]); } else if (0 < pageCount) { this.loadNewsContentsByFile(this.pagination[0]); } else { // CRIAR PAGINA DEFAULT $("#news").empty(); $("#news").append("

EM BREVE

"); } $("#newsPagination").empty(); if (0 < pageCount) { $("#newsPagination").append("
  • «
  • "); $.each(self.pagination, function (i, item) { $("#newsPagination").append("" + (i + 1) + ""); }); $("#newsPagination").append("
  • »
  • "); } } else { $.ajax({ url: "db/pages.json", data: { c: new Date().getTime() }, dataType: 'json', type: 'GET', beforeSend: function() { }, complete: function() { }, error: function() { }, success: function(data) { if ((null != data) && (null != data.pages)) { self.pagination = data.pages; var pageCount = self.pagination.length; currentPage--; if ((-1 < currentPage) && (pageCount > currentPage)) { self.loadNewsContentsByFile(self.pagination[currentPage]); } else if (0 < pageCount) { self.loadNewsContentsByFile(self.pagination[0]); } else { // CRIAR PAGINA DEFAULT $("#news").empty(); $("#news").append("

    EM BREVE

    "); } $("#newsPagination").empty(); if (0 < pageCount) { $("#newsPagination").append("
  • «
  • "); $.each(self.pagination, function (i, item) { $("#newsPagination").append("" + (i + 1) + ""); }); $("#newsPagination").append("
  • »
  • "); } } } }); } }; this.loadNewsContentsByFile = function(fileName) { var self = this; $.ajax({ url: 'db/' + fileName, data: { c: new Date().getTime() }, dataType: 'json', type: 'GET', beforeSend: function() { }, complete: function() { }, error: function() { }, success: function(data) { if ((null != data) && (null !== data.itens)) { var _html; $("#news").empty(); $.each(data.itens, function (i, item) { _html = " "; _html += "
    "; _html += "
    "; _html += "
    "; _html += "

    " + item.titulo + "

    "; _html += "
      "; _html += "
    • " + item.data + "
    • "; _html += "
    "; if (0 < item.imagens.length) { _html += "
    "; _html += "
    "; $.each(item.imagens, function (i2, imagemPath) { _html += "
    "; _html += " \"""; _html += "
    "; }); _html += "
    "; _html += " "; _html += " "; _html += " "; _html += " "; _html += " "; _html += " "; _html += "
    "; } _html += "

    " + item.mensagem + "

    "; _html += "
    "; _html += "
    "; _html += "
    "; _html += "
    "; _html += "
    "; _html += " "; $("#news").append(_html); }); } } }); }; this.getUrlParam = function(paramName) { var url = window.location.href; var posA; var pagina = 1; var separadores = ["?", "&", "#"]; for (var i = 0; i < separadores.length; i++) { posA = url.indexOf(separadores[i] + paramName + "="); if (-1 < posA) { posA += paramName.length + 2; var posB = url.indexOf("&", posA); if (-1 == posB) { posB = url.indexOf("#", posA); if (-1 == posB) { posB = url.length; } } pagina = url.substring(posA, posB); if ((isNaN(pagina)) || (isNaN(parseInt(pagina)))) { pagina = 1; } break; } } return pagina; }; this.loadNewsPagination(); this.loadNewsContentsByPage(this.getUrlParam("page")); };