Titanium Countdown class displays (and updates) time left provided by user. Time can be provided in any time units, and they will be recalculated to specified time units. It is possible to specify which units or text will appear in countdown and which text must be hidden if certain unit reaches 0 by using labels for each time unit.

Package contains countdown.js and app.js for example usage.

Contents

Download

Example codes

//create label function
var createLabel = function(y, text){
	text = (typeof text == "undefined") ? "" : text;
	return Titanium.UI.createLabel({
		color:"#fff",
		text:text,
		top: y,
		font:{fontSize:20,fontFamily:"Helvetica Neue"},
		textAlign:"center",
		width:"auto"
	});
};
//create window
var win1 = Titanium.UI.createWindow({  
    title:"Countdown",
    backgroundColor: "#000",
    modal: true
});
//year label
var year = createLabel(20,"There are {y} years and");
win1.add(year);

//months label
var month = createLabel(50,"{m} months");
win1.add(month);

//months label
var week = createLabel(80,"{w} weeks");
win1.add(week);

//months label
var day = createLabel(110,"{d} days");
win1.add(day);

//months label
var hour = createLabel(140,"{h} hours");
win1.add(hour);

//months label
var min = createLabel(170,"{i} minutes");
win1.add(min);

//months label
var sec = createLabel(200,"{s} seconds");
win1.add(sec);

//create countdown
var countdown = require("countdown");
var cd = new countdown({
	//provide time
	//here for example 2 years
	year: 2,
	sec: 5,
	//provide lables for outputing
	//each specific time unit
	label_year: year,//years
	label_month: month,//months
	label_week: week,//weeks
	label_day: day,//days
	label_hour: hour,//hours
	label_min: min,//minutes
	label_sec: sec,//seconds
	//on end event callback
	onend: function(){alert("That's it");}
});

Examples video

Method list

Constructor

Back to method list

Method namenew countdown(config)
DescriptionCreates class instance with provided configuration
Input parameters

json config - json structure with configuration:

  • int time - timestamp to the target date, provide target timestamp, of units left in parameters below(default: 0)
  • int year - how many years have left till countdown ends, if timestamp not provided (default: 0)
  • int month - how many months have left till countdown ends, if timestamp not provided (default: 0)
  • int week - how many weeks have left till countdown ends, if timestamp not provided (default: 0)
  • int day - how many days have left till countdown ends, if timestamp not provided (default: 0)
  • int hour - how many hours have left till countdown ends, if timestamp not provided (default: 0)
  • int min - how many minutes have left till countdown ends, if timestamp not provided (default: 0)
  • int sec - how many seconds have left till countdown ends, if timestamp not provided (default: 0)
  • label label_year - label where to display years, if not provided, years will be recalculated to lesser units. If additional text should appear with year units, provide it as label's text in this format 'Some text {y} more text' (default: none)
  • label label_month - label where to display months, if not provided, months will be recalculated to lesser units. If additional text should appear with months units, provide it as label's text in this format 'Some text {m} more text' (default: none)
  • label label_week - label where to display weeks, if not provided, weeks will be recalculated to lesser units. If additional text should appear with weeks units, provide it as label's text in this format 'Some text {w} more text' (default: none)
  • label label_day - label where to display days, if not provided, days will be recalculated to lesser units. If additional text should appear with days units, provide it as label's text in this format 'Some text {d} more text' (default: none)
  • label label_hour - label where to display hours, if not provided, hours will be recalculated to lesser units. If additional text should appear with hour units, provide it as label's text in this format 'Some text {h} more text' (default: none)
  • label label_min - label where to display minutes, if not provided, minutes will be recalculated to lesser units. If additional text should appear with minute units, provide it as label's text in this format 'Some text {i} more text' (default: none)
  • label label_sec - label where to display seconds, if not provided, seconds will be recalculated to lesser units. If additional text should appear with second units, provide it as label's text in this format 'Some text {s} more text' (default: none)
  • label end - label to make visible after countdown ended (default: none)
  • bool hide_zeros - hide highest units that have reached zero, for example hides '0' years in '0 years 2 days 3 hours 4 secons' (default: 'true')
  • bool leading_zeros - display leading zeros for hours, minutes and seconds, when their value < 10 (default: 'true')
  • function onstep - callback function which is called every second and provides how many seconds is left (till countdown end) as function parameter
  • function onend - callback function which is called when countdown is ended

Start countdown

Back to method list

Method namestart()
DescriptionStart countdown if countdown was stopped

Stop countdown

Back to method list

Method namestop()
DescriptionStop countdown

Latest changes

None for now