<commit_before>/*
Combination of button functionality with variable expansion support.

*/

mi2JS.comp.add('base/Button', 'base/Tpl', '',

// component initializer function that defines constructor and adds methods to the prototype 
function(proto, superProto, comp, superComp){

	proto.minClickDelay = 300;

	proto.initTemplate = function(){
		superProto.initTemplate.call(this);
		this.listen(this.el,'click');
	};

	proto.on_click = function(evt){
		if(evt.which != 1) return; // only left click

		var evtNames = [], actions = [], comp, enabled = true;
		var el = evt.target;
		while(true){
			if(this.cancelClick(el)) return;

			if(el.hasAttribute('event')) evtNames.push(el.getAttribute('event'));
			if(el.hasAttribute('action')) actions.push(el.getAttribute('action'));

			if(el == this.el) break;
			el = el.parentNode;
		}

		if(this.__propName) actions.push(this.__propName);

		if(evtNames.length && this.parent.fireEvent){
			var now = Date.now();
			if(this._lastClick && now - this._lastClick < this.minClickDelay) return;	
			this._lastClick = now;

			this.parent.fireEvent(evtNames[0],{
				action:actions[0],
				actions:actions,
				events:evtNames,
				domEvent: evt,
				target: evt.target,
				src:this,
				eventFor: 'parent'
			});
			evt.stop();
			return false;
		}
	};

	proto.cancelClick = function(el){
		
		// if disabled at any level 
		if(el.hasAttribute(mi2JS.disabledAttribute)) return true;
		
		// do not mess with other components
		comp = el.getAttribute('as');
		return (comp && el != this.el && !(comp == 'base/Tpl' || comp =='Base' )); 
	};

});<commit_msg>separate eventData extraction from firing event<commit_after>/*
Combination of button functionality with variable expansion support.

*/

mi2JS.comp.add('base/Button', 'base/Tpl', '',

// component initializer function that defines constructor and adds methods to the prototype 
function(proto, superProto, comp, superComp){

	proto.minClickDelay = 300;

	proto.initTemplate = function(){
		superProto.initTemplate.call(this);
		this.listen(this.el,'click');
	};

	proto.on_click = function(evt){
		if(evt.which != 1) return; // only left click

		var eventData = this.eventData(evt.target, evt);
		if(eventData.cancelClick) return;

		if(eventData.events.length && this.parent.fireEvent){
			var now = Date.now();
			if(this._lastClick && now - this._lastClick < this.minClickDelay) return;	
			this._lastClick = now;

			this.parent.fireEvent(eventData.events[0],eventData);
			evt.stop();
			return false;
		}
	};

	proto.eventData = function(el,evt){
		var evtNames = [], actions = [], comp, cancelClick = false;
		while(true){
			if(this.cancelClick(el)) cancelClick = true;

			if(el.hasAttribute('event')) evtNames.push(el.getAttribute('event'));
			if(el.hasAttribute('action')) actions.push(el.getAttribute('action'));

			if(el == this.el) break;
			el = el.parentNode;
		}

		if(this.__propName) actions.push(this.__propName);
		
		return {
				action:actions[0],
				actions:actions,
				events:evtNames,
				domEvent: evt,
				cancelClick: cancelClick,
				target: el,
				src:this,
				eventFor: 'parent'
			};
	};

	proto.cancelClick = function(el){
		
		// if disabled at any level 
		if(el.hasAttribute(mi2JS.disabledAttribute)) return true;
		
		// do not mess with other components
		comp = el.getAttribute('as');
		return (comp && el != this.el && !(comp == 'base/Tpl' || comp =='Base' )); 
	};

});
{'fraction_non_alphanumeric': 0.15409356725146198, 'fraction_numerical': 0.004678362573099415, 'mean_word_length': 3.852482269503546, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3904130', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1118, 'n_words': 246}