Skip to content

Loading…

jQuery < 1.4.3 compatibility #37

Closed
wants to merge 1 commit into from

4 participants

@swiftyone

Before 1.4.3 data() did not include HTML5 data-* attributes.
Tested with jQuery 1.4.2

@swiftyone swiftyone Added jQuery < 1.4.3 compatibility
Before 1.4.3 data() did not include HTML5 data-* attributes.
Tested with jQuery 1.4.2
01b883a
@tuupola
Owner

1.4.2 is over two years old. Are there still some legacy systems which force using old jQuery?

@swiftyone

Not sure.
I'm currently working on a project that started in 2010 and have to use 1.4.2 for compatibility reasons..
But still, using attr() is significantly faster than data(): (http://jsperf.com/jq-attr-vs-data) and the use of attr() is sufficient in this case, as the additional features (as parsing) are not needed.

@TMcKinley

I did this change as well before I saw this Pull Request. Good to know that I'm not crazy. :-/

@gillyb

I would also like to see this change, since i am using this plugin, and the system im working on uses jquery 1.4 on some pages, and some pages has the new jquery. (I know it sounds crazy, but it still exists)

@swiftyone - What i don't understand though, is why you kept both implementations in your code commit. If you're using the one you added (using the attr method) then you don't need to check if data exists, since it will work on all jquery versions.

Hence, the code should look like this :
.attr("src", $self.attr('data-' + settings.data_attribute));

btw - I made this change locally, and it works on both the jquery versions we're using. No reason it wouldn't work on all versions.

@swiftyone

@gillyb Yeah, it sure works without the old implementation. But if you keep it, you can also use data which you added via .data() yourself, as those changes are not updated on the DOM node. I just like to keep it, even though I probably will never use it...

@tuupola
Owner

Related to #101

@tuupola
Owner

Modified merged in 1.9.x.

@tuupola tuupola closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 25, 2012
  1. @swiftyone

    Added jQuery < 1.4.3 compatibility

    swiftyone committed
    Before 1.4.3 data() did not include HTML5 data-* attributes.
    Tested with jQuery 1.4.2
Showing with 2 additions and 2 deletions.
  1. +2 −2 jquery.lazyload.js
View
4 jquery.lazyload.js
@@ -95,7 +95,7 @@
.bind("load", function() {
$self
.hide()
- .attr("src", $self.data(settings.data_attribute))
+ .attr("src", $self.data(settings.data_attribute) || $self.attr('data-' + settings.data_attribute))
[settings.effect](settings.effect_speed);
self.loaded = true;
@@ -110,7 +110,7 @@
settings.load.call(self, elements_left, settings);
}
})
- .attr("src", $self.data(settings.data_attribute));
+ .attr("src", $self.data(settings.data_attribute) || $self.attr('data-' + settings.data_attribute));
}
});
Something went wrong with that request. Please try again.