Skip to content

Commit 406ec68

Browse files
committed
Core: Don't use jQuery.type
The function code has been (mostly) copied into the library. Fixes #115
1 parent 2195372 commit 406ec68

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

jquery.color.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor " +
2525
"borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",
2626

27+
class2type = {},
28+
toString = class2type.toString,
29+
2730
// plusequals test for += 100 -= 100
2831
rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
2932

@@ -153,6 +156,22 @@ each( spaces, function( spaceName, space ) {
153156
};
154157
} );
155158

159+
// Populate the class2type map
160+
jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
161+
function( i, name ) {
162+
class2type[ "[object " + name + "]" ] = name.toLowerCase();
163+
} );
164+
165+
function getType( obj ) {
166+
if ( obj == null ) {
167+
return obj + "";
168+
}
169+
170+
return typeof obj === "object" ?
171+
class2type[ toString.call( obj ) ] || "object" :
172+
typeof obj;
173+
}
174+
156175
function clamp( value, prop, allowEmpty ) {
157176
var type = propTypes[ prop.type ] || {};
158177

@@ -226,7 +245,7 @@ color.fn = jQuery.extend( color.prototype, {
226245
}
227246

228247
var inst = this,
229-
type = jQuery.type( red ),
248+
type = getType( red ),
230249
rgba = this._rgba = [];
231250

232251
// more than 1 argument specified - assume ( red, green, blue, alpha )
@@ -518,7 +537,7 @@ each( spaces, function( spaceName, space ) {
518537
}
519538

520539
var ret,
521-
type = jQuery.type( value ),
540+
type = getType( value ),
522541
arr = ( type === "array" || type === "object" ) ? value : arguments,
523542
local = this[ cache ].slice();
524543

@@ -548,7 +567,7 @@ each( spaces, function( spaceName, space ) {
548567
}
549568
color.fn[ key ] = function( value ) {
550569
var local, cur, match, fn,
551-
vtype = jQuery.type( value );
570+
vtype = getType( value );
552571

553572
if ( key === "alpha" ) {
554573
fn = this._hsla ? "hsla" : "rgba";
@@ -564,7 +583,7 @@ each( spaces, function( spaceName, space ) {
564583

565584
if ( vtype === "function" ) {
566585
value = value.call( this, cur );
567-
vtype = jQuery.type( value );
586+
vtype = getType( value );
568587
}
569588
if ( value == null && prop.empty ) {
570589
return this;
@@ -590,7 +609,7 @@ color.hook = function( hook ) {
590609
set: function( elem, value ) {
591610
var parsed;
592611

593-
if ( value !== "transparent" && ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) ) {
612+
if ( value !== "transparent" && ( getType( value ) !== "string" || ( parsed = stringParse( value ) ) ) ) {
594613
value = color( parsed || value );
595614
value = value.toRgbaString();
596615
}

0 commit comments

Comments
 (0)