Subversion Repositories Applications.papyrus

Rev

Rev 1372 | 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
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.widget.AnimatedPng");
14
dojo.require("dojo.widget.*");
15
dojo.require("dojo.widget.HtmlWidget");
16
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 () {
17
	this.cellWidth = this.width;
18
	this.cellHeight = this.height;
19
	var img = new Image();
20
	var self = this;
21
	img.onload = function () {
22
		self._initAni(img.width, img.height);
23
	};
24
	img.src = this.aniSrc;
25
}, _initAni:function (w, h) {
26
	this.domNode.src = this._blankSrc;
27
	this.domNode.width = this.cellWidth;
28
	this.domNode.height = this.cellHeight;
29
	this.domNode.style.backgroundImage = "url(" + this.aniSrc + ")";
30
	this.domNode.style.backgroundRepeat = "no-repeat";
31
	this.aniCols = Math.floor(w / this.cellWidth);
32
	this.aniRows = Math.floor(h / this.cellHeight);
33
	this.aniCells = this.aniCols * this.aniRows;
34
	this.aniFrame = 0;
35
	window.setInterval(dojo.lang.hitch(this, "_tick"), this.interval);
36
}, _tick:function () {
37
	this.aniFrame++;
38
	if (this.aniFrame == this.aniCells) {
39
		this.aniFrame = 0;
40
	}
41
	var col = this.aniFrame % this.aniCols;
42
	var row = Math.floor(this.aniFrame / this.aniCols);
43
	var bx = -1 * col * this.cellWidth;
44
	var by = -1 * row * this.cellHeight;
45
	this.domNode.style.backgroundPosition = bx + "px " + by + "px";
46
}});
47