8000 Merge pull request #288 from mako-taco/dev · gfranko/jquery.selectBoxIt.js@f6bda73 · GitHub
[go: up one dir, main page]

Skip to content

Commit f6bda73

Browse files
committed
Merge pull request #288 from mako-taco/dev
Resolves #286 - Added dontCopyAttributes w/ data-reactid
2 parents 3c501b0 + 840cce5 commit f6bda73

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

src/javascripts/jquery.selectBoxIt.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@
100100
"rel"
101101

102102
],
103+
104+
// **dontCopyAttributes: HTML attributes to explicitly blacklist from being copied to the new dropdown
105+
"dontCopyAttributes": [
106+
107+
"data-reactid"
108+
109+
],
103110

104111
// **copyClasses**: HTML classes that will be copied over to the new drop down. The value indicates where the classes should be copied. The default value is 'button', but you can also use 'container' (recommended) or 'none'.
105112
"copyClasses": "button",
@@ -1805,6 +1812,7 @@
18051812
// Stores the plugin prototype object in a local variable
18061813
var selectBoxIt = $.selectBox.selectBoxIt.prototype;
18071814

1815+
18081816
// Add Options Module
18091817
// ==================
18101818

@@ -2140,7 +2148,9 @@
21402148

21412149
// Stores the plugin context inside of the self variable
21422150
var self = this,
2143-
whitelist = self.options["copyAttributes"];
2151+
whitelist = self.options["copyAttributes"],
2152+
blacklist = self.options["dontCopyAttributes"];
2153+
21442154

21452155
// If there are array properties
21462156
if(arr.length) {
@@ -2151,6 +2161,13 @@
21512161
// Get's the property name and property value of each property
21522162
var propName = (property.name).toLowerCase(), propValue = property.value;
21532163

2164+
// If the currently traversed property is in the blacklist
2165+
if($.inArray(propName, blacklist) !== -1) {
2166+
2167+
return;
2168+
2169+
}
2170+
21542171
// If the currently traversed property value is not "null", is on the whitelist, or is an HTML 5 data attribute
21552172
if(propValue !== "null" && ($.inArray(propName, whitelist) !== -1 || propName.indexOf("data") !== -1)) {
21562173

@@ -2167,6 +2184,7 @@
21672184
return self;
21682185

21692186
};
2187+
21702188
// Destroy Module
21712189
// ==============
21722190

src/javascripts/modules/jquery.selectBoxIt.copyAttributes.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434

3535
// Stores the plugin context inside of the self variable
3636
var self = this,
37-
whitelist = self.options["copyAttributes"];
37+
whitelist = self.options["copyAttributes"],
38+
blacklist = self.options["dontCopyAttributes"];
39+
3840

3941
// If there are array properties
4042
if(arr.length) {
@@ -45,6 +47,13 @@
4547
// Get's the property name and property value of each property
4648
var propName = (property.name).toLowerCase(), propValue = property.value;
4749

50+
// If the currently traversed property is in the blacklist
51+
if($.inArray(propName, blacklist) !== -1) {
52+
53+
return;
54+
55+
}
56+
4857
// If the currently traversed property value is not "null", is on the whitelist, or is an HTML 5 data attribute
4958
if(propValue !== "null" && ($.inArray(propName, whitelist) !== -1 || propName.indexOf("data") !== -1)) {
5059

@@ -60,4 +69,4 @@
6069
// Maintains chainability
6170
return self;
6271

63-
};
72+
};

src/javascripts/modules/jquery.selectBoxIt.core.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@
100100
"rel"
101101

102102
],
103+
104+
// **dontCopyAttributes: HTML attributes to explicitly blacklist from being copied to the new dropdown
105+
"dontCopyAttributes": [
106+
107+
"data-reactid"
108+
109+
],
103110

104111
// **copyClasses**: HTML classes that will be copied over to the new drop down. The value indicates where the classes should be copied. The default value is 'button', but you can also use 'container' (recommended) or 'none'.
105112
"copyClasses": "button",
@@ -1803,4 +1810,4 @@
18031810
});
18041811

18051812
// Stores the plugin prototype object in a local variable
1806-
var selectBoxIt = $.selectBox.selectBoxIt.prototype;
1813+
var selectBoxIt = $.selectBox.selectBoxIt.prototype;

test/spec/selectBoxItSpec.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ describe('selectBoxIt jQuery Plugin', function () {
55

66
setFixtures('<select id="test1" data-icon="ui-icon ui-icon-power" data-text="Testing" class="testClass1 testClass2"><option value="Select a Month">Select a Month</option><option value="January">January</option><option value="February">February</option><option value="March">March</option><option value="April">April</option><option value="May">May</option><option value="June">June</option><option value="July">July</option><option value="August">August</option><option value="September" data-icon="ui ui-icon-power">September</option><option value="October">October</option><option value="November">November</option><option value="December">December</option></select>' +
77
'<select id="test2" data-icon="ui-icon ui-icon-power" data-text="Testing" class="testClass1 testClass2"><option value="Select a Month">Select a Month</option><option value="January">January</option><option value="February">February</option><option value="March">March</option><option value="April">April</option><option value="May">May</option><option value="June">June</option><option value="July">July</option><option value="August">August</option><option value="September" data-icon="ui ui-icon-power">September</option><option value="October">October</option><option value="November">November</option><option value="December">December</option></select>' +
8-
'<select id="test3" data-icon="ui-icon ui-icon-power" data-text="Testing" class="testClass1 testClass2"><option value="Select a Month">Select a Month</option><option value="January">January</option><option value="February">February</option><option value="March">March</option><option value="April">April</option><option value="May">May</option><option value="June">June</option><option value="July">July</option><option value="August">August</option><option value="September" data-icon="ui ui-icon-power">September</option><option value="October">October</option><option value="November">November</option><option value="December">December</option></select>');
8+
'<select id="test3" data-icon="ui-icon ui-icon-power" data-text="Testing" class="testClass1 testClass2"><option value="Select a Month">Select a Month</option><option value="January">January</option><option value="February">February</option><option value=&q 6D38 uot;March">March</option><option value="April">April</option><option value="May">May</option><option value="June">June</option><option value="July">July</option><option value="August">August</option><option value="September" data-icon="ui ui-icon-power">September</option><option value="October">October</option><option value="November">November</option><option value="December">December</option></select>' +
9+
'<select id="test4" data-icon="ui-icon ui-icon-power" data-reactid="0.0.0.1.2" data-custom="hi" data-text="Testing" class="testClass1 testClass2"><option value="Select a Month">Select a Month</option><option value="January">January</option><option value="February">February</option><option value="March">March</option><option value="April">April</option><option value="May">May</option><option value="June">June</option><option value="July">July</option><option value="August">August</option><option value="September" data-icon="ui ui-icon-power">September</option><option value="October">October</option><option value="November">November</option><option value="December">December</option></select>');
910

1011
spyOnEvent($("select#test1"), "create");
1112

@@ -30,6 +31,14 @@ describe('selectBoxIt jQuery Plugin', function () {
3031
};
3132
selectBoxIt3 = $("select#test3").selectBoxIt(opts3).data("selectBoxIt");
3233

34+
/*
35+
* Fixture used to test option variants.
36+
*/
37+
var opts4 = {
38+
dontCopyAttributes: ['data-reactid','data-custom']
39+
};
40+
selectBoxIt4 = $("select#test4").selectBoxIt(opts4).data("selectBoxIt");
41+
3342
});
3443

3544
describe("create()", function() {
@@ -52,6 +61,16 @@ describe('selectBoxIt jQuery Plugin', function () {
5261

5362
});
5463

64+
it("should not copy attributes in dontCopyAttributes", function () {
65+
66+
expect(selectBoxIt4.dropdown).not.toHaveAttr("data-reactid");
67+
68+
expect(selectBoxIt4.dropdown).not.toHaveAttr("data-custom");
69+
70+
expect(selectBoxIt4.dropdown).toHaveAttr("data-icon");
71+
72+
});
73+
5574
it("should add a css class to the new dropdown container element", function() {
5675

5776
expect(selectBoxIt1.dropdownContainer).toHaveClass("selectboxit-container");

0 commit comments

Comments
 (0)
0