Skip to content
Browse files

jQuery 1.6.x compatible fixes for attr/prop methods

  • Loading branch information...
1 parent c213425 commit dbdef47141a3b1c7f761ad0e7f715291e6b38eab @tonytomov committed Sep 18, 2011
Showing with 35 additions and 33 deletions.
  1. +18 −17 js/grid.base.js
  2. +1 −1 js/grid.celledit.js
  3. +13 −12 js/grid.formedit.js
  4. +1 −1 js/grid.inlinedit.js
  5. +1 −1 js/grid.tbltogrid.js
  6. +1 −1 js/jquery.fmatter.js
View
35 js/grid.base.js
@@ -878,6 +878,7 @@ $.fn.jqGrid = function( pin ) {
}
$(this).empty().attr("tabindex","1");
this.p = p ;
+ this.p.useProp = !!$.fn.prop;
var i, dir,ts;
if(this.p.colNames.length === 0) {
for (i=0;i<this.p.colModel.length;i++){
@@ -1560,7 +1561,7 @@ $.fn.jqGrid = function( pin ) {
fmt = $.jgrid.formatter.integer || {};
cp = intNum(ts.p.page);
last = intNum(ts.p.lastpage);
- $(".selbox",pgboxes).attr("disabled",false);
+ $(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false);
if(ts.p.pginput===true) {
$('.ui-pg-input',pgboxes).val(ts.p.page);
sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg_t : '#sp_1'+tspg;
@@ -1752,7 +1753,7 @@ $.fn.jqGrid = function( pin ) {
var ret;
if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging); }
ts.p.selrow = null;
- if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false);}
+ if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", false);}
ts.p.savedRow = [];
if(ret=='stop') {return false;}
return true;
@@ -1891,7 +1892,7 @@ $.fn.jqGrid = function( pin ) {
if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");}
} else {
ts.p.selrow = null;
- if(ts.p.multiselect){$("#cb_"+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false);}
+ if(ts.p.multiselect){$("#cb_"+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", false);}
ts.p.selarrrow =[];
ts.p.savedRow =[];
}
@@ -2096,7 +2097,7 @@ $.fn.jqGrid = function( pin ) {
$(ts.rows).each(function(i) {
if ( i>0 ) {
if(!$(this).hasClass("subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled')){
- $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) ).attr("checked","checked");
+ $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked",true);
$(this).addClass("ui-state-highlight").attr("aria-selected","true");
ts.p.selarrrow.push(this.id);
ts.p.selrow = this.id;
@@ -2110,7 +2111,7 @@ $.fn.jqGrid = function( pin ) {
$(ts.rows).each(function(i) {
if(i>0) {
if(!$(this).hasClass("subgrid") && !$(this).hasClass('ui-state-disabled')){
- $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) ).removeAttr("checked");
+ $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked", false);
$(this).removeClass("ui-state-highlight").attr("aria-selected","false");
emp.push(this.id);
}
@@ -2257,10 +2258,10 @@ $.fn.jqGrid = function( pin ) {
$(ts.p.selarrrow).each(function(i,n){
var ind = ts.rows.namedItem(n);
$(ind).removeClass("ui-state-highlight");
- $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n)).attr("checked",false);
+ $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n))[ts.p.useProp ? 'prop': 'attr']("checked", false);
});
ts.p.selarrrow = [];
- $("#cb_"+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false);
+ $("#cb_"+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", false);
$(ts).jqGrid("setSelection",ptr[0].id,true);
}
} else {
@@ -2270,8 +2271,8 @@ $.fn.jqGrid = function( pin ) {
if(e[ts.p.multikey]) {
$(ts).jqGrid("setSelection",ptr[0].id,true);
} else if(ts.p.multiselect && scb) {
- scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ptr[0].id).attr("checked");
- $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ptr[0].id).attr("checked",!scb);
+ scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ptr[0].id).is(":checked");
+ $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ptr[0].id)[ts.p.useProp ? 'prop' : 'attr']("checked", scb);
}
}
if($.isFunction(ts.p.onCellSelect)) {
@@ -2292,7 +2293,7 @@ $.fn.jqGrid = function( pin ) {
if(ts.p.datatype=="local"){ $(ts).jqGrid("resetSelection"); if(ts.p.data.length) { refreshIndex();} }
else if(!ts.p.treeGrid) {
ts.p.selrow=null;
- if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false);}
+ if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", false);}
ts.p.savedRow = [];
}
if(ts.p.scroll) {emptyRows(ts.grid.bDiv,true, false);}
@@ -2517,7 +2518,7 @@ $.jgrid.extend({
if(pt.className !== "ui-subgrid") {
if( $t.p.selrow != pt.id) {
$($t.rows.namedItem($t.p.selrow)).removeClass("ui-state-highlight").attr({"aria-selected":"false", "tabindex" : "-1"});
- $(pt).addClass("ui-state-highlight").attr({"aria-selected":true, "tabindex" : "0"});//.focus();
+ $(pt).addClass("ui-state-highlight").attr({"aria-selected":"true", "tabindex" : "0"});//.focus();
stat = true;
} else {
stat = false;
@@ -2531,12 +2532,12 @@ $.jgrid.extend({
if ( ia === -1 ){
if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");}
stat = true;
- $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID($t.p.selrow)).attr("checked",stat);
+ $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID($t.p.selrow))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
$t.p.selarrrow.push($t.p.selrow);
} else {
if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");}
stat = false;
- $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID($t.p.selrow)).attr("checked",stat);
+ $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID($t.p.selrow))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
$t.p.selarrrow.splice(ia,1);
tpsr = $t.p.selarrrow[0];
$t.p.selrow = (tpsr === undefined) ? null : tpsr;
@@ -2552,8 +2553,8 @@ $.jgrid.extend({
sr = rowid === t.p.selrow ? t.p.selrow : rowid;
$("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(sr)).removeClass("ui-state-highlight").attr("aria-selected","false");
if(t.p.multiselect) {
- $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr)).attr("checked",false);
- $("#cb_"+$.jgrid.jqID(t.p.id)).attr("checked",false);
+ $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr))[t.p.useProp ? 'prop': 'attr']("checked",false);
+ $("#cb_"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false );
}
sr = null;
} else if(!t.p.multiselect) {
@@ -2565,9 +2566,9 @@ $.jgrid.extend({
$(t.p.selarrrow).each(function(i,n){
ind = t.rows.namedItem(n);
$(ind).removeClass("ui-state-highlight").attr("aria-selected","false");
- $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n)).attr("checked",false);
+ $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n))[t.p.useProp ? 'prop': 'attr']("checked",false);
});
- $("#cb_"+$.jgrid.jqID(t.p.id)).attr("checked",false);
+ $("#cb_"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false);
t.p.selarrrow = [];
}
if(t.p.cellEdit === true) {
View
2 js/grid.celledit.js
@@ -149,7 +149,7 @@ $.jgrid.extend({
if(cm.editoptions){
cbv = cm.editoptions.value.split(":");
}
- v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).attr("checked") ? cbv[0] : cbv[1];
+ v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1];
v2=v;
break;
case "password":
View
25 js/grid.formedit.js
@@ -365,7 +365,7 @@ $.jgrid.extend({
} else {
switch ($(this).get(0).type) {
case "checkbox":
- if($(this).attr("checked")) {
+ if($(this).is(":checked")) {
postdata[this.name]= $(this).val();
}else {
var ofv = $(this).attr("offval");
@@ -497,7 +497,8 @@ $.jgrid.extend({
fld[0].defaultChecked = true;
fld[0].value = vl;
} else {
- fld.attr({checked:"",defaultChecked:""});
+ fld[0].checked = false;
+ fld[0].defaultChecked = false;
}
} else {fld.val(vl); }
} else {
@@ -566,20 +567,20 @@ $.jgrid.extend({
if(cm[i].editoptions && cm[i].editoptions.value) {
var cb = cm[i].editoptions.value.split(":");
if(cb[0] == tmp) {
- $("#"+nm,"#"+fmid).attr("checked",true);
- $("#"+nm,"#"+fmid).attr("defaultChecked",true); //ie
+ $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
+ $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
} else {
- $("#"+nm,"#"+fmid).attr("checked",false);
- $("#"+nm,"#"+fmid).attr("defaultChecked",""); //ie
+ $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
+ $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
}
} else {
tmp = tmp.toLowerCase();
if(tmp.search(/(false|0|no|off|undefined)/i)<0 && tmp!=="") {
- $("#"+nm,"#"+fmid).attr("checked",true);
- $("#"+nm,"#"+fmid).attr("defaultChecked",true); //ie
+ $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
+ $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
} else {
- $("#"+nm,"#"+fmid).attr("checked",false);
- $("#"+nm,"#"+fmid).attr("defaultChecked",""); //ie
+ $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
+ $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
}
}
break;
@@ -1949,9 +1950,9 @@ $.jgrid.extend({
if ( $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:radio") || $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:checkbox")) {
$("[name="+$.jgrid.jqID(i)+"]",formid).each( function() {
if( $(this).val() == rowdata[i] ) {
- $(this).attr("checked","checked");
+ $(this)[$t.p.useProp ? 'prop': 'attr']("checked",true);
} else {
- $(this).attr("checked","");
+ $(this)[$t.p.useProp ? 'prop': 'attr']("checked", false);
}
});
} else {
View
2 js/grid.inlinedit.js
@@ -132,7 +132,7 @@ $.jgrid.extend({
if(cm.editoptions ) {
cbv = cm.editoptions.value.split(":");
}
- tmp[nm]= $("input",this).attr("checked") ? cbv[0] : cbv[1];
+ tmp[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1];
break;
case 'text':
case 'password':
View
2 js/grid.tbltogrid.js
@@ -52,7 +52,7 @@ jQuery(selector).each(function() {
var input = jQuery('input', jQuery(this));
var rowId = input.attr("value");
rowIds.push(rowId || data.length);
- if (input.attr("checked")) {
+ if (input.is(":checked")) {
rowChecked.push(rowId);
}
row[colModel[rowPos].name] = input.attr("value");
View
2 js/jquery.fmatter.js
@@ -506,7 +506,7 @@
break;
case 'checkbox':
var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"];
- ret = $('input',cellval).attr("checked") ? cbv[0] : cbv[1];
+ ret = $('input',cellval).is(":checked") ? cbv[0] : cbv[1];
break;
case 'select' :
ret = $.unformat.select(cellval,options,pos,cnt);

8 comments on commit dbdef47

@OlegKi
OlegKi commented on dbdef47 Sep 18, 2011

Hello Tony,

I think it's good implementation way. I would personally do some things in a little another way, but it's the matter of the taste mostly. For example in the line this.p.useProp = !!$.fn.prop; I would use $.isFunction($.fn.prop) or typeof($.fn.prop) === 'function' instead of !!$.fn.prop. In some other places I would be more consequent in the usage of DOM properties. An example: you use $(this).is(":checked") with this as DOM element. You can use just this.checked directly. If you decide don't use DOM properties then the assignments fld[0].checked = false; and fld[0].defaultChecked = false; should be changed also. Either one uses DOM properties directly or one uses consequent jQuery methods like for example jQuery UI do.

Best regards
Oleg

@tonytomov
Owner

Oleg,
I just made these changes to be compatible with the old code.
About "this.p.useProp = !!$.fn.prop" - it is a new way of checking for some properties (function) (see HTML5 property detection ) - I just want to see this in action.

Tony

@midem
midem commented on dbdef47 Oct 7, 2011

Hello,

thank you for changes. But unchecking checked checkboxes in form editing still didn't work with jquery 1.6.3. It can be fixed by:

- if($(this).attr("checked")) {
+ if( $(this).is(":checked") ){

in jquery.jqGrid.src.js

Best regards,
Mirek

@tonytomov
Owner

Hello,
Could you please let me know in which line exactly is this - using the latest commits
Thank you

@OlegKi
OlegKi commented on dbdef47 Oct 7, 2011

I suppose it is the line which is already fixed in your code Tony.

@Tony: Next days I will post you my suggestions about multi-row headers.

Best regards
Oleg

@tonytomov
Owner

Oleg,
This will be good. I plan to work this weekend on this, so that we can have a new version next week.

Tony

@OlegKi
OlegKi commented on dbdef47 Oct 7, 2011

@tony: My son was at hospital for two days this week and so how you can imagine I had other problems as jqGrid. Now everything is OK, my son is at home, and I plan to work on the problem at the weekend too. It hope to have the most things working in the next days.

Oleg

@tonytomov
Owner

Oleg,
You do not need to work this weekend on this.
Thanks

Tony

Please sign in to comment.
Something went wrong with that request. Please try again.