Sha256: 26138d5939c4ee865f4509274bde751e40bd8c58401edb1ec6e64914b643c95e
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
///- - - - - - - - - - - - - - - - - - - - /// FORM ITEM ///- - - - - - - - - - - - - - - - - - - - class FormItem { constructor() { this.target = '.form-item' } isSet() { if ( $( this.target ).length > 0 ) { return true } else { return false } } setEvents() { $(document).on('click', this.target + '--add-new', addNewItem ) $(document).on('click', '.form-item--remove-item-with-js', function( event ) { // Stop default behaviour event.preventDefault() $( this ).parent( this.target ).remove() }) $(document).on('click', '.form-item--open-button, .form-item--close-button', function() { $( this ).parent('.form-item').children('.form-item--editor').toggleClass('form-item--editor-close') $( this ).parent('.form-item').children('.form-item--open-button, .form-item--close-button').toggle() }) } } export let _FormItem = new FormItem() ///- - - - - - - - - - - - - - - - - - - - /// COMPONENT HELPER FUNCTIONS ///- - - - - - - - - - - - - - - - - - - - function addNewItem( event ) { // Stop default behaviour event.preventDefault() // Get the child to clone let id = $( event.target ).data( 'new-child-id' ) let $newChild = $( '#' + id ) // Clone child and remove id and styles from cloned child $newChild.clone().insertAfter( $newChild ) $newChild.removeClass( 'form-item--new' ).removeAttr( 'id' ) }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
binda-0.0.3 | app/assets/javascripts/binda/components/form_item.js |
binda-0.0.2 | app/assets/javascripts/binda/components/form_item.js |