Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.widget.AnimatedPng");
12
dojo.require("dojo.widget.*");
13
dojo.require("dojo.widget.HtmlWidget");
14
dojo.widget.defineWidget("dojo.widget.AnimatedPng", dojo.widget.HtmlWidget, {isContainer:false, width:0, height:0, aniSrc:"", interval:100, _blankSrc:dojo.uri.moduleUri("dojo.widget", "templates/images/blank.gif"), templateString:"<img class=\"dojoAnimatedPng\" />", postCreate:function () {
15
	this.cellWidth = this.width;
16
	this.cellHeight = this.height;
17
	var img = new Image();
18
	var self = this;
19
	img.onload = function () {
20
		self._initAni(img.width, img.height);
21
	};
22
	img.src = this.aniSrc;
23
}, _initAni:function (w, h) {
24
	this.domNode.src = this._blankSrc;
25
	this.domNode.width = this.cellWidth;
26
	this.domNode.height = this.cellHeight;
27
	this.domNode.style.backgroundImage = "url(" + this.aniSrc + ")";
28
	this.domNode.style.backgroundRepeat = "no-repeat";
29
	this.aniCols = Math.floor(w / this.cellWidth);
30
	this.aniRows = Math.floor(h / this.cellHeight);
31
	this.aniCells = this.aniCols * this.aniRows;
32
	this.aniFrame = 0;
33
	window.setInterval(dojo.lang.hitch(this, "_tick"), this.interval);
34
}, _tick:function () {
35
	this.aniFrame++;
36
	if (this.aniFrame == this.aniCells) {
37
		this.aniFrame = 0;
38
	}
39
	var col = this.aniFrame % this.aniCols;
40
	var row = Math.floor(this.aniFrame / this.aniCols);
41
	var bx = -1 * col * this.cellWidth;
42
	var by = -1 * row * this.cellHeight;
43
	this.domNode.style.backgroundPosition = bx + "px " + by + "px";
44
}});
45