2017 © Pedro Peláez
 

yii2-extension yii2-jqhooks

Yii2 jQuery action hooks

image

dlds/yii2-jqhooks

Yii2 jQuery action hooks

  • Tuesday, February 7, 2017
  • by dlds
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,096 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 7 % Grown

The README.md

jQuery action hooks

Action hooks is simple jQuery helper library. Used when jQuery operation like show, hide, toggle, ... are required to attach with conditional ability., (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

$ composer require dlds/yii2-jqhooks

or add, (*4)

"dlds/yii2-jqhooks": "~1.0"

to the require section of your composer.json file., (*5)

Usage

You want to show 'overlay' html element when user clicks on 'trigger' html element. With Action hooks you have to do:, (*6)

  1. Register hook, (*7)

    <div class="my-custom-overlay-class" data-hook="overlay"></div>
    
  2. Register trigger, (*8)

    <a class="my-custom-trigger-class" data-had="{"click":[["show","overlay"]]}"></div>
    

Each registered hook must have data-hook="{hookName}" attribute. Each trigger element must have data-had="{hookActionDefinition}" attribute, (*9)

Format

Hook action definition (data-had) format:, (*10)

{
  'jqEevent' => [
    ['hookActionName' 'hookName', 'hookActionCondition'],
  ]
}

Attributes

  1. jqEvent is classic jQuery event like 'change', 'click', ...
  2. hookActionName is jqhooks aciton method name (doClose, doOpen, doToggle, ...).
  3. hookName is custom string which reflects value of 'data-hook' attr assigned to target element
  4. hookActionCondition callback or simple fn definition which will be processed as js function. This condition allows you to define when the action will be processed.

Actions

  1. doOpen add class 'open' to hooked element
  2. doClose remove class 'open' to hooked element
  3. doShow shows hooked element (calls $.show())
  4. doHide hides hooked element (calls $.hide())
  5. doToggle toggles hooked element (calls $.toggle())
  6. doCheck adds property 'checked=true' to hooked element
  7. doUncheck rmeoves property 'checked=true' to hooked element

Ternary usage

You can specify ternary condition like following:, (*11)

{
  'click' => [
      ['show:hide' 'overlay', 'return this.val() === 1'],
  ]
}

This definitios runs 'show' action if clicked element value === 1 otherwise it runs 'hide' action., (*12)

Helper

You can simple use JqHooks::attach() which registeres proper js and runs initialization on document ready., (*13)

JqHooks::attach([
  'click' => [
      ['show:hide' 'overlay', 'return this.val() === 1'],
  ]
])

The Versions

07/02 2017

dev-master

9999999-dev

Yii2 jQuery action hooks

  Sources   Download

BSD

The Requires

 

The Development Requires

by Jiri Svoboda

helpers yii2 jquery

07/02 2017

2.0

2.0.0.0

Yii2 jQuery action hooks

  Sources   Download

BSD

The Requires

 

The Development Requires

by Jiri Svoboda

helpers yii2 jquery

23/12 2016

1.5

1.5.0.0

Yii2 jQuery action hooks

  Sources   Download

BSD

The Requires

 

The Development Requires

by Jiri Svoboda

helpers yii2 jquery

20/12 2016

1.4

1.4.0.0

Yii2 jQuery action hooks

  Sources   Download

BSD

The Requires

 

The Development Requires

by Jiri Svoboda

helpers yii2 jquery

13/12 2016

1.3

1.3.0.0

Yii2 jQuery action hooks

  Sources   Download

BSD

The Requires

 

The Development Requires

by Jiri Svoboda

helpers yii2 jquery

12/12 2016

1.2

1.2.0.0

Yii2 jQuery action hooks

  Sources   Download

BSD

The Requires

 

The Development Requires

by Jiri Svoboda

helpers yii2 jquery

10/11 2016

1.1

1.1.0.0

Yii2 jQuery action hooks

  Sources   Download

BSD

The Requires

 

The Development Requires

by Jiri Svoboda

helpers yii2 jquery

10/11 2016

1.0

1.0.0.0

Yii2 jQuery action hooks

  Sources   Download

BSD

The Requires

 

The Development Requires

by Jiri Svoboda

helpers yii2 jquery