[Require-js] swipe down on Ajax-loaded JavaScript implementations

Source: Internet
Author: User

Define (function () {function scrollmoreinfo ($wraper, Loaddatafunc, Json_ids, Pernum, Tpl_info) {this. $wraper = $wraper; t His.loaddatafunc = Loaddatafunc;this.originids = Json_ids;this.tpl = tpl_info;this.isappending = False;this.perNum = Pernum;this.leftdata = [];} Scrollmoreinfo.prototype = new Hnb.event (); $.extend (Scrollmoreinfo.prototype, {init:function () {var = this; Self.initdata (); Self.register ();},initdata:function () {var self = This;self.start = Self.originids.length;self.isend = False;self.idref = {};for (var i in self.originids) {if (Self.originids[i]) {Self.idref[self.originids[i] + "_"] = True;}}} , Register:function () {var self = this;$ (window). Scroll (function () {var height = $ (window). height (); var top = $ (window). ScrollTop (); var bodyheight = $ ("#id_top_wrap"). Height (); if (height + top > bodyHeight-100) {//Load data ... Self.appendmoredata ();}});           $ (window). Trigger ("scroll");},appendmoredata:function () {var = this; if (self.isappending) {return;} if (Self.leftData.lengTh >= self.pernum) {var arr_data = self.leftData.splice (0, Self.pernum); Self.renderdata (arr_data);} else if ( Self.isend) {if (self.leftData.length = = 0) {self.rendernomore (); return;}                var arr_data = self.leftData.splice (0, Self.pernum); Self.renderdata (Arr_data); if (self.leftData.length = = 0) {Self.rendernomore ();}} else {//load more data Self.isappending = True;self._loaddata (). Fail (function () {self.isend = true;}).                Always (function () {self.isappending = False;self.appendmoredata ();}); }},///Tail picture (no-more-data/data-loading) showing Rendernomore:function () {var self = this;self. $wraper. Find (". c-data-no-m Ore "). Removeclass (" DN "), self. $wraper. Find (". c-data-loading "). AddClass (" DN ");},//Data template rendering Renderdata:function (arr_ Data) {var self = this;var html = Hnb.ui.tmpl (SELF.TPL, {arr_infolist:arr_data}); $wraper. Find (". c-data-loading"). Before (HTML); Self.trigger ("After:render:more:data");},//Data load _loaddata:function () {var self = This;var Defer = $. Deferred (); Self.loaddatafunc (Self.start, Self.pernum). Done (function (json_msg) {if (json_msg.state) {///failed, the existing number It is displayed to the page, set to end Defer.reject (-1);} else {if (Json_msg.data.infoList.length < self.pernum) {self.isend = true;} Self._storedata (json_msg.data.infoList);d efer.resolve ();}}).            Fail (function () {Defer.reject (-1);});  Data read starting point Self.start + = Self.pernum;return defer;}, when the loaded data is less than the length of each page, store it first _storedata:function (arr_data) {var self = This;for (var i in Arr_data) {if (arr_data[i].id &&!self.idref[arr_data[i].id + "_"]) {Self.leftData.push (arr_ Data[i]); Self.idref[arr_data[i].id + "_"] = True;}}});  return {create:function ($wraper, Loaddatafunc, Json_datainit, Pernum, tpl_info) {var obj = new Scrollmoreinfo ($wraper , Loaddatafunc, Json_datainit, Pernum, Tpl_info); Obj.init (); return obj;}});

[Require-js] swipe down on Ajax-loaded JavaScript implementations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.