Javascript API - krunchness/CMB2 GitHub Wiki

Table of Contents generated with DocToc

TODO

  • Document unhooking CMB2 event callbacks.
  • Document using various CMB2 custom event callbacks.
  • Document overriding (date/time/color) Picker options.
  • Document log method.
  • Document media modal override options.

Triggered Events

CMB2 has several events that get triggered during various client-side interactions. Some events are triggered directly on the document object, and some are triggered on specific elements. As with all jQuery event callbacks, the first parameter sent to the callback is the event object, but with the CMB2 events, other parameters are also provided, including the CMB2 object. Source: js/cmb2.js

cmb_pre_init


Triggered before CMB2 starts setting up its functionality, on the document ready event.

cmb_init


Triggered when CMB2 finishes setting up its functionality, on the document ready event. If you want to add functionality related to CMB2's other events, this is the best event to hook into to ensure CMB2 is setup/ready.

postbox-toggled


Triggered when the metabox is expanded/collopsed, and borrows the event name from the core WordPress metabox Javascript. The .postbox element that was toggled is passed to the callback as the 2nd parameter.

cmb_media_modal_init


Triggered when a WordPress media modal instance is created to handle the various CMB2 media file types. Is also passed the CMB2.media object (as well as the default CMB2 object).

cmb_media_modal_select


Triggered when a selection is made inside the CMB2 media modal instance. Is also passed the current selection object, and the CMB2.media object (as well as the default CMB2 object).

cmb_media_modal_open


Triggered when a CMB2 media modal instance is opened. Is also passed the current selection object, and the CMB2.media object (as well as the default CMB2 object).

cmb2_add_group_row_start


Triggered when the 'Add group row' button is clicked, before CMB2 performs its actions. Is triggered on the 'add group row' buton (.cmb-add-group-row), as well as passed that button element.

cmb2_add_row


Triggered when the 'Add row'/'Add group row' buttons are clicked. Is triggered on the CMB2 Group element (.cmb-repeatable-group). The callback event will have a group property to determine if event was triggered on the 'Add row' or the 'Add group row' button. Also passed the new row jQuery element object.

cmb2_remove_group_row_start


Triggered when the 'Remove group row' button is clicked, before CMB2 performs its actions. Is triggered on the CMB2 Group element (.cmb-repeatable-group), and is passed the 'remove group row' button.

cmb2_remove_row


Triggered when the 'Remove row'/'Remove group row' buttons are clicked. Is triggered on the CMB2 Group element (.cmb-repeatable-group). The callback event will have a group property to determine if event was triggered on the 'Remove row' or the 'Remove group row' button.

cmb2_shift_rows_enter


Triggered when the 'move up'/'move down' buttons are clicked, before CMB2 performs its actions (before shift occurs). Is triggered on the button element (.cmb-shift-rows'). The callback event will be passed the jQuery button element, the jQuery "from" element (the element to be moved), and the jQuery "to" element (the element to be replaced/moved).

cmb2_shift_rows_start


Triggered when the 'move up'/'move down' buttons are clicked, before CMB2 performs its actions (before the shift, but confirmed shift should occur). Is triggered on the button element (.cmb-shift-rows'). The callback event will be passed the jQuery button element, the jQuery "from" element (the element to be moved), and the jQuery "to" element (the element to be replaced/moved).

cmb2_shift_rows_complete


Triggered when the 'move up'/'move down' buttons are clicked, after CMB2 performs its actions (shift is complete). Is triggered on the button element (.cmb-shift-rows'). The callback event will be passed the jQuery button element, the jQuery "from" element (the element to be moved), and the jQuery "to" element (the element to be replaced/moved).