1 /** @fileoverview Highlights widget dor Janelas Virtuais/Tela Social
  2 	@version 1.0
  3 	
  4 	@author Marcio Galli   <mgalli@taboca.com>
  5     @author Rafael Sartori <faelsartori@gmail.com>
  6 	@author Matheus Martins Teixeira <a href="mailto:mteixeira@grad.icmc.usp.br"><mteixeira@grad.icmc.usp.br></a>
  7  */ 
  8 /* ***** BEGIN LICENSE BLOCK *****
  9  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 10  *
 11  * The contents of this file are subject to the Mozilla Public License Version
 12  * 1.1 (the "License"); you may not use this file except in compliance with
 13  * the License. You may obtain a copy of the License at
 14  * http://www.mozilla.org/MPL/
 15  *
 16  * Software distributed under the License is distributed on an "AS IS" basis,
 17  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 18  * for the specific language governing rights and limitations under the
 19  * License.
 20  *
 21  * The Original Code is TelaSocial
 22  *
 23  * The Initial Developer of the Original Code is Taboca TelaSocial.
 24  * Portions created by the Initial Developer are Copyright (C) 2010
 25  * the Initial Developer. All Rights Reserved.
 26  *
 27  * Contributor(s):
 28  *      Marcio Galli   <mgalli@taboca.com>
 29  *      Rafael Sartori <faelsartori@gmail.com>
 30  *      Matheus Teixeira <teixeira.mdk@gmail.com>
 31  *
 32  * Alternatively, the contents of this file may be used under the terms of
 33  * either the GNU General Public License Version 2 or later (the "GPL"), or
 34  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 35  * in which case the provisions of the GPL or the LGPL are applicable instead
 36  * of those above. If you wish to allow use of your version of this file only
 37  * under the terms of either the GPL or the LGPL, and not to allow others to
 38  * use your version of this file under the terms of the MPL, indicate your
 39  * decision by deleting the provisions above and replace them with the notice
 40  * and other provisions required by the GPL or the LGPL. If you do not delete
 41  * the provisions above, a recipient may use your version of this file under
 42  * the terms of any one of the MPL, the GPL or the LGPL.
 43  *
 44  * ***** END LICENSE BLOCK ***** */
 45 
 46  /**
 47 	Objeto com as funções para o widget highlights
 48 	@class
 49 	@name highlights
 50  */
 51 var highlights = {
 52 	/** 
 53 	Url para o rss do widget
 54 	@type String
 55 	*/
 56 	feedURL : ICMC_DESTAQUES,
 57 	/** 
 58 	JSON retornado pela requisição dos itens
 59 	@type JSON
 60 	*/
 61 	feed : null,
 62 	/** 
 63 	Fila com as noticias a serem exibidas
 64 	@type Array
 65 	*/
 66 	queue : null,
 67 	/** 
 68 	URl do gerador de QRCodes
 69 	@type String
 70 	*/
 71 	urlQR : "https://chart.googleapis.com/chart?cht=qr&chs=220x220&chld=L|1&chl=",
 72 	/** 
 73 	Objeto container do widget
 74 	@type Dom Object
 75 	*/
 76 	container : null,
 77 	/**
 78 		Inicializa o widget highlights
 79 		@public
 80 		@function
 81 	*/
 82 	init : function() {
 83 		this.queue = new Array();
 84 		this.feed = new google.feeds.Feed(this.feedURL);
 85 		this.feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
 86 		this.feed.setNumEntries(10);
 87 	},
 88 	/**
 89 		Inicia o widget
 90 		@public
 91 		@function
 92 	*/
 93 	start : function() {
 94 		this.container = $('<div>').addClass('mainWrapper').appendTo('#container');
 95 
 96 		setTimeout(function() {
 97 			highlights.loadFeed();
 98 		}, 100);
 99 	},
100 	/**
101 		Atualiza a lista de itens do rss para o widget.
102 		O método {@link highlights.start} chama está função
103 		@private
104 		@function
105 	*/
106 	loadFeed : function() {
107 		this.feed.load(function(e) {
108 			highlights.createQueue(e)
109 		});
110 	},
111 	/**
112 		Cria a fila de noticias
113 		O método {@link highlights.loadFeed} chama está função
114 		@param {JSON Object} e Json com os dados carregados
115 		@private
116 		@function
117 	*/
118 	createQueue : function(e) {
119 		highlights.z = 1000;
120 		$(e.xmlDocument).find('item').each(function() {
121 			var title = $(this).find('title').text();
122 			var link = $(this).find('link').text();
123 			highlights.queue.push({
124 				title : title,
125 				link : link
126 			});
127 		});
128 		highlights.counter = highlights.queue.length * 30;
129 		highlights.container.html('');
130 		setTimeout(function() {
131 			highlights.render()
132 		}, 100);
133 	},
134 	z : 1000,
135 	/**
136 		Renderiza os objetos no container do widget.
137 		Após processar os itens, o método {@link highlights.createQueue} chama está função
138 		@private
139 		@function
140 	*/
141 	render : function() {
142 		if(highlights.queue.length > 0) {
143 			var obj = highlights.queue.pop();
144 
145 			var title = $('<span>').addClass('title').html("Sala de Imprensa")
146 			var description = $('<span>').addClass('description').html(obj.title);
147 			var qrcode = $('<img>').attr('src', highlights.urlQR + obj.link).width(240);
148 			var texts = $('<table>').append($('<tr>').append($('<td>').append(title).append(description)).append($('<td>').append(qrcode).attr('width', '240px')));
149 			$('<div>').addClass('item').css('z-index', highlights.z--).append(texts).appendTo(highlights.container);
150 			setTimeout(function() {
151 				highlights.render();
152 			}, 100);
153 		} else {
154 			highlights.swap();
155 		}
156 	},
157 	counter : 0,
158 	/**
159 		Função auxiliar na renderização. Faz o efeito de transição entre as notícias.
160 		@private
161 		@function
162 	*/
163 	swap : function() {
164 		if(highlights.counter > 0) {
165 			$($(highlights.container).find('.item')[0]).fadeOut(1000, function() {
166 				$(this).remove().appendTo(highlights.container).show().css('z-index', highlights.z--);
167 				highlights.counter--;
168 				setTimeout(function() {
169 					highlights.swap();
170 				}, 7000);
171 			});
172 		} else {
173 			highlights.loadFeed();
174 		}
175 	}
176 }