/*! waterfall - v0.1.73 - 2015-12-01
* //wlog.cn/waterfall/
* Copyright (c) 2015 bingdian; Licensed MIT */
! function(a, b, c, d) {
"use strict";
function e(b, c) {
this.$element = a(b),
this.options = a.extend(!0, {}, h, c),
this.colHeightArray = [],
this.styleQueue = [],
this._init()
}
var f = a(b),
g = "waterfall",
h = {
itemCls: "waterfall-item",
prefix: "waterfall",
fitWidth: !0,
colWidth: 240,
gutterWidth: 10,
gutterHeight: 10,
align: "center",
minCol: 1,
maxCol: d,
maxPage: d,
bufferPixel: -50,
containerStyle: {
position: "relative"
},
resizable: !0,
isFadeIn: !1,
isAnimated: !1,
animationOptions: {},
isAutoPrefill: !0,
checkImagesLoaded: !0,
path: d,
dataType: "json",
params: {},
headers: {},
loadingMsg: '
Loading...
',
state: {
isDuringAjax: !1,
isProcessingData: !1,
isResizing: !1,
isPause: !1,
curPage: 1
},
callbacks: {
loadingStart: function(a) {
a.show()
},
loadingFinished: function(a, b) {
b ? a.remove() : a.fadeOut()
},
loadingError: function(a, b) {
a.html("Data load faild, please try again later.")
},
renderData: function(b, c) {
var d, e;
return "json" === c || "jsonp" === c ? (d = a("#waterfall-tpl").html(),
(e = Handlebars.compile(d))(b)) : b
}
},
debug: !1
};
e.prototype = {
constructor: e,
_debug: function() {
!0 === this.options.debug && ("undefined" != typeof console && "function" == typeof console.log ? 1 === Array.prototype.slice.call(arguments).length && "string" == typeof Array.prototype.slice.call(arguments)[0] ? console.log(Array.prototype.slice.call(arguments).toString()) : console.log(Array.prototype.slice.call(arguments)) : Function.prototype.bind || "undefined" == typeof console || "object" != typeof console.log || Function.prototype.call.call(console.log, console, Array.prototype.slice.call(arguments)))
},
_init: function(a) {
var b = this.options,
c = b.path;
return this._setColumns(), this._initContainer(),
this._resetColumnsHeightArray(),
this.reLayout(a), c ? (b.isAutoPrefill &&
this._prefill(), b.resizable &&
this._doResize(), void this._doScroll()) : void
this._debug("Invalid path")
},
_initContainer: function() {
var b = this.options,
c = b.prefix;
a("body").css({
overflow: "auto"
}), this.$element.css(this.options.containerStyle).addClass(c + "-container"), this.$element.after('' + b.loadingMsg + '
'), this.$loading = a("#" + c + "-loading"), this.$message = a("#" + c + "-message")
},
_getColumns: function() {
var a = this.options,
b = a.fitWidth ? this.$element.parent() : this.$element,
c = "BODY" === b[0].tagName ? b.width() - 20 : b.width(),
d = a.colWidth,
e = a.gutterWidth,
f = a.minCol,
g = a.maxCol,
h = Math.floor(c / (d + e)),
i = Math.max(h, f);
return g && i > g ? g : i
},
_setColumns: function() {
this.cols = this._getColumns()
},
_getItems: function(a) {
var b = a.filter("." + this.options.itemCls).css({
position: "absolute"
});
return b
},
_resetColumnsHeightArray: function() {
var a, b = this.cols;
for (this.colHeightArray.length = b, a = 0; b > a; a++) this.colHeightArray[a] = 0
},
layout: function(a, b) {
var c, d, e, f, g, h, i = this.options,
j = this.options.isFadeIn ? this._getItems(a).css({
opacity: 0
}).animate({
opacity: 1
}) : this._getItems(a),
k = this.options.isAnimated && this.options.state.isResizing ? "animate" : "css",
l = i.animationOptions,
m = i.colWidth,
n = i.gutterWidth,
o = this.colHeightArray.length,
p = i.align;
for (this.$element.append(j), "center" === p ? (c = (this.$element.width() - m * o - n * (o - 1)) / 2, c = c > 0 ? c : 0) : "left" === p ? c = 0 : "right" === p && (c = this.$element.width() - m * o - n * (o - 1)), e = 0, g = j.length; g > e; e++) this._placeItems(j[e], c);
for (f = 0, h = this.styleQueue.length; h > f; f++) d = this.styleQueue[f], d.$el[k](d.style, l);
this.$element.height(Math.max.apply({}, this.colHeightArray)), this.styleQueue = [], this.options.state.isResizing = !1, this.options.state.isProcessingData = !1, b && b.call(j)
},
reLayout: function(a) {
var b = this.$element.find("." + this.options.itemCls);
this._resetColumnsHeightArray(), this.layout(b, a)
},
_placeItems: function(b, c) {
var d, e, f = a(b),
g = this.options,
h = g.colWidth,
i = g.gutterWidth,
j = g.gutterHeight,
k = this.colHeightArray,
l = k.length,
m = Math.min.apply({}, k),
n = a.inArray(m, k);
d = f.hasClass(g.prefix + "-item-fixed-left") ? 0 : f.hasClass(g.prefix + "-item-fixed-right") ? l > 1 ? l - 1 : 0 : n, e = {
left: (h + i) * d + c,
top: k[d]
}, this.styleQueue.push({
$el: f,
style: e
}), k[d] += f.outerHeight() + j
},
prepend: function(a, b) {
this.$element.prepend(a), this.reLayout(b)
},
append: function(a, b) {
this.$element.append(a), this.reLayout(b)
},
removeItems: function(a, b) {
this.$element.find(a).remove(), this.reLayout(b)
},
option: function(b, c) {
a.isPlainObject(b) && (this.options = a.extend(!0, this.options, b), "function" == typeof c && c(), this._init())
},
pause: function(a) {
this.options.state.isPause = !0, "function" == typeof a && a()
},
resume: function(a) {
this.options.state.isPause = !1, "function" == typeof a && a()
},
_requestData: function(b) {
var c, e = this,
f = this.options,
g = f.maxPage,
h = f.state.curPage++,
i = f.path,
j = f.dataType,
k = f.params,
l = f.headers;
return g !== d && h > g ? (f.state.isBeyondMaxPage = !0, void f.callbacks.loadingFinished(this.$loading, f.state.isBeyondMaxPage)) : (c = "function" == typeof i ? i(h) : i.join(h), this._debug("heading into ajax", c + a.param(k)), f.callbacks.loadingStart(this.$loading), f.state.isDuringAjax = !0, f.state.isProcessingData = !0, void a.ajax({
url: c,
data: k,
headers: l,
dataType: j,
success: function(a) {
e._handleResponse(a, b), e.options.state.isDuringAjax = !1
},
error: function(a) {
e._responeseError("error")
}
}))
},
_handleResponse: function(b, c) {
var d = this,
e = this.options,
f = a.trim(e.callbacks.renderData(b, e.dataType)),
g = a(f),
h = e.checkImagesLoaded;
h ? g.imagesLoaded(function() {
d.append(g, c), d.options.callbacks.loadingFinished(d.$loading, d.options.state.isBeyondMaxPage)
}) : (d.append(g, c), d.options.callbacks.loadingFinished(d.$loading, d.options.state.isBeyondMaxPage))
},
_responeseError: function(a) {
this.$loading.hide(), this.options.callbacks.loadingError(this.$message, a), "end" !== a && "error" !== a && (a = "unknown"), this._debug("Error", a)
},
_nearbottom: function() {
var a = this.options,
b = Math.min.apply({}, this.colHeightArray),
c = f.scrollTop() + f.height() - this.$element.offset().top - b;
return this._debug("math:", c), c > a.bufferPixel
},
_prefill: function() {
this.$element.height() <= f.height() && this._scroll()
},
_scroll: function() {
var a = this.options,
b = a.state,
c = this;
b.isProcessingData || b.isDuringAjax || b.isInvalidPage || b.isPause || this._nearbottom() && this._requestData(function() {
setTimeout(function() {
c._scroll()
}, 100)
})
},
_doScroll: function() {
var a, b = this;
f.bind("scroll", function() {
a && clearTimeout(a), a = setTimeout(function() {
b._scroll()
}, 100)
})
},
_resize: function() {
var a = this.cols,
b = this._getColumns();
(b !== a || "left" !== this.options.align) && (this.options.state.isResizing = !0, this.cols = b, this.reLayout(), this._prefill())
},
_doResize: function() {
var a, b = this;
f.bind("resize", function() {
a && clearTimeout(a), a = setTimeout(function() {
b._resize()
}, 100)
})
}
}, a.fn[g] = function(b) {
if ("string" == typeof b) {
var c = Array.prototype.slice.call(arguments, 1);
this.each(function() {
var d = a.data(this, "plugin_" + g);
return d ? a.isFunction(d[b]) && "_" !== b.charAt(0) ? void d[b].apply(d, c) : void d._debug('no such method "' + b + '"') : void d._debug("instance is not initialization")
})
} else this.each(function() {
a.data(this, "plugin_" + g) || a.data(this, "plugin_" + g, new e(this, b))
});
return this
}
}(jQuery, window, document),
function(a, b) {
"use strict";
var c = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
a.fn.imagesLoaded = function(d) {
function e() {
var b = a(m),
c = a(n);
i && (n.length ? i.reject(k, b, c) : i.resolve(k)), a.isFunction(d) && d.call(h, k, b, c)
}
function f(a) {
g(a.target, "error" === a.type)
}
function g(b, d) {
b.src !== c && -1 === a.inArray(b, l) && (l.push(b), d ? n.push(b) : m.push(b), a.data(b, "imagesLoaded", {
isBroken: d,
src: b.src
}), j && i.notifyWith(a(b), [d, k, a(m), a(n)]), k.length === l.length && (setTimeout(e), k.unbind(".imagesLoaded", f)))
}
var h = this,
i = a.isFunction(a.Deferred) ? a.Deferred() : 0,
j = a.isFunction(i.notify),
k = h.find("img").add(h.filter("img")),
l = [],
m = [],
n = [];
return a.isPlainObject(d) && a.each(d, function(a, b) {
"callback" === a ? d = b : i && i[a](b)
}), k.length ? k.bind("load.imagesLoaded error.imagesLoaded", f).each(function(d, e) {
var f = e.src,
h = a.data(e, "imagesLoaded");
return h && h.src === f ? void g(e, h.isBroken) : e.complete && e.naturalWidth !== b ? void g(e, 0 === e.naturalWidth || 0 === e.naturalHeight) : void((e.readyState || e.complete) && (e.src = c, e.src = f))
}) : e(), i ? i.promise(h) : h
}
}(jQuery);