mirror of
https://github.com/DataTables/DataTables.git
synced 2025-02-20 18:54:15 +01:00
Fix: Compatibility with jQuery 2's isPlainObject
. API instances were returning as plain objects
- This appears to be caused by setting the prototype chain as an object directly. For example: var test = function () {}; test.prototype = {}; $.isPlainObject( new test() ); will return `true` with jQuery 2.1.4 (and `false` for 1.11.3). If an item is added to the prototype object then it will return `false`, although for some reason that wasn't the case with DataTables' API prototype. More investigation required, but for full compatiblity with exisiting jQuery releases, the correct thing to do here is to build on the exisiting prototype, which we can do with `$.extend`.
This commit is contained in:
parent
a7a9ac1910
commit
9ef7f1ad20
@ -1 +1 @@
|
||||
6f5ada12b6eb080305858981d2a11e8873354d3a
|
||||
2b8674aa2395b7be7f923e044fdb062e93a8af4e
|
||||
|
6
media/js/jquery.dataTables.js
vendored
6
media/js/jquery.dataTables.js
vendored
@ -6791,7 +6791,9 @@
|
||||
|
||||
DataTable.Api = _Api;
|
||||
|
||||
_Api.prototype = /** @lends DataTables.Api */{
|
||||
// Don't destroy the existing prototype, just extend it. Required for jQuery 2's
|
||||
// isPlainObject.
|
||||
$.extend( _Api.prototype, {
|
||||
any: function ()
|
||||
{
|
||||
return this.count() !== 0;
|
||||
@ -7037,7 +7039,7 @@
|
||||
|
||||
|
||||
unshift: __arrayProto.unshift
|
||||
};
|
||||
} );
|
||||
|
||||
|
||||
_Api.extend = function ( scope, obj, ext )
|
||||
|
4
media/js/jquery.dataTables.min.js
vendored
4
media/js/jquery.dataTables.min.js
vendored
@ -93,11 +93,11 @@ b){ka(o,a,b)});if(s.length){var u=function(a,b){return a.getAttribute("data-"+b)
|
||||
o.aaSorting;h=0;for(i=q.length;h<i;h++)q[h][1]=o.aoColumns[h].asSorting[0]}xa(o);v.bSort&&A(o,"aoDrawCallback",function(){if(o.bSorted){var a=V(o),b={};g.each(a,function(a,c){b[c.src]=c.dir});w(o,null,"order",[o,a,b]);Kb(o)}});A(o,"aoDrawCallback",function(){(o.bSorted||z(o)==="ssp"||v.bDeferRender)&&xa(o)},"sc");gb(o);h=r.children("caption").each(function(){this._captionSide=r.css("caption-side")});i=r.children("thead");0===i.length&&(i=g("<thead/>").appendTo(this));o.nTHead=i[0];i=r.children("tbody");
|
||||
0===i.length&&(i=g("<tbody/>").appendTo(this));o.nTBody=i[0];i=r.children("tfoot");if(0===i.length&&0<h.length&&(""!==o.oScroll.sX||""!==o.oScroll.sY))i=g("<tfoot/>").appendTo(this);0===i.length||0===i.children().length?r.addClass(j.sNoFooter):0<i.length&&(o.nTFoot=i[0],ea(o.aoFooter,o.nTFoot));if(d.aaData)for(h=0;h<d.aaData.length;h++)L(o,d.aaData[h]);else(o.bDeferLoading||"dom"==z(o))&&ma(o,g(o.nTBody).children("tr"));o.aiDisplay=o.aiDisplayMaster.slice();o.bInitialised=!0;!1===n&&ha(o)}});b=null;
|
||||
return this};var Ub=[],x=Array.prototype,dc=function(a){var b,c,e=m.settings,d=g.map(e,function(a){return a.nTable});if(a){if(a.nTable&&a.oApi)return[a];if(a.nodeName&&"table"===a.nodeName.toLowerCase())return b=g.inArray(a,d),-1!==b?[e[b]]:null;if(a&&"function"===typeof a.settings)return a.settings().toArray();"string"===typeof a?c=g(a):a instanceof g&&(c=a)}else return[];if(c)return c.map(function(){b=g.inArray(this,d);return-1!==b?e[b]:null}).toArray()};t=function(a,b){if(!(this instanceof t))return new t(a,
|
||||
b);var c=[],e=function(a){(a=dc(a))&&c.push.apply(c,a)};if(g.isArray(a))for(var d=0,f=a.length;d<f;d++)e(a[d]);else e(a);this.context=Oa(c);b&&this.push.apply(this,b.toArray?b.toArray():b);this.selector={rows:null,cols:null,opts:null};t.extend(this,this,Ub)};m.Api=t;t.prototype={any:function(){return 0!==this.count()},concat:x.concat,context:[],count:function(){return this.flatten().length},each:function(a){for(var b=0,c=this.length;b<c;b++)a.call(this,this[b],b,this);return this},eq:function(a){var b=
|
||||
b);var c=[],e=function(a){(a=dc(a))&&c.push.apply(c,a)};if(g.isArray(a))for(var d=0,f=a.length;d<f;d++)e(a[d]);else e(a);this.context=Oa(c);b&&this.push.apply(this,b.toArray?b.toArray():b);this.selector={rows:null,cols:null,opts:null};t.extend(this,this,Ub)};m.Api=t;g.extend(t.prototype,{any:function(){return 0!==this.count()},concat:x.concat,context:[],count:function(){return this.flatten().length},each:function(a){for(var b=0,c=this.length;b<c;b++)a.call(this,this[b],b,this);return this},eq:function(a){var b=
|
||||
this.context;return b.length>a?new t(b[a],this[a]):null},filter:function(a){var b=[];if(x.filter)b=x.filter.call(this,a,this);else for(var c=0,e=this.length;c<e;c++)a.call(this,this[c],c,this)&&b.push(this[c]);return new t(this.context,b)},flatten:function(){var a=[];return new t(this.context,a.concat.apply(a,this.toArray()))},join:x.join,indexOf:x.indexOf||function(a,b){for(var c=b||0,e=this.length;c<e;c++)if(this[c]===a)return c;return-1},iterator:function(a,b,c,e){var d=[],f,h,g,j,n,l=this.context,
|
||||
m,q,p=this.selector;"string"===typeof a&&(e=c,c=b,b=a,a=!1);h=0;for(g=l.length;h<g;h++){var o=new t(l[h]);if("table"===b)f=c.call(o,l[h],h),f!==k&&d.push(f);else if("columns"===b||"rows"===b)f=c.call(o,l[h],this[h],h),f!==k&&d.push(f);else if("column"===b||"column-rows"===b||"row"===b||"cell"===b){q=this[h];"column-rows"===b&&(m=Da(l[h],p.opts));j=0;for(n=q.length;j<n;j++)f=q[j],f="cell"===b?c.call(o,l[h],f.row,f.column,h,j):c.call(o,l[h],f,h,j,m),f!==k&&d.push(f)}}return d.length||e?(a=new t(l,a?
|
||||
d.concat.apply([],d):d),b=a.selector,b.rows=p.rows,b.cols=p.cols,b.opts=p.opts,a):this},lastIndexOf:x.lastIndexOf||function(a,b){return this.indexOf.apply(this.toArray.reverse(),arguments)},length:0,map:function(a){var b=[];if(x.map)b=x.map.call(this,a,this);else for(var c=0,e=this.length;c<e;c++)b.push(a.call(this,this[c],c));return new t(this.context,b)},pluck:function(a){return this.map(function(b){return b[a]})},pop:x.pop,push:x.push,reduce:x.reduce||function(a,b){return hb(this,a,b,0,this.length,
|
||||
1)},reduceRight:x.reduceRight||function(a,b){return hb(this,a,b,this.length-1,-1,-1)},reverse:x.reverse,selector:null,shift:x.shift,sort:x.sort,splice:x.splice,toArray:function(){return x.slice.call(this)},to$:function(){return g(this)},toJQuery:function(){return g(this)},unique:function(){return new t(this.context,Oa(this))},unshift:x.unshift};t.extend=function(a,b,c){if(c.length&&b&&(b instanceof t||b.__dt_wrapper)){var e,d,f,h=function(a,b,c){return function(){var e=b.apply(a,arguments);t.extend(e,
|
||||
1)},reduceRight:x.reduceRight||function(a,b){return hb(this,a,b,this.length-1,-1,-1)},reverse:x.reverse,selector:null,shift:x.shift,sort:x.sort,splice:x.splice,toArray:function(){return x.slice.call(this)},to$:function(){return g(this)},toJQuery:function(){return g(this)},unique:function(){return new t(this.context,Oa(this))},unshift:x.unshift});t.extend=function(a,b,c){if(c.length&&b&&(b instanceof t||b.__dt_wrapper)){var e,d,f,h=function(a,b,c){return function(){var e=b.apply(a,arguments);t.extend(e,
|
||||
e,c.methodExt);return e}};e=0;for(d=c.length;e<d;e++)f=c[e],b[f.name]="function"===typeof f.val?h(a,f.val,f):g.isPlainObject(f.val)?{}:f.val,b[f.name].__dt_wrapper=!0,t.extend(a,b[f.name],f.propExt)}};t.register=p=function(a,b){if(g.isArray(a))for(var c=0,e=a.length;c<e;c++)t.register(a[c],b);else for(var d=a.split("."),f=Ub,h,i,c=0,e=d.length;c<e;c++){h=(i=-1!==d[c].indexOf("()"))?d[c].replace("()",""):d[c];var j;a:{j=0;for(var n=f.length;j<n;j++)if(f[j].name===h){j=f[j];break a}j=null}j||(j={name:h,
|
||||
val:{},methodExt:[],propExt:[]},f.push(j));c===e-1?j.val=b:f=i?j.methodExt:j.propExt}};t.registerPlural=s=function(a,b,c){t.register(a,c);t.register(b,function(){var a=c.apply(this,arguments);return a===this?this:a instanceof t?a.length?g.isArray(a[0])?new t(a.context,a[0]):a[0]:k:a})};p("tables()",function(a){var b;if(a){b=t;var c=this.context;if("number"===typeof a)a=[c[a]];else var e=g.map(c,function(a){return a.nTable}),a=g(e).filter(a).map(function(){var a=g.inArray(this,e);return c[a]}).toArray();
|
||||
b=new b(a)}else b=this;return b});p("table()",function(a){var a=this.tables(a),b=a.context;return b.length?new t(b[0]):a});s("tables().nodes()","table().node()",function(){return this.iterator("table",function(a){return a.nTable},1)});s("tables().body()","table().body()",function(){return this.iterator("table",function(a){return a.nTBody},1)});s("tables().header()","table().header()",function(){return this.iterator("table",function(a){return a.nTHead},1)});s("tables().footer()","table().footer()",
|
||||
|
Loading…
x
Reference in New Issue
Block a user