All Downloads are FREE. Search and download functionalities are using the official Maven repository.

js.progress-polyfill.js Maven / Gradle / Ivy

Go to download

A plugin used to generate reports of test outcomes and code coverage by tests executed by the CCL Testing Framework and through the maven-ccl-plugin

There is a newer version: 2.3
Show newest version
/*
Copyright (C) 2011 Lea Verou

You may use HTML5-Progress-polyfill under the terms of the MIT License.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/*
 *  polyfill
 * Don't forget to also include progress-polyfill.css!
 * @author Lea Verou http://leaverou.me
 */
 
(function(){

// Test browser support first
if('position' in document.createElement('progress')) {
	return;
}

/**
 * Private functions
 */

// Smoothen out differences between Object.defineProperty
// and __defineGetter__/__defineSetter__
var defineProperty, supportsEtters = true, progressWidth=0;

if(Object.defineProperty) {
	// Changed to fix issue #3 https://github.com/LeaVerou/HTML5-Progress-polyfill/issues/3
	defineProperty = function(o, property, etters) {
		etters.enumerable = true;
		etters.configurable = true;
		
		try {
			Object.defineProperty(o, property, etters);
		} catch(e) {
			if(e.number === -0x7FF5EC54) {
				etters.enumerable = false;
				Object.defineProperty(o, property, etters);
			}
		}
	}
}
else {
	if ('__defineSetter__' in document.body) {
		defineProperty = function(o, property, etters) {
			o.__defineGetter__(property, etters.get);
			
			if(etters.set) {
				o.__defineSetter__(property, etters.set);
			}
		};
	}
	else {
		// Fallback to regular properties if getters/setters are not supported
		defineProperty = function(o, property, etters) {
				o[property] = etters.get.call(o);
			},
			supportsEtters = false;
	}
}

try {
	[].slice.apply(document.images)
	
	var arr = function(collection) {
		return [].slice.apply(collection);
	}
} catch(e) {
	var arr = function(collection) {
		var ret = [], len = collection.length;
		
		for(var i=0; i 0) {
		    progressWidth = progress.offsetWidth;
		  }
			progress.style.paddingRight = progressWidth * (1-progress.position) + 'px';
		}
	},
	
	isInited: function(progress) {
		return progress.getAttribute('role') === 'progressbar';
	},
	
	init: function (progress) {
		if(self.isInited(progress)) {
			return; // Already init-ed
		}
		
		// Add ARIA
		progress.setAttribute('role', 'progressbar');
		progress.setAttribute('aria-valuemin', '0');
		progress.setAttribute('aria-valuemax', parseFloat(progress.getAttribute('max')) || 1);
		
		if(progress.hasAttribute('value')) {
			progress.setAttribute('aria-valuenow', parseFloat(progress.getAttribute('value')) || 0);
		}
		
		// We can't add them on a prototype, as it's the same for all unknown elements
		for(var attribute in self.DOMInterface) {
			defineProperty(progress, attribute, {
				get: self.DOMInterface[attribute].get,
				set: self.DOMInterface[attribute].set
			});
		}
		
		self.redraw(progress);
	},
	
	// Live NodeList, will update automatically
	progresses: document.getElementsByTagName('progress')
};



for(var i=self.progresses.length-1; i>=0; i--) {
	self.init(self.progresses[i]);
}

// Take care of future ones too, if supported
if(document.addEventListener) {
	document.addEventListener('DOMAttrModified', function(evt) {
		var node = evt.target, attribute = evt.attrName;
		
		if(/^progress$/i.test(node.nodeName) && (attribute === 'max' || attribute === 'value')) {
			self.redraw(node);
		}
	}, false);
	
	document.addEventListener('DOMNodeInserted', function(evt) {
		var node = evt.target;
		
		if(/^progress$/i.test(node.nodeName)) {
			self.init(node);
		}
	}, false);
}

})();




© 2015 - 2024 Weber Informatics LLC | Privacy Policy