Edit this page

up.script up.$macro(selector, options, macro)
JavaScript function

This feature has been deprecated. Use up.macro() with a callback that wraps the given native element in a jQuery collection.

Load unpoly-migrate.js to polyfill deprecated features.

Registers a compiler that is run before all other compilers. The compiler function is called with each matching element as a jQuery object.

If you're not using jQuery, use up.macro() instead, which calls the macro function with a native element.

Example

up.$macro('[content-link]', function($link) {
  $link.attr(
    'up-target': '.content',
    'up-transition': 'cross-fade',
    'up-duration':'300'
  )
})

Parameters

selector
required

The selector to match.

string
macro
required

The function to call when an element matching selector is inserted.

Up to three arguments can be accepted:

  1. The newly inserted element matching the selector
  2. Any data attached to the element
  3. Meta information about the current render pass

The function may return a destructor function that is called before it is removed from the DOM. The destructor function is called with the compiled element.

The compiler function can be async.

Function($element, data)