/    Sign up×
Community /Pin to ProfileBookmark

JQuery and IE7 bug

Hi everyone..

I am using the script below to run a rating plugin… it works on all browsers except ie6 and 7.. any help would be greatly appreciated.. thanks in advance..

$.fn.rater = function(options) {
var opts = $.extend({}, $.fn.rater.defaults, options);
return this.each(function() {
var $this = $(this);
var $on = $this.find(‘.ui-rater-starsOn’);
var $off = $this.find(‘.ui-rater-starsOff’);
opts.size = $on.height();
if (opts.rating == undefined) opts.rating = $on.width() / opts.size;
if (opts.id == undefined) opts.id = $this.attr(‘id’);

$off.mousemove(function(e) {
var left = e.clientX – $off.offset().left;
var width = $off.width() – ($off.width() – left);
width = Math.ceil(width / (opts.size / opts.step)) * opts.size / opts.step;
$on.width(width);
}).hover(function(e) { $on.addClass(‘ui-rater-starsHover’); }, function(e) {
$on.removeClass(‘ui-rater-starsHover’); $on.width(opts.rating * opts.size);
}).click(function(e) {
var r = Math.round($on.width() / $off.width() * (opts.units * opts.step)) / opts.step;
$off.unbind(‘click’).unbind(‘mousemove’).unbind(‘mouseenter’).unbind(‘mouseleave’);
$off.css(‘cursor’, ‘default’); $on.css(‘cursor’, ‘default’);
$.fn.rater.rate($this, opts, r);
}).css(‘cursor’, ‘pointer’); $on.css(‘cursor’, ‘pointer’);
});

};

$.fn.rater.defaults = {
postHref: location.href,
guid: 0,
units: 5,
step: 1,
};

$.fn.rater.rate = function($this, opts, rating) {
var $on = $this.find(‘.ui-rater-starsOn’);
var $off = $this.find(‘.ui-rater-starsOff’);
$off.fadeTo(600, 0.4, function() {
$.ajax({
url: opts.postHref,
type: “POST”,
data: ‘id=’ + opts.id + ‘&guid=’ + opts.guid + ‘&rating=’ + rating,
complete: function(req) {
if (req.status == 200) { //success
opts.rating = parseFloat(req.responseText);
$off.fadeTo(600, 0.1, function() {
$on.removeClass(‘ui-rater-starsHover’).width(opts.rating * opts.size);
var $count = $this.find(‘.ui-rater-rateCount’);
$count.text(parseInt($count.text()) + 1);
$this.find(‘.ui-rater-rating’).text(opts.rating.toFixed(1));
$off.fadeTo(600, 1);
$this.attr(‘title’, ‘Your rating: ‘ + rating.toFixed(1));
});
} else { //failure
alert(req.responseText);
$on.removeClass(‘ui-rater-starsHover’).width(opts.rating *
opts.size);
$this.rater(opts);
$off.fadeTo(2200, 1);
}
}
});
});
};

-Carlos

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Sep 29.2009 — It would help if you used code tags to format your code and it would help to say what does not work. What is the error message?

Eric
Copy linkTweet thisAlerts:
@ElggauthorSep 29.2009 — Hey Alien..

Thanks for the reply.. and I'm sorry about the lack of details..

This code is in fact driving a photorating system where the rate is taken through moving the mouse over an image (like stars or love hearts.. I'm sure you're familiar with 'stars rating' look and feel that you often see on the web).

There is no error message produced by the browser itself, or, there aint one that I have seen anyways.. The problem is that it works with all browsers, including IE8, but fails with IE7.. the images just don't change color when you move the mouse over them and no rating can be taken.

But here's a live test site that uses the code where you can view any of those images and add a rating:

http://3.cloodo.com

It would be great to be able to get a fix for this one.

Thanks again

-Carlos
Copy linkTweet thisAlerts:
@A1ien51Sep 29.2009 — Opening up the page I see:


Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618)

Timestamp: Tue, 29 Sep 2009 05:04:09 UTC


Message: Expected identifier, string or number

Line: 34

Char: 1

Code: 0

URI: http://3.cloodo.com/mod/photorating/views/default/photorating/js/jquery.rater.js


Message: Object doesn't support this property or method

Line: 114

Char: 4

Code: 0

URI: http://3.cloodo.com/pg/photos/view/923/12

[/quote]


Eric
Copy linkTweet thisAlerts:
@A1ien51Sep 29.2009 — And if you look at the code

$.fn.rater.defaults = {
30 postHref: location.href,
31 guid: 0,
32 units: 5,
33 step: 1.5,
34};


You can see the error right on line 33. You can not have a trailing comma in an object. I love when browser's point you right to the error.

Eric
Copy linkTweet thisAlerts:
@ElggauthorSep 29.2009 — Thanks Eric..

well, that's really neat..

so what you're saying is that if I take the comma off line 33, it should work..?

Is that the problem..??

Thanks man.
Copy linkTweet thisAlerts:
@nathandelaneSep 29.2009 — In your script you are using clientX and clientY, but those are not compatible with IE. See [url=http://www.quirksmode.org/js/events_properties.html]QuirksMode > Event Properties > Mouse Position[/url] for more information. From the page:


there is no reliable cross–browser way to find the mouse coordinates relative to the document we need.

These are the six property pairs

  • 1. clientX,clientY

  • 2. layerX,layerY

  • 3. offsetX,offsetY

  • 4. pageX,pageY

  • 5. screenX,screenY

  • 6. x,y


  • The screenX and screenY properties are the only ones that are completely cross–browser compatible. They give the mouse position relative to the entire computer screen of the user.
    [/quote]
    ×

    Success!

    Help @Elgg spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...