ZCache.JS

Plugin para carregamento e armazenamento de arquivos Javascript em localStorage baseado no Basket.js

O ZCache é indicado para o carregamento de bibliotecas de terceiros em seu projeto. Uma vez carregado o arquivo não será necessário fazer novamente o download do mesmo na proxima vez que a pagina for recarregada, salvo quando o arquivo ultrapassar o tempo de permanência no cache.

O ZCache é compatível com:
  • - Internet Explorer 8+
  • - Mozilla Firefox 16+
  • - Google Chrome 23+
  • - Safari 5.1+
  • - Android Browser 2.1+

OBS: Em navegadores sem suporte a localStorage os arquivos são incluídos, mas não são salvos em cache.

Uso

Baixe o arquivo no repositório https://github.com/brunoziie/zcache e inclua no seu HTML.
<script type="text/javascript" src="zcache.min.js"></script>

Exemplos

Incluindo um único arquivo:
ZCache.require('jquery.mim.js'); 
 
Incluindo um arquivo sem salvar no cache:
ZCache.require('jquery.mim.js', true);

Incluindo múltiplos arquivos
ZCache.require(['myscript1.js', 'myscript2.js', 'myscript3.js']);

Incluindo múltiplos arquivos sem salvar um determinado arquivo da lista no cache
ZCache.require([{file : 'myscript1.js', noCache: true}, 'myscript2.js']);

 

Opções


Para definir uma opção usa-se o método setOption
ZCache.setOption('cacheDuration', 3600);

debug
Quando true exibe mensagens no console em caso de erro. (default: false)
 
cacheDuration
Define (em segundos) a duração de um arquivo em no cache (default: 1800 segundos)
 
scriptsPath
Define o caminho para o diretório onde estão armazenados os arquivos javascript (default: vazio)


OBS: Caso use arquivos em muitos diretórios distintos aconselha-se não alterar essa opção

Obter o conteúdo de um arquivo

Utilitário para obter o conteúdo de um arquivo de um input de tipo file.
/**
 * Get local file content.
 * 
 * @author Bruno Ziiê | eu@brunoziie.com
 */
var FileContent = function(){

 var that = {};

 /**
  * File input Id
  * @type {String}
  */
 that.inputElementId = null

 /**
  * File list from input
  * @type {Object}
  */
 that.fileList = null;

 /**
  * First element of this.fileList
  * @type {Object}
  */
 that.file = null;

 /**
  * FileReader Instance
  * @type {Object}
  */
 that.reader = null;

 /**
  * Object constructor
  *
  * @param {String} inputElementId File Input id
  */
 this.__constructor = function(inputElementId){
  that.inputElementId = inputElementId || null;
  that.reader = new FileReader();
  return this;
 };

 /**
  * Refresh storaged data from input
  * 
  * @return {void}
  */
 that.getElement = function(){
  if(that.inputElementId != null) {
   that.fileList = document.getElementById(that.inputElementId);

   if(that.fileList != null){
    if (that.fileList.files.length > 0) {
     that.file = that.fileList.files[0];
    };
   }
  }
 }

 /**
  * Get the file content in text format
  * 
  * @param  {Function} callback Function to call when the file was loaded
  * @return {void}
  */
 this.getAsText = function(callback){
  that.getElement();

  if(that.file != null){
   var blob = that.file.slice(0, that.file.size);

   that.reader.readAsText(blob);
   that.reader.onloadend = function(){
    callback(that.reader.result);
   }
  }else{
   callback('');
  }
 }

 /**
  * Get the file content in binary format
  * 
  * @param  {Function} callback Function to call when the file was loaded
  * @return {void}
  */
 this.getAsBinary = function(callback){
  that.getElement();

  if(that.file != null){
   var blob = that.file.slice(0, that.file.size);

   that.reader.readAsBinaryString(blob);
   that.reader.onloadend = function(){
    callback(that.reader.result);
   }
  }else{
   callback('');
  }
 }


 /**
  * Get the file content in base64 format
  * 
  * @param  {Function} callback Function to call when the file was loaded
  * @return {void}
  */
 this.getAsBase64Data = function(callback){
  that.getElement();

  if(that.file != null){
   var blob = that.file.slice(0, that.file.size);

   that.reader.readAsDataURL(blob);
   that.reader.onloadend = function(){
    callback(that.reader.result);
   }
  }else{
   callback('');
  }
 }

 return this.__constructor.apply(this, arguments);

};
Uso:
var myFile = new FileContent('arquivo');
myFile.getAsBinary(function(text){
    // fazer algo com o text
});

[LIKE] PhoneGap Facebook Plugin Android, PG 1.8.1

Screencast mostrando como implementar o plugin de integração com o facebook no PhoneGap

MeuBusão beta



Criado a principio como forma de ganhar experiência no desenvolvimento de Web Apps com a plataforma PhoneGap, sai a versão beta do MeuBusão.

O MeuBusão tem como objetivo facilitar o acesso a informações sobre itinerários, preços e linhas de ónibus aos usuários de transporte publico do Recife e Região metropolitana.

O aplicativo já se encontra disponível para download no Google Play. Nessa primeira versão estão disponíveis apenas as funcionalidades de exibir opções de ônibus para se chegar de um ponto a outro e buscar linhas. Em breve mais funcionalidades serão implementadas e disponibilizadas por meio de atualizações.

Traçando rota entre dois pontos com Google Maps API


 var directionsDisplay;
 var directionsService = new google.maps.DirectionsService();
 var map;

 function initialize() {
  directionsDisplay = new google.maps.DirectionsRenderer();
  var center = new google.maps.LatLng(-8.288642,-35.031128);

  var mapOptions = {
    zoom:18,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    center: center
   }

  map = new google.maps.Map(
    document.getElementById("map_canvas"), 
    mapOptions
   );
  directionsDisplay.setMap(map);
 }

 
 function calcRoute() {
  var start = '-8.288642,-35.031128';
  var end = '-8.288300,-35.029371';
  var request = {
    origin: start,
    destination: end,
    travelMode: google.maps.TravelMode.WALKING 
   };

  directionsService.route(request, function(result, status) {
   if (status == google.maps.DirectionsStatus.OK) {
    directionsDisplay.setDirections(result);
   }
  });
 }