Skip to content

Commit efe375d

Browse files
authored
Merge pull request #140 from gearsdigital/feature/remove-hook-system
Feature/remove hook system (#134)
2 parents f728697 + 05f6bba commit efe375d

File tree

5 files changed

+9
-158
lines changed

5 files changed

+9
-158
lines changed

public/customoptions.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
.selectric-customOptions .ico {
1+
.selectric-custom-options .ico {
22
display: inline-block;
33
vertical-align: middle;
44
zoom: 1;
55
*display: inline;
66
height: 30px;
77
width: 30px;
88
margin: 0 6px 0 0;
9-
background: url(img/browser-icons.png) no-repeat;
9+
background: url(./img/browser-icons.png) no-repeat;
1010
}
1111

12-
.selectric-customOptions .ico-chrome { background-position: 0 0; }
13-
.selectric-customOptions .ico-firefox { background-position: -30px 0; }
14-
.selectric-customOptions .ico-ie { background-position: -60px 0; }
15-
.selectric-customOptions .ico-opera { background-position: -90px 0; }
16-
.selectric-customOptions .ico-safari { background-position: -120px 0; }
12+
.selectric-custom-options .ico-chrome { background-position: 0 0; }
13+
.selectric-custom-options .ico-firefox { background-position: -30px 0; }
14+
.selectric-custom-options .ico-ie { background-position: -60px 0; }
15+
.selectric-custom-options .ico-opera { background-position: -90px 0; }
16+
.selectric-custom-options .ico-safari { background-position: -120px 0; }

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

@@ -1060,38 +1054,6 @@
10601054
});
10611055
};
10621056

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

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

@@ -1043,38 +1037,6 @@
10431037
});
10441038
};
10451039

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

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)