Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

gallery-2010.06.30-19-54 apipkin gallery-progressbar

  • Loading branch information...
commit 46df78aeb7b5a615303705c965c44d83532dd3f0 1 parent 0429047
YUI Builder authored
View
27 src/gallery-progressbar/build.properties
@@ -0,0 +1,27 @@
+# Progressbar Build Properties
+
+# As long as the 'builder' project is cloned to the default folder
+# next to the 'yui3-gallery' project folder, the 'builddir' property does not
+# need to be changed
+#
+# If the 'builder' project is checked out to an alternate location, this
+# property should be updated to point to the checkout location.
+builddir=../../../builder/componentbuild
+
+# The name of the component. E.g. event, attribute, widget
+component=gallery-progressbar
+
+# The list of files which should be concatenated to create the component.
+# NOTE: For a css component (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead.
+# component.jsfiles=progressbar.js, progressbarHelperClass.js, progressbarSubComponentClass.js
+component.jsfiles=progressbar.js
+
+# The list of modules this component requires. Used to set up the Y.add module call for YUI 3.
+component.requires=widget,substitute
+
+# The list of modules this component supersedes. Used to set up the Y.add module call for YUI 3.
+component.supersedes=
+
+# The list of modules that are optional for this module. Used to set up the Y.add module call for YUI 3.
+component.optional=
+
View
7 src/gallery-progressbar/build.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- YUI 3 Gallery Component Build File -->
+<project name="Progressbar" default="local">
+ <description>Progressbar Build File</description>
+ <property file="build.properties" />
+ <import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" />
+</project>
View
128 src/gallery-progressbar/js/progressbar.js
@@ -0,0 +1,128 @@
+ Y.ProgressBar = Y.Base.create('progressBar', Y.Widget, [], {
+
+ currentLabel : '',
+
+ /** set up **/
+ renderUI : function() {
+ this.get('contentBox').append(Y.substitute(this.get('layout'),
+ {sliderClass: this.getClassName('slider'),
+ labelClass : this.getClassName('label')}
+ ));
+ },
+
+ bindUI : function() {
+ this.after('labelChange', this._updateLabel);
+ this.after('progressChange', this._updateBackground);
+ },
+
+ syncUI : function() {
+ this._updateBackground();
+ },
+
+ /** A little bit of sugar **/
+ increment : function(step) {
+ step = step || 1;
+ this.set('progress', this.get('progress') + parseFloat(step,10));
+ return this;
+ },
+
+ update : function(progress) {
+ this.set('progress', progress);
+ return this;
+ },
+
+ setLabelAt : function(position, value) {
+ var label = this.get('label');
+ position = parseFloat(position, 10);
+ label[position] = value;
+ this.set('label', label);
+ return this;
+ },
+
+ removeLabelAt : function(position) {
+ var label = this.get('label');
+ position = parseFloat(position, 10);
+ if(label[position] !== undefined && label[position] !== null) {
+ delete label[position];
+ }
+ this.get('label', label);
+ return this;
+ },
+
+ /** protected updaters **/
+ _updateLabel : function(e) {
+ var attrs = this.getAttrs(),
+ label = this.get('label'),
+ progress = this.get('progress'),
+ keys, labelString;
+
+ if(label[progress] !== undefined && label[progress] !== null) {
+ labelString = label[progress];
+ } else {
+ keys = Y.Object.keys(label);
+ keys.sort(Y.Array.numericSort);
+ var i = -1, l = keys.length;
+ while(++i < l) {
+ if(keys[i] <= progress) {
+ labelString = label[keys[i]];
+ }
+ }
+ }
+ attrs.label = labelString || '';
+ this.get('contentBox').one('.' + this.getClassName('label')).set('text', Y.substitute(this.get('labelTemplate'), attrs ));
+ },
+
+ _updateBackground : function(e) {
+ var slider = this.get('contentBox').one('.' + this.getClassName('slider')),
+ position = slider.get('offsetWidth') * this.get('progress') / 100;
+
+ slider.setStyle('backgroundPosition', position + 'px center');
+
+ this._updateLabel();
+ }
+
+ }, {
+ ATTRS : {
+ labelTemplate : {
+ value : '{label} - {progress}%'
+ },
+
+ label : {
+ value : {0:'Loading', 100:'Complete'},
+ validator : function(val){
+ return (Y.Lang.isString(val) || Y.Lang.isObject(val));
+ },
+ setter : function(val) {
+ if(Y.Lang.isString(val)) {
+ val = {0:val};
+ }
+ return val;
+ }
+ },
+
+ layout : {
+ value : '<div class="{sliderClass} {labelClass}"></div>'
+ },
+
+ precision : {
+ value : 2,
+ setter : function(val) {
+ return parseInt(val,10);
+ }
+ },
+
+ progress : {
+ value : 0,
+ setter : function(val) {
+ var precision = Math.pow(10,this.get('precision'));
+ val = parseFloat(val,10);
+ if(val < 0) {
+ val = 0;
+ } else if(val > 100) {
+ val = 100;
+ }
+ return Math.round(val * precision) / precision;
+ }
+ }
+ }
+ });

0 comments on commit 46df78a

Please sign in to comment.
Something went wrong with that request. Please try again.