Spanish Total.js
English
Documentation For AI agents
Contents

Click actions

The classes and the data attributes that call a function or change the URL on a click, a double click and a right click.

.md GitHub
On this page

The library handles three CSS classes in the whole page, also in elements added later: exec for a click, exec2 for a double click and exec3 for a click with the right button. What happens is written in data- attributes. An introduction with examples is in the guide Click actions.

When a component named exec is declared in the page, it takes over this work and the library does nothing.

API

property

data-exec="name"

Calls a function when an element with the class exec is clicked.

The function receives the element as a jQuery object and the event. The name has the forms of $(selector).EXEC():

NameCalls
FUNC.nameA function found at a path
?/methodA method of the closest plugin
plugin/methodA method of a plugin
@methodA method of the closest component. It receives the component ahead of the element and the event
-component/methodA component method
&commandA command of components
#eventAn event
Call a function
<button id="save" class="exec" data-exec="FUNC.save">Save</button>

<script>
FUNC.save = function(element, e) {
	console.log(element.attr('id'), e.type); // save click
};

ON('ready', () => $('#save').trigger('click'));
</script>
Call the closest component
<ui-component name="box"><button id="close" class="exec" data-exec="@close">Close</button></ui-component>

<script>
COMPONENT('box', function(self) {
	self.close = function(component, element) {
		console.log(component.name, element.attr('id')); // box close
	};
});

setTimeout(() => $('#close').trigger('click'), 300);
</script>
property

data-href="url"

Changes the URL when an element with the class exec is clicked.

The address is passed to REDIRECT(). With data-exec on the same element, the function runs first.

Open a page of the application
<button id="orders" class="exec" data-href="/orders/">Orders</button>

<script>
ROUTE('/orders/', function() {
	console.log('orders'); // orders
});

setTimeout(() => $('#orders').trigger('click'), 300);
</script>
property

data-prevent="true"

Stops the default action of the browser and the propagation of the click.

The values are true and 1. Use it for links and for buttons that submit a form.

A link that calls a function
<a id="help" class="exec" data-exec="FUNC.help" data-prevent="true" href="/help/">Help</a>

<script>
FUNC.help = function(element, e) {
	console.log(e.isDefaultPrevented()); // true
};

ON('ready', () => $('#help').trigger('click'));
</script>
property

data-exec2="name"

Calls a function when an element with the class exec2 is double-clicked.

The names and the arguments are those of data-exec. data-href2 and data-prevent2 work in the same way for the double click.

An element can have both classes, exec and exec2. A click then waits 300 milliseconds, and a double click in that time calls only the function of data-exec2.

A double click
<div id="row" class="exec2" data-exec2="FUNC.open">Row</div>

<script>
FUNC.open = function(element, e) {
	console.log(element.attr('id'), e.type); // row dblclick
};

ON('ready', () => $('#row').trigger('dblclick'));
</script>
property

data-exec3="name"

Calls a function when an element with the class exec3 is clicked with the right button.

The names and the arguments are those of data-exec, and data-href3 changes the URL. The menu of the browser is not displayed.

A menu of your own
<div id="file" class="exec3" data-exec3="FUNC.menu">File</div>

<script>
FUNC.menu = function(element, e) {
	console.log(element.attr('id'), e.isDefaultPrevented()); // file true
};

ON('ready', () => $('#file').trigger('contextmenu'));
</script>
Made in Europe