Skip to content

Commit e49383e

Browse files
author
dutchenkoOleg
committed
docs
1 parent 96a718f commit e49383e

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed

docs/examples/abstract-class.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ import { WebPluginInterface } from 'web-plugin-interface';
2525
export class SomeJqueryPluginAbstract extends WebPluginInterface {
2626
/**
2727
* @param {jQuery} $container
28-
* @param {Object} [customSettings={}]
29-
* @param {Object} [customProps={}]
28+
* @param {Object} [clientSettings={}]
29+
* @param {Object} [clientProps={}]
3030
*/
31-
constructor ($container, customSettings = {}, customProps = {}) {
31+
constructor ($container, clientSettings = {}, clientProps = {}) {
3232
super();
3333
this.$container = $container;
34-
this.customSettings = customSettings;
34+
this.clientSettings = clientSettings;
35+
this.clientProps = clientProps;
3536
this.settings = {};
3637
this.props = {};
3738
this.readyCssClass = 'is-ready';
@@ -63,8 +64,8 @@ export class SomeJqueryPluginAbstract extends WebPluginInterface {
6364
* @protected
6465
*/
6566
_setup () {
66-
this.props = $.extends({}, this.defaultProps, this.customProps);
67-
this.settings = $.extends({}, this.defaultSettings, this.customSettings);
67+
this.props = $.extends({}, this.defaultProps, this.clientProps);
68+
this.settings = $.extends({}, this.defaultSettings, this.clientSettings);
6869

6970
// props example
7071
if (this.props.stopAutoPlayIfOutView) {

docs/examples/factory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

33
/**
4-
* @module examples/abstract-class
5-
* @description Abstract class example with WebPluginInterface implementation
4+
* @module examples/factory
5+
* @description Example of Factories based on SomeJqueryPluginAbstract
66
* @author OlegDutchenko <[email protected]>
77
* @version 0.0.1
88
*/

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+
}

0 commit comments

Comments
 (0)