Fix for handling touch and click event in iPad safari

The following script will handle the touch and click event in iOS newly updated safari:

      var clickEvent = navigator.userAgent.match(/iPad|iPhone/) ? ‘touchstart’ : ‘click’;

function init() {

var name = options.idBase;

for (var i = 0; i < options.items.length; i++) {

var id = options.idBase + options.items[i][0];

var val = options.items[i][0];

var text = options.items[i][1];

options.jsource.append($(‘<input name=”‘ + name + ‘” id=”‘ + id + ‘” value=”‘ + val + ‘” type=”radio” />’));

options.jsource.append($(‘<label for=”‘ + id + ‘”>’ + text + ‘</label>’));

}

options.jsource.addClass(‘ks-rdo-filter’);

options.jsource.find(‘label’).first().addClass(‘first’);

options.jsource.find(‘label’).last().addClass(‘last’);

options.jsource.find(‘label’).on(clickEvent, function () {

options.jsource.find(‘.selected’).removeClass(‘selected’);

$(this).addClass(‘selected’);

$(this).prev().trigger(clickEvent);

if (options.onClicked != ‘undefined’)

options.onClicked($(this).prev().val());

});

if (options.selectedIndex > -1)

options.jsource.find(‘label’).eq(options.selectedIndex).trigger(clickEvent);

}

 

Categories: Javascript