Skip to content

Internal showPageByHref() not calling callback functions (custom fix inside) #524

@tegola

Description

@tegola

Internal showPageByHref function doesn't take into account the callback parameter:

For example, this callback found on jQT itself won't work:

showPageByHref(params.$el.attr("href"), {
  animation: animation,
  callback: function() {
    params.$el.removeClass("loading");
    return setTimeout(function() {
      return params.$el.removeClass('active');
    }, 250);
  },
  $referrer: params.$el
});

Here's the original showPageByHref with my fix applied (again, I'm not familiar with CoffeeScript, so can't do a pull request:

showPageByHref = (function(_this) {
  return function(href, options) {
    options = $.extend({}, {
      data: null,
      method: "GET",
      animation: null,
      $referrer: null
    }, options);
    if (href.charAt(0) !== '#') {
      return $.ajax({
        url: href,
        data: options.data,
        type: options.method,
        success: function(data) {
          var firstPage;
          firstPage = insertPages(data, options.animation);
          if (firstPage) {
            if (options.method === "GET" && _this.settings.cacheGetRequests === true && options.$referrer) {
              return options.$referrer.attr("href", "#" + firstPage.attr("id"));
            }
          }
          // FIX START         
          if (options.callback && typeof options.callback === "function") {
            options.callback.call();
          }
          // FIX END
        },
        error: function(data) {
          if (options.$referrer) {
            return options.$referrer.removeClass('active');
          }
        }
      });
    } else {
      if (options.$referrer) {
        return options.$referrer.removeClass('active');
      }
    }
  };
})(this);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions