Skip to content

Commit caecb1c

Browse files
committed
remove hook system
1 parent 818ba3c commit caecb1c

File tree

5 files changed

+3
-152
lines changed

5 files changed

+3
-152
lines changed

public/index.html

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -437,17 +437,6 @@ <h2>Public methods</h2>
437437
Selectric.init(); // Reinitialize the plugin</code></pre>
438438
</div>
439439

440-
<div class="section">
441-
<h2>Hooks</h2>
442-
443-
<p>Check <a href="plugins/jquery.selectric.placeholder.js">jquery.selectric.placeholder.js</a> source for a usage example</p>
444-
<pre><code class="language-javascript">// Add a callback everytime '<i>callbackName</i>' is called
445-
$.fn.selectric.hooks.add('<i>callbackName</i>', '<i>hookName</i>', function(element, data) {});
446-
447-
// Remove a callback
448-
$.fn.selectric.hooks.remove('<i>callbackName</i>', '<i>hookName</i>');</code></pre>
449-
</div>
450-
451440
<div class="section">
452441
<h2>Browser support</h2>
453442

public/jquery.selectric.js

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
},
192192

193193
/**
194-
* Calls the events and hooks registered with function name.
194+
* Calls the events registered with function name.
195195
*
196196
* @param {string} fn - The name of the function.
197197
* @param {number} scope - Scope that should be set on the function.
@@ -205,12 +205,6 @@
205205
func.apply(elm, args);
206206
}
207207

208-
if ( $.fn[pluginName].hooks[fn] ) {
209-
$.each($.fn[pluginName].hooks[fn], function() {
210-
this.apply(elm, args);
211-
});
212-
}
213-
214208
$(elm).trigger(pluginName + '-' + this.toDash(fn), args);
215209
},
216210

@@ -1056,38 +1050,6 @@
10561050
});
10571051
};
10581052

1059-
/**
1060-
* Hooks for the callbacks
1061-
*
1062-
* @type {object}
1063-
*/
1064-
$.fn[pluginName].hooks = {
1065-
/**
1066-
* @param {string} callbackName - The callback name.
1067-
* @param {string} hookName - The name of the hook to be attached.
1068-
* @param {function} fn - Callback function.
1069-
*/
1070-
add: function(callbackName, hookName, fn) {
1071-
if ( !this[callbackName] ) {
1072-
this[callbackName] = {};
1073-
}
1074-
1075-
this[callbackName][hookName] = fn;
1076-
1077-
return this;
1078-
},
1079-
1080-
/**
1081-
* @param {string} callbackName - The callback name.
1082-
* @param {string} hookName - The name of the hook that will be removed.
1083-
*/
1084-
remove: function(callbackName, hookName) {
1085-
delete this[callbackName][hookName];
1086-
1087-
return this;
1088-
}
1089-
};
1090-
10911053
/**
10921054
* Default plugin options
10931055
*

public/jquery.selectric.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.selectric.js

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
},
175175

176176
/**
177-
* Calls the events and hooks registered with function name.
177+
* Calls the events registered with function name.
178178
*
179179
* @param {string} fn - The name of the function.
180180
* @param {number} scope - Scope that should be set on the function.
@@ -188,12 +188,6 @@
188188
func.apply(elm, args);
189189
}
190190

191-
if ( $.fn[pluginName].hooks[fn] ) {
192-
$.each($.fn[pluginName].hooks[fn], function() {
193-
this.apply(elm, args);
194-
});
195-
}
196-
197191
$(elm).trigger(pluginName + '-' + this.toDash(fn), args);
198192
},
199193

@@ -1039,38 +1033,6 @@
10391033
});
10401034
};
10411035

1042-
/**
1043-
* Hooks for the callbacks
1044-
*
1045-
* @type {object}
1046-
*/
1047-
$.fn[pluginName].hooks = {
1048-
/**
1049-
* @param {string} callbackName - The callback name.
1050-
* @param {string} hookName - The name of the hook to be attached.
1051-
* @param {function} fn - Callback function.
1052-
*/
1053-
add: function(callbackName, hookName, fn) {
1054-
if ( !this[callbackName] ) {
1055-
this[callbackName] = {};
1056-
}
1057-
1058-
this[callbackName][hookName] = fn;
1059-
1060-
return this;
1061-
},
1062-
1063-
/**
1064-
* @param {string} callbackName - The callback name.
1065-
* @param {string} hookName - The name of the hook that will be removed.
1066-
*/
1067-
remove: function(callbackName, hookName) {
1068-
delete this[callbackName][hookName];
1069-
1070-
return this;
1071-
}
1072-
};
1073-
10741036
/**
10751037
* Default plugin options
10761038
*

test/events.spec.js

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -122,68 +122,6 @@ describe('events', function() {
122122
expect(callbacks.refresh).toHaveBeenCalled();
123123
});
124124

125-
it('should trigger hooks callbacks', function() {
126-
var hooks = jasmine.createSpyObj('hooks', [
127-
'beforeInit',
128-
'init',
129-
'beforeOpen',
130-
'open',
131-
'beforeClose',
132-
'close',
133-
'beforeChange',
134-
'change',
135-
'refresh'
136-
]);
137-
138-
select.selectric('destroy');
139-
$.fn.selectric.hooks.add('BeforeInit', 'test', hooks.beforeInit);
140-
$.fn.selectric.hooks.add('BeforeInit', 'test2', hooks.beforeInit);
141-
$.fn.selectric.hooks.add('BeforeInit', 'test3', hooks.beforeInit);
142-
$.fn.selectric.hooks.remove('BeforeInit', 'test3');
143-
$.fn.selectric.hooks.add('Init', 'test', hooks.init);
144-
$.fn.selectric.hooks.add('BeforeOpen', 'test', hooks.beforeOpen);
145-
$.fn.selectric.hooks.add('Open', 'test', hooks.open);
146-
$.fn.selectric.hooks.add('BeforeClose', 'test', hooks.beforeClose);
147-
$.fn.selectric.hooks.add('Close', 'test', hooks.close);
148-
$.fn.selectric.hooks.add('BeforeChange', 'test', hooks.beforeChange);
149-
$.fn.selectric.hooks.add('Change', 'test', hooks.change);
150-
$.fn.selectric.hooks.add('Refresh', 'test', hooks.refresh);
151-
select.selectric();
152-
153-
$('.selectric').click();
154-
$('.selectric-items').find('li:eq(4)').click();
155-
select.selectric('refresh');
156-
157-
expect(hooks.beforeInit).toHaveBeenCalledTimes(2);
158-
expect(hooks.init).toHaveBeenCalled();
159-
expect(hooks.beforeOpen).toHaveBeenCalled();
160-
expect(hooks.open).toHaveBeenCalled();
161-
expect(hooks.beforeClose).toHaveBeenCalled();
162-
expect(hooks.close).toHaveBeenCalled();
163-
expect(hooks.beforeChange).toHaveBeenCalled();
164-
expect(hooks.change).toHaveBeenCalled();
165-
expect(hooks.refresh).toHaveBeenCalled();
166-
});
167-
168-
it('should allow to chain hooks', function() {
169-
var hooks = jasmine.createSpyObj('hooks', [
170-
'beforeInit'
171-
]);
172-
173-
select.selectric('destroy');
174-
$.fn.selectric.hooks
175-
.add('BeforeInit', 'test', hooks.beforeInit)
176-
.add('BeforeInit', 'test2', hooks.beforeInit);
177-
select.selectric();
178-
179-
$('.selectric').click();
180-
$('.selectric-items').find('li:eq(4)').click();
181-
select.selectric('refresh');
182-
183-
expect(hooks.beforeInit).toHaveBeenCalledTimes(2);
184-
185-
});
186-
187125
it('should not bind events when select is disabled after init', function() {
188126
select.prop('disabled', true).selectric('refresh');
189127
$('.selectric').trigger('click');

0 commit comments

Comments
 (0)