User:ChaoticShadow/common.js

mw.loader.using( 'oojs-ui-core' ).done( function {	$( function  { function update(val) { $( '#result-oo' ).html(val); }		var input1 = new OO.ui.NumberInputWidget( {			min: 1,			max: 10,			step: 1		}); var input2 = new OO.ui.NumberInputWidget( {			min: 0,			max: 50,			step: 5		}); var val1 = 1; var val2 = 0; var sum = val1 + val2; input1.on('change', function(val) {			val1 = Number(val);			sum = val1 + val2;			update(sum);		}); input2.on('change', function(val) {			val2 = Number(val);			sum = val1 + val2;			update(sum);		}); $( '#test-oo' ).append(			input1.$element,			input2.$element		); }); });

(function (jQuery) {	function calcDiff(d1, d2) {		var remDiff = d2 - d1;		var days = Math.floor(remDiff / (1000*60*60*24));		remDiff = remDiff % (1000*60*60*24);		var hours = Math.floor(remDiff / (1000*60*60));		remDiff = remDiff % (1000*60*60);		var minutes = Math.floor(remDiff / (1000*60));		return { days: days, hours: hours, minutes: minutes };	}	var intervals = [];	jQuery('.timer').each(function(idx) { var that = $(this); var d1 = new Date(that.attr('data-attr-end')); function update { var diff = calcDiff(new Date, d1); that.html(				diff.days + ' days, ' + 				diff.hours + ' hours, ' +				diff.minutes + ' minutes'			); if (diff.days <= 0 && diff.hours <= 0 && diff.minutes <= 0) { intervals[idx] = clearInterval(intervals[idx]); that.html('over'); }		}		update; var interval = setInterval(function {			// console.log(calcDiff(new Date, d1))			console.log(idx, 'i am updating');			update;		}, 30000); intervals.push(interval); });

})(jQuery)