@@ -17,7 +17,7 @@ Install from [NPM](https://nodei.co/npm/gpslab-controller/):
1717$ npm install gpslab-controller
1818```
1919
20- Or download the script [ here] ( https://github.com/gpslab/gpslab-controller/blob/master/src /controller.js ) and include it (unless you are packaging scripts somehow else):
20+ Or download the script [ here] ( https://github.com/gpslab/gpslab-controller/blob/master/dist /controller.min .js ) and include it (unless you are packaging scripts somehow else):
2121
2222``` html
2323<script src =" /path/to/controller.js" ></script >
@@ -26,9 +26,14 @@ Or download the script [here](https://github.com/gpslab/gpslab-controller/blob/m
2626Or include it via [ jsDelivr CDN] ( https://www.jsdelivr.com/package/npm/gpslab-controller ) :
2727
2828``` html
29- <script src =" https://cdn.jsdelivr.net/npm/gpslab-controller@2/src /controller.js" ></script >
29+ <script src =" https://cdn.jsdelivr.net/npm/gpslab-controller@2/dist /controller.min .js" ></script >
3030```
3131
32+ ## ECMAScript 2016
33+
34+ This framework is written for ECMAScript 2016, but you can use the recompiled version for
35+ [ ECMAScript 2015] ( dist/controller.es2015.min.js ) .
36+
3237## Methods
3338
3439The library exposes these methods: ` registerControl() ` , ` registerControls() ` , ` singleBind() ` , ` bind() ` .
@@ -68,7 +73,7 @@ Binding the control for single specific element.
6873
6974#### Arguments
7075
71- 1 . ` element ` (** HTMLElement ** ) HTMLElement for binding.
76+ 1 . ` element ` (** Element ** ) Element for binding.
7277
7378#### Returns
7479
@@ -82,7 +87,7 @@ Find the controls in element and children elements and binding it.
8287
8388#### Arguments
8489
85- 1 . ` element ` (** ?HTMLElement ** ) HTMLElement for binding. The ` BODY ` element as a default .
90+ 1 . ` element ` (** Element ** ) Element for binding.
8691
8792#### Returns
8893
@@ -94,10 +99,10 @@ Create new control for bind [the jQuery datepicker](https://jqueryui.com/datepic
9499controller:
95100
96101``` js
97- Controller .registerControl (' form- date' , element => $ (element).datepicker ({dateFormat: ' yy-mm-dd' }));
102+ Controller .registerControl (' date-picker ' , element => $ (element).datepicker ({dateFormat: ' yy-mm-dd' }));
98103
99104document .addEventListener (' DOMContentLoaded' , function () {
100- Controller .bind () ; // bind datepicker control
105+ Controller .bind (document . getElementsByTagName ( ' body ' ). item ( 0 )) ; // find input and bind datepicker control to it
101106});
102107```
103108
@@ -106,7 +111,7 @@ Use in HTML:
106111``` html
107112<form >
108113 <!-- after document loaded Datepicker will be binded to this element -->
109- <input type =" date" name =" date" data-control =" form- date" >
114+ <input type =" date" name =" date" data-control =" date-picker " >
110115 <button type =" submit" >Submit</button >
111116</form >
112117```
@@ -119,7 +124,7 @@ You can bind controls for a new added elements:
119124const input = document .createElement (' input' );
120125input .setAttribute (' type' , ' date' );
121126input .setAttribute (' name' , ' date' );
122- input .setAttribute (' data-control' , ' form- date' );
127+ input .setAttribute (' data-control' , ' date-picker ' );
123128
124129// add element to document first
125130// sometimes controls incorrectly works if you binding them before add element to a document
@@ -137,18 +142,28 @@ Use spaces (` `) or commas (`,`) for separate control names in the `data` attrib
137142
138143``` html
139144<form >
140- <input
141- type =" date"
142- name =" date"
143- required =" required"
144- data-control =" form-date form-required form-related"
145- data-related-target =" #date_related"
146- >
147- <input type =" date" name =" date_related" data-control =" form-date" id =" date_related" >
145+ <!-- set password and repeat it for sign up -->
146+ <input type =" password" name =" password" required =" required" data-control =" show-password input-equal-to" data-equal-to =" #repeat_password" >
147+ <input type =" password" name =" repeat_password" required =" required" data-control =" show-password" id =" repeat_password" >
148148 <button type =" submit" >Submit</button >
149149</form >
150150```
151151
152+ ``` js
153+ Controller .registerControl (' input-equal-to' , element => {
154+ const target = document .querySelectorAll (element .getAttribute (' data-equal-to' ));
155+ // check that value of input element equal to value of target element
156+ });
157+ Controller .registerControl (' show-password' , element => {
158+ // for example, you can add button for show password
159+ });
160+
161+ // bind all controls for all elements
162+ document .addEventListener (' DOMContentLoaded' , function () {
163+ Controller .bind (document .getElementsByTagName (' body' ).item (0 ));
164+ });
165+ ```
166+
152167### Use classes for controls
153168
154169It will be better create new classes for define control and encapsulate all logic in them:
@@ -193,10 +208,10 @@ class AppendControl {
193208}
194209
195210Controller .registerControls ({
196- ' form- date' : element => $ (element).datepicker ({dateFormat: ' yy-mm-dd' }),
211+ ' date-picker ' : element => $ (element).datepicker ({dateFormat: ' yy-mm-dd' }),
197212 ' append ' : element => new AppendControl (element),
198213});
199- Controller .bind ();
214+ Controller .bind (document . getElementsByTagName ( ' body ' )[ 0 ] );
200215```
201216
202217Use in HTML:
@@ -205,10 +220,22 @@ Use in HTML:
205220<button
206221 type =" button"
207222 data-control =" append"
208- data-prototype =" <input type='date' name='date' data-control='form- date' / >"
223+ data-prototype =" <input type='date' name='date' data-control='date-picker' >"
209224>Append</button >
210225```
211226
227+ ## Building
228+
229+ For contributors:
230+
231+ * Run ` npm install ` to install all the dependencies.
232+ * Run ` gulp ` . The default task will build minify files.
233+
234+ For repo owners, after a code change:
235+
236+ * Run ` npm version ` to tag the new release.
237+ * Run ` npm login ` , ` npm publish ` to release on npm.
238+
212239## License
213240
214241This bundle is under the [ MIT license] ( http://opensource.org/licenses/MIT ) . See the complete license in the file: LICENSE
0 commit comments