msjolund / jquery-esn-autobrowse Goto Github PK
View Code? Open in Web Editor NEWAutobrowse jquery plugin
Home Page: http://msjolund.github.com/autobrowse/
Autobrowse jquery plugin
Home Page: http://msjolund.github.com/autobrowse/
Hi there!
Thingie binds event to $(window), which means that if one would want to unbind the event so as to change the url or put another listener to scroll, one would have no means to unbind?
e.g.
$(".element").autobrowse()
$(".element").unbind() would not work, and there would be no way to unbind the event.
Will be adding a pull reuqest in a sec
Is it possible to load json from a local file and not from a remote server?
I simply copied the file ParisHilton.JSON which loads from the twitter demo's url into a local file and set the url function as such:
url: function (offset)
{
return "ParisHilton.json";
},
But nothing gets loaded from that file. But if I put back the direct link to the twitter JSON feed like in the example content is loaded just fine.
So is it possible for this plugin to work with a local file? I want to create a JSON file and load it locally as I have mentioned before. How would I go to achieve this?
Thanks
Hi there,
added a onError param that will be called when jqXHR requests deem correct, as per jquery best practices
the full diff, that will enable both stopFunction and onError follows
47a48,49
> * * stopFunction a function that will return true if it is necessary to stop autoscrolling
> * * onError a function that will be executed on error (HTTP response 500, etc.)
65c67,69
< postData: null
---
> postData: null,
> stopFunction: function () {},
> onError: function () {}
153c157
< if (options.itemsReturned(response) == 0 || (options.max != null && currentOffset >= options.max))
---
> if (options.itemsReturned(response) == 0 || (options.max != null && currentOffset >= options.max) || options.stopFunction(response) === true)
158a163
>
176c181
< jQuery.post(options.url(currentOffset), data, ajaxCallback, "json");
---
> jQuery.post(options.url(currentOffset), data, ajaxCallback, "json").error(options.onError);
180c185
< jQuery.getJSON(options.url(currentOffset), ajaxCallback);
---
> jQuery.getJSON(options.url(currentOffset), ajaxCallback).error(options.onError);
If you need it, I can commit only the changes required for this to work not including the stopFunction :)
Cheers!
Pedro
PS: Sorry I dont create a pull request, I cannot get the proxy to work behind my corporate proxy for the life of me
We could not find a license for this package. Please clarify the license - MIT would be a good choice in the jQuery context.
There are guidelines for adding a license at https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/licensing-a-repository. Thank you.
Even after the element on which autobrowse is initialized is removed from DOM, the plugin keeps working on scroll.
url: function (offset) { return "http://twitter.com/status/user_timeline/ParisHilton.json?count=10&page=OFFSET&callback=?".replace(/OFFSET/, 1+Math.round(offset/10)); }
there is no as such source available for this plugin. kindly provide a good example how can we pull data from a service in asp.net. it will be highly appreciated. Thanks.
My feed is being called twice when there's not enough data to fill the screen.
What I would like, is that if the API returns less than 30 results, we stop scrolling, since we hit all the records already. However, this is very custom and would not be acceptable for all use cases so I added a stopFunction to the code:
47a48
> * * stopFunction a function that will return true if it is necessary to stop autoscrolling
65c66,67
< postData: null
---
> postData: null,
> stopFunction: function () {}
153c155
< if (options.itemsReturned(response) == 0 || (options.max != null && currentOffset >= options.max))
---
> if (options.itemsReturned(response) == 0 || (options.max != null && currentOffset >= options.max) || options.stopFunction(response) === true)
this is the diff, pretty simple
so when I call the autoscroll I do like
$('.requests-table-container').autobrowse({
url: function (offset) {
return apiUrl.replace("!offset", offset);
},
template: appendRequestsToDom,
itemsReturned: function (response) {
return response.length;
},
offset: 0,
loader: '<div class="loader">'+
'<img src="images/loader.gif" />'+
'</div>',
stopFunction: function (response) {
return response.length < 30
}
});
Thanks for the autobrowse code, it was helpful in developing my scripts. One thing I thought I'd point out, it was driving me nuts, on a fast connection, I would get repetitive "No more data to load" messages, and multiple json requests when running out of data. I noticed the function would call itself again and again, looping until the _stopPlugin function had completed. Simply added a return statement when the options.itemsReturned(reponse)=0 was true did the trick and eneded the loop.
-------------------------
// Check if these were the last items to fetch from the server, if so, stop listening
if (options.itemsReturned(response) == 0 || (options.max != null && options.itemsReturned(response) + currentOffset >= options.max))
{
_stopPlugin(scrollCallback)
--> return; // break and do not call scrollCallBack() again
}
loading = false;
scrollCallback()
};
-----------------------
i tried this, but its making endless new ajax calls on the end anyway:
complete: function(obj, response, newElements) {
if (newElements.length == 0) {
this.stopFunction;
return false;
}
myMasonry.masonry('appended', newElements);
myMasonry.masonry('reload');
myMasonry.imagesLoaded(function() {
myMasonry.masonry('reload');
});
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.