Skip to content

Commit a28ae43

Browse files
Merge pull request #9 from dutchenkoOleg/master
docs
2 parents 68f8f57 + a25429f commit a28ae43

File tree

4 files changed

+147
-8
lines changed

4 files changed

+147
-8
lines changed

docs/examples/abstract-class.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,32 @@
77
* @version 0.0.1
88
*/
99

10+
// ----------------------------------------
11+
// Imports
12+
// ----------------------------------------
13+
1014
import $ from 'jquery'; // for example
1115
import 'some-jquery-plugin'; // for example
1216
import { WebPluginInterface } from 'web-plugin-interface';
1317

18+
// ----------------------------------------
19+
// Exports
20+
// ----------------------------------------
21+
1422
/**
1523
* @implements WebPluginInterface
1624
*/
1725
export class SomeJqueryPluginAbstract extends WebPluginInterface {
1826
/**
1927
* @param {jQuery} $container
20-
* @param {Object} [customSettings={}]
21-
* @param {Object} [customProps={}]
28+
* @param {Object} [clientSettings={}]
29+
* @param {Object} [clientProps={}]
2230
*/
23-
constructor ($container, customSettings = {}, customProps = {}) {
31+
constructor ($container, clientSettings = {}, clientProps = {}) {
2432
super();
2533
this.$container = $container;
26-
this.customSettings = customSettings;
34+
this.clientSettings = clientSettings;
35+
this.clientProps = clientProps;
2736
this.settings = {};
2837
this.props = {};
2938
this.readyCssClass = 'is-ready';
@@ -55,8 +64,8 @@ export class SomeJqueryPluginAbstract extends WebPluginInterface {
5564
* @protected
5665
*/
5766
_setup () {
58-
this.props = $.extends({}, this.defaultProps, this.customProps);
59-
this.settings = $.extends({}, this.defaultSettings, this.customSettings);
67+
this.props = $.extends({}, this.defaultProps, this.clientProps);
68+
this.settings = $.extends({}, this.defaultSettings, this.clientSettings);
6069

6170
// props example
6271
if (this.props.stopAutoPlayIfOutView) {
@@ -93,9 +102,9 @@ export class SomeJqueryPluginAbstract extends WebPluginInterface {
93102
this._afterInitialize();
94103
}
95104

96-
// ------------------------------
105+
// ***********************************
97106
// Custom extend implemented interface
98-
// ------------------------------
107+
// ***********************************
99108

100109
/**
101110
* @type {boolean}

docs/examples/factory.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
3+
/**
4+
* @module examples/factory
5+
* @description Example of Factories based on SomeJqueryPluginAbstract
6+
* @author OlegDutchenko <[email protected]>
7+
* @version 0.0.1
8+
*/
9+
10+
// ----------------------------------------
11+
// Imports
12+
// ----------------------------------------
13+
14+
import { SomeJqueryPluginAbstract } from './abstract-class';
15+
16+
// ----------------------------------------
17+
// Exports
18+
// ----------------------------------------
19+
20+
// A
21+
export class FactoryA extends SomeJqueryPluginAbstract {
22+
/**
23+
* @type {Object}
24+
*/
25+
get defaultSettings () {
26+
return {
27+
autoplay: false,
28+
speed: 750,
29+
fade: true
30+
}
31+
}
32+
33+
/**
34+
* @type {Object}
35+
*/
36+
get defaultProps () {
37+
return {
38+
stopAutoPlayIfOutView: false
39+
}
40+
}
41+
}
42+
43+
44+
// B
45+
export class FactoryB extends SomeJqueryPluginAbstract {
46+
/**
47+
* @protected
48+
*/
49+
_afterInitialize () {
50+
super._afterInitialize();
51+
// individual extend
52+
// ...
53+
}
54+
55+
/**
56+
* @type {Object}
57+
*/
58+
get defaultSettings () {
59+
return {
60+
speed: 600
61+
}
62+
}
63+
}
64+
65+
// C
66+
// ...

docs/examples/index.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
/**
4+
* @module examples/index
5+
* @description Initialize all factories
6+
* @author OlegDutchenko <[email protected]>
7+
* @version 0.0.1
8+
*/
9+
10+
// ----------------------------------------
11+
// Imports
12+
// ----------------------------------------
13+
14+
import $ from 'jquery';
15+
import 'custom-jquery-methods/fn/has-inited-key'; // optional
16+
import { SomeJqueryPluginAbstract } from './abstract-class';
17+
import * as factory from './factory';
18+
19+
// ----------------------------------------
20+
// Private
21+
// ----------------------------------------
22+
23+
/**
24+
* @param {jQuery} $container
25+
* @param {string} key
26+
* @return {SomeJqueryPluginAbstract}
27+
* @private
28+
*/
29+
function _create ($container, key) {
30+
const {
31+
Factory,
32+
settings: clientSettings = {},
33+
props: clientProps = {}
34+
} = $container.data(key) || {};
35+
36+
if (Factory in factory) {
37+
return new factory[Factory]($container, clientSettings, clientProps);
38+
}
39+
return new SomeJqueryPluginAbstract($container, clientSettings, clientProps);
40+
}
41+
42+
// ----------------------------------------
43+
// Exports
44+
// ----------------------------------------
45+
46+
/**
47+
* @param {jQuery} $containers
48+
*/
49+
export function initialize ($containers) {
50+
$containers.each((i, container) => {
51+
const $container = $(container);
52+
53+
// optional action
54+
// avoid duplicated initializing
55+
if ($container.hasInitedKey('someJqueryPluginIsInitialized')) {
56+
return true;
57+
}
58+
59+
const instance = _create($container, 'initialize-some-jquery-plugin');
60+
instance.initialize();
61+
});
62+
}

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
1. [Interface](./interface.md)
99
1. Code examples
1010
- [examples/abstract-class](./examples/abstract-class.js)
11+
- [examples/factory](./examples/factory.js)
12+
- [examples/index](./examples/index.js)

0 commit comments

Comments
 (0)