Skip to content

Instantly share code, notes, and snippets.

@mtrpcic
Created April 26, 2011 19:19
Show Gist options
  • Save mtrpcic/942900 to your computer and use it in GitHub Desktop.
Save mtrpcic/942900 to your computer and use it in GitHub Desktop.
/*
---------
Copyright 2011, ZangZing LLC. All rights reserved.
*/
function ZZA(c, a, b) {
this.id = c;
this.zzv_id = null;
this.usertype = (this.useridentifier = a) ? 1 : 2;
if (b == undefined) b = false;
this.usemixpanel = b;
this.evts = [];
this.last = null;
this.maxevts = 10;
this.maxtime = 2500;
this.maxpushbytes = 2E3;
this.zzaurl = "http://zza.zangzing.com";
this.pindex = this.pushed = 0;
this.closing = false;
this.re = /[\x00-\x1f\\"]/;
this.stringescape = {
"\u0008": "\\b",
"\t": "\\t",
"\n": "\\n",
"\u000c": "\\f",
"\r": "\\r",
'"': '\\"',
"\\": "\\\\"
};
this.init = function () {
this.zzv_id = this._readCookie("_zzv_id");
if (this.zzv_id == null) {
var d = null,
e = location.host.lastIndexOf("zangzing.com");
if (e != -1 && e + 12 == location.host.length) d = "zangzing.com";
this.zzv_id = this.createUUID();
this._createCookie("_zzv_id", this.zzv_id, d, 10950)
}
var f = this;
window.setTimeout(function () {
f._timer()
}, 5E3)
};
this.track_event = function (d, e) {
this._track(d, this._getuserid(), this.usertype, null, e)
};
this.track_event2 = function (d, e) {
this._track(d, this._getuserid(), this.usertype, document.URL, e)
};
this.track_event_from_user = function (d, e, f) {
this._track(d, e, 1, null, f)
};
this.track_event_from_visitor = function (d, e, f) {
this._track(d, e, 2, null, f)
};
this.close = function () {
this.closing = true;
this._flush(true)
};
this.count = function () {
return this.evts.length
};
this.pushed_count = function () {
return this.pushed
};
this.mixpanel_ready = function () {
if (typeof mpmetrics != "undefined") {
for (var d = 0; d < this._mixpanel_queue.length; d++) mpmetrics.track(this._mixpanel_queue[d].e, this._mixpanel_queue[d].p);
this._mixpanel_queue = []
}
};
this._mixpanel_queue = [];
this._track = function (d, e, f, g, h) {
if (h == undefined) h = {};
if (f == 1 && d == "page.visit") h.zzv_id = this.zzv_id;
var i = {};
i.e = d;
i.t = (new Date).getTime();
i.u = e;
i.v = f;
i.x = h;
i.r = document.referrer;
if (g) i.p = g;
this.evts.push(i);
this.last = (new Date).getTime();
if (this.usemixpanel) {
p = {};
if (this.usertype == 1) p.Zuser = i.u;
else p.Zvisitor = i.u;
if (i.p) p.Zpageuri = i.p;
p.Zsource = this.id;
for (var j in i.x) p[j] = i.x[j];
typeof mpmetrics != "undefined" ? mpmetrics.track(i.e, p) : this._mixpanel_queue.push({
e: i.e,
p: p
})
}
};
this._getuserid = function () {
var d;
if (this.usertype == 1) d = this.useridentifier;
else if (this.usertype == 2) d = this.zzv_id;
return d
};
this._timer = function () {
this._flush(false);
var d = this;
window.setTimeout(function () {
d._timer()
}, 2E3)
};
this._flush = function (d) {
var e = false;
if (d) e = true;
else if (this.evts.length > this.maxevts) e = true;
else if (this.last != null) if ((new Date).getTime() - this.last > this.maxtime) e = true;
if (e) {
this._push();
this.evts = [];
this.last = null
}
};
this._getrandom = function (d) {
return Math.floor(Math.random() * (d + 1)) + 1
};
this._getevts = function () {
if (this.pindex > this.evts.length - 1) return null;
for (var d = this.maxpushbytes, e = []; this.pindex < this.evts.length;) {
var f = this.evts[this.pindex],
g = this.toJSONString(f).length;
if (g > d) break;
e.push(f);
d -= g;
this.pindex += 1
}
this.pushed += e.length;
return this.toJSONString({
id: this.id,
evts: e
})
};
this._usexhr = function () {
var d = window.navigator.userAgent.toLowerCase();
if (d.indexOf("safari") != -1 && d.indexOf("chrome") == -1) return true;
return false
};
this._push = function () {
if (this.evts.length != 0) for (this.pindex = 0; this.pindex < this.evts.length;) {
var d = this._getevts();
d = this.zzaurl + "/_z.gif?r=" + this._getrandom(1E7) + "&e=" + escape(d);
if (this.closing && this._usexhr()) {
xhr = new XMLHttpRequest;
xhr.open("GET", d, false);
xhr.send(null)
} else(new Image).src = d
}
};
this.encodeString = function (d) {
return d.replace(/[\x00-\x1f\\"]/g, function (e) {
var f = this.stringescape[e];
if (f) return f;
f = e.charCodeAt();
return "\\u00" + Math.floor(f / 16).toString(16) + (f % 16).toString(16)
})
};
this.toJSONString = function (d) {
switch (typeof d) {
case "string":
return '"' + (this.re.test(d) ? this.encodeString(d) : d) + '"';
case "number":
case "boolean":
return String(d);
case "object":
if (d) switch (d.constructor) {
case Array:
for (var e = [], f = 0, g = d.length; f < g; f++) e[e.length] = this.toJSONString(d[f]);
return "[" + e.join(",") + "]";
case Object:
e = [];
for (f in d) if (d.hasOwnProperty(f)) e[e.length] = '"' + (this.re.test(f) ? this.encodeString(f) : f) + '":' + this.toJSONString(d[f]);
return "{" + e.join(",") + "}";
case String:
return '"' + (this.re.test(d) ? this.encodeString(d) : d) + '"';
case Number:
case Boolean:
return String(d);
case Function:
case Date:
case RegExp:
return "undefined"
}
return "null";
case "function":
case "undefined":
case "unknown":
return "undefined";
default:
return "null"
}
};
this.createUUID = function () {
for (var d = [], e = 0; e < 32; e++) d[e] = "0123456789ABCDEF".substr(Math.floor(Math.random() * 16), 1);
d[12] = "4";
d[16] = "0123456789ABCDEF".substr(d[16] & 3 | 8, 1);
return d.join("")
};
this._createCookie = function (d, e, f, g) {
if (g) {
var h = new Date;
h.setTime(h.getTime() + g * 864E5);
g = "; expires=" + h.toGMTString()
} else g = "";
d = d + "=" + e + g + "; path=/";
if (f != null) d += "; domain=" + f;
document.cookie = d
};
this._readCookie = function (d) {
d += "=";
for (var e = document.cookie.split(";"), f = 0; f < e.length; f++) {
for (var g = e[f]; g.charAt(0) == " ";) g = g.substring(1, g.length);
if (g.indexOf(d) == 0) return g.substring(d.length, g.length)
}
return null
};
this._eraseCookie = function (d) {
createCookie(d, "", -1)
}
}
var agent = {
port: 30777,
agentId: null,
STATUS: {
READY: true,
NOT_RUNNING: false,
BAD_SESSION: "bad session"
},
getStatus: function (c) {
var a = this.buildAgentUrl("/ping");
$.jsonp({
url: a,
success: function (b) {
if (b.headers.status == 200) c(agent.STATUS.READY);
else {
ZZAt.track("agent.ping.invalid", b);
c(agent.STATUS.BAD_SESSION)
}
},
error: function () {
c(agent.STATUS.NOT_RUNNING)
}
})
},
isAvailable: function (c) {
this.callAgent("/ping", function () {
c(true)
}, function () {
c(false)
})
},
isAgentUrl: function (c) {
return c ? c.indexOf("http://localhost:" + agent.port) === 0 : false
},
checkAddCredentialsToUrl: function (c) {
if (this.isAgentUrl(c)) if (c.indexOf("session=") === -1 && typeof zz.current_user_id !== "undefined") {
c += c.indexOf("?") > -1 ? "&" : "?";
c += "session=" + $.cookie("user_credentials") + "&user_id=" + zz.current_user_id + "&callback=?"
}
return c
},
buildAgentUrl: function (c) {
var a = "";
if (!c) return c;
if (!agent.isAgentUrl(c)) if (c.indexOf("http://") !== -1 || c.indexOf("https://") !== -1) return c;
else a = "http://localhost:" + agent.port;
a += c;
a = a.replace(/http:\/\/localhost:[^\/]*/, "http://localhost:" + agent.port);
return this.checkAddCredentialsToUrl(a)
},
callAgent: function (c, a, b) {
var d, e = $.cookie("user_credentials");
d = c.indexOf("?") == -1 ? "http://localhost:" + this.port + c + "?session=" + e + "&user_id=" + zz.current_user_id + "&callback=?" : "http://localhost:" + this.port + c + "&session=" + e + "&user_id=" + zz.current_user_id + "&callback=?";
var f = function (g) {
g.headers ? logger.debug("error calling agent: " + g.headers.status + ":" + g.headers.error_message + " url: " + d) : logger.debug("no response or invalid response from agent. url: " + d);
typeof b != "undefined" && b()
};
$.jsonp({
url: d,
success: function (g) {
g.headers.status == 200 ? a(g.body) : f(g)
},
error: f
})
}
},
albums = {
deleteAlbum: function (c, a, b) {
$.ajax({
type: "POST",
dataType: "json",
data: {
_method: "delete"
},
url: zz.path_prefix + "/albums/" + c + ".json",
error: function () {
_.isUndefined(b) || a()
},
success: function () {
agent.callAgent("/albums/" + c + "/photos/*/cancel_upload");
_.isUndefined(a) || a()
}
})
}
},
async_ajax = {
MAX_CALLS: 35,
DELAY: 1E3,
get: function (c, a, b) {
var d = this,
e, f = 0,
g = function (h, i, j) {
var k = j.getResponseHeader("x-poll-for-response");
logger.debug(k);
k ? setTimeout(function () {
e(k)
}, d.DELAY) : a(h)
};
e = function (h) {
f++;
logger.debug("making call " + f);
f > d.MAX_CALLS ? b("timeout") : $.ajax({
url: h,
success: g,
error: function (i, j, k) {
logger.debug(j);
b(i, j, k)
}
})
};
e(c)
}
};
zzcontacts = {
ready: false,
data: [],
search_tree: [],
settings: {},
init: function (c, a, b, d) {
this.settings = $.extend({
url: zz.path_prefix + "/users/" + c + "/contacts.json"
}, a);
$.ajax({
type: "GET",
url: zzcontacts.settings.url,
dataType: "json",
success: function (e) {
zzcontacts.data = e;
zzcontacts.ready = true;
zzcontacts.init_buttons();
$.isFunction(b) && b()
},
error: function () {
$.isFunction(d) && d()
}
})
},
find: function (c) {
if (!zzcontacts.ready || !c) return null;
var a = RegExp(c, "gi");
c = [];
for (var b in zzcontacts.data) {
var d = jQuery.grep(zzcontacts.data[b].contacts, function (e) {
return e[0].match(a) || e[1].match(a)
});
c = c.concat(d)
}
return zzcontacts._format_results(c)
},
_format_results: function (c) {
var a = [],
b;
for (b in c) {
var d = c[b],
e = d[0];
d = d[1];
var f = e;
if (e.length > 0) e += " &lt;" + d + "&gt;";
else e = f = d;
a[b] = {
id: d,
name: e,
token_text: f
}
}
return a
},
import_contacts: function (c, a, b) {
if (!c) return null;
if (c == "local") zzcontacts._import_local_contacts(a, b);
else {
var d = false,
e = function () {
d = true;
async_ajax.get(zz.path_prefix + "/" + c + "/contacts/import", function (f) {
zzcontacts.data[c] = {};
zzcontacts.data[c].contacts = f;
zzcontacts.data[c].last_import = "A moment ago";
a()
}, function (f, g) {
b("import", g)
})
};
if (zzcontacts.data[c]) e();
else {
oauthmanager.login(zz.path_prefix + "/" + c + "/sessions/new", e);
setTimeout(function () {
d || b("oauth", "OAuth authorization not possible")
}, 2E4)
}
}
},
_import_local_contacts: function (c, a) {
agent.isAvailable(function (b) {
if (b) {
b = agent.buildAgentUrl("/contacts/import");
$.jsonp({
url: b,
success: function (d) {
zzcontacts.data.local = {};
zzcontacts.data.local.contacts = d.body;
zzcontacts.data.local.last_import = "A moment ago.";
$.isFunction(c) && c()
},
error: function (d, e) {
$.isFunction(a) && a("agent", e)
}
})
} else pages.no_agent.dialog(function () {
agent.isAvailable(function (d) {
if (d) zzcontacts.import_contacts("local", c, a);
else $.isFunction(a) && a("agent", "Please install agent.")
})
})
})
},
is_service_linked: function (c) {
return zzcontacts.ready && typeof zzcontacts.data[c] != "undefined"
},
init_buttons: function () {
$(".contacts-btn").each(function (c, a) {
var b = $(a),
d = b.attr("data-service");
d === "local" && $.client.os === "Mac" && b.find("span").html('<div class="off"></div>Mac Address Book');
if (zzcontacts.is_service_linked(d)) {
b.find("div").removeClass("off sync error").addClass("on");
b.attr("title", "Last import on:" + zzcontacts.data[d].last_import)
} else b.attr("title", "Click to import your contacts from this service");
b.click(function (e) {
e.preventDefault();
b.attr("disabled", "disabled");
b.find("div").removeClass("off on error").addClass("sync");
zzcontacts.import_contacts(d, function () {
b.find("div").removeClass("off sync error").addClass("on");
b.attr("title", "Last imported a moment ago.");
b.removeAttr("disabled")
}, function (f, g) {
b.find("div").removeClass("off sync on").addClass("error");
b.attr("title", "There was an error: " + g + ".");
b.removeAttr("disabled")
})
})
})
}
};
var css_transform = {
rotate: function (c, a, b, d) {
if ($.client.browser == "Explorer") this._ie_rotate(c, a, b, d);
else {
a = "rotate(" + a + "deg)";
$(c).css({
"-moz-transform": a,
"-webkit-transform": a
})
}
},
_ie_rotate: function (c, a, b, d) {
a /= 57;
var e = c.position().left,
f = c.position().top,
g = c.width(),
h = c.height();
if (b) e = b;
if (d) f = d;
b = g / 2;
h /= 2;
g = Math.cos(a);
var i = Math.sin(a);
a = g;
d = i;
i = -i;
var j = "progid:DXImageTransform.Microsoft.Matrix(";
j += "M11=" + a;
j += ", M21=" + d;
j += ", M12=" + i;
j += ", M22=" + g;
j += ', SizingMethod="auto expand")';
a = Math.abs(a);
i = Math.abs(i);
d = Math.abs(d);
g = Math.abs(g);
c.css({
filter: j,
left: Math.round(e + 0 - ((a - 1) * b + i * h)) + "px",
top: Math.round(f + 0 - (d * b + (g - 1) * h)) + "px"
})
}
};
if ($.client.os == "Mac") $("html").addClass("os-mac");
else $.client.os == "Windows" && $("html").addClass("os-win");
var zz_dialog = {
show_dialog: function (c, a) {
return $(c).zz_dialog(a).data().zz_dialog
},
show_confirmation_dialog: function () {},
show_alert_dialog: function () {},
CONFIRMATION_TEMPLATE: '<div class="message">{{message}}</div>',
ALERT_TEMPLATE: '<div class="message">{{message}}</div>',
BASE_Z_INDEX: 99990,
open_dialog_count: 0,
scrim_z_index: function () {
return this.BASE_Z_INDEX + this.open_dialog_count * 10
},
dialog_z_index: function () {
return this.scrim_z_index() + 1
}
};
(function (c) {
c.widget("ui.zz_dialog", {
options: {
modal: true,
cancelButton: true,
top: "auto",
left: "auto",
autoOpen: true,
height: "auto",
width: "auto"
},
_create: function () {
var a = this,
b = this.element;
if (b.parent().parent().size() <= 0) {
b.css("display", "none");
c("body").append(b)
}
b.wrap('<div class="zz_dialog"><div class="zz_dialog_inner"></div><a href="javascript:void(0)" class="zz_dialog_closer"></a></div>');
b.css("display", "block");
b.css("border", 0);
b.css("margin", 0);
a.dialogDiv = b.parent().parent();
a.dialogDiv.data("originalelement", a.element);
a.options.cancelButton && a.dialogDiv.find(".zz_dialog_closer").show().click(function () {
a.close()
});
a._setSize();
a.resize_handler = function () {
a._setPosition()
};
a.keypress_handler = function (d) {
d.stopPropagation()
};
if (a.options.modal) {
a.scrim = c('<div class="zz_dialog_scrim"></div>');
a.scrim.insertBefore(a.dialogDiv)
}
},
_init: function () {
this.options.autoOpen && this.open()
},
open: function () {
zz_dialog.open_dialog_count++;
if (this._trigger("beforeopen") !== false) {
this._setPosition();
c(window).resize(this.resize_handler);
if (this.options.modal) {
this.scrim.css({
"z-index": zz_dialog.scrim_z_index()
});
this.scrim.show();
c(window).keypress(this.keypress_handler)
}
this.dialogDiv.css({
"z-index": zz_dialog.dialog_z_index()
});
this.dialogDiv.fadeIn("fast");
this._trigger("open")
}
},
close: function () {
if (this._trigger("beforeclose") !== false) {
this.dialogDiv.fadeOut("fast");
this.options.modal && c(this.scrim).hide();
c(window).unbind("resize", this.resize_handler);
c(document).unbind("keypress", this.keypress_handler);
this._trigger("close");
this.destroy();
zz_dialog.open_dialog_count--
}
},
toggle: function () {
this.dialogDiv.css("display") == "none" ? this.open() : this.close()
},
destroy: function () {
c.Widget.prototype.destroy.apply(this, arguments);
this.options.modal && this.scrim.remove();
this.dialogDiv.empty().remove()
},
_setSize: function () {
var a = this.options;
a.height == "auto" ? this.dialogDiv.css("height", c(this.element).outerHeight(true)) : this.dialogDiv.css("height", a.height);
a.width == "auto" ? this.dialogDiv.css("width", c(this.element).outerWidth(true)) : this.dialogDiv.css("width", a.width)
},
_setPosition: function () {
this.options.top == "auto" ? this.dialogDiv.css("top", c(window).height() / 2 - this.dialogDiv.height() / 2) : this.dialogDiv.css("top", this.options.top);
this.options.left == "auto" ? this.dialogDiv.css("left", c(window).width() / 2 - this.dialogDiv.width() / 2) : this.dialogDiv.css("left", this.options.left)
}
})
})(jQuery);
var image_utils = {
scale: function (c, a) {
var b = Math.min(a.width / c.width, a.height / c.height);
return {
width: Math.floor(c.width * b),
height: Math.floor(c.height * b)
}
},
scale_center_and_crop: function (c, a) {
var b, d, e, f;
if (c.width / c.height > a.width / a.height) {
b = a.height;
e = 0;
d = Math.round(c.width / c.height * a.height);
f = Math.round((a.width - d) / 2)
} else {
d = a.width;
f = 0;
b = Math.round(c.height / c.width * a.width);
e = Math.round((a.height - b) / 2)
}
return {
top: e,
left: f,
height: b,
width: d
}
},
pre_load_image: function (c, a, b) {
var d = new Image;
d.onload = function () {
a && a(d)
};
d.onerror = function () {
b && b(d)
};
d.src = c;
return d
}
};
(function (c) {
c.fn.rowLeft = function () {
for (var a = this.position().top, b = this.prev(), d = []; b.length > 0 && b.position().top === a;) {
d.push(b[0]);
b = b.prev()
}
return c(d)
};
c.fn.rowRight = function () {
for (var a = this.position().top, b = this.next(), d = []; b.length > 0 && b.position().top === a;) {
d.push(b[0]);
b = b.next()
}
return c(d)
};
c.fn.animateRelative = function (a, b, d, e) {
c.each(this, function (f, g) {
var h = c(g);
h.animate({
left: parseInt(h.css("left")) + a,
top: parseInt(h.css("top")) + b
}, d, e)
})
};
c.fn.rotate = function (a) {
css_transform.rotate(this, a);
return this
};
c.fn.center_x = function (a) {
return this.center(a, true, false)
};
c.fn.center_y = function (a) {
return this.center(a, false, true)
};
c.fn.center_xy = function (a) {
return this.center(a, true, true)
};
c.fn.center = function (a, b, d) {
a || (a = c(this).parent());
if (c.isFunction(a.parent)) {
var e = c(a);
a = {
left: 0,
top: 0,
width: e.width(),
height: e.height()
}
}
_.each(this, function (f) {
f = c(f);
var g = Math.round((a.width - f.width()) / 2 + a.left),
h = Math.round((a.height - f.height()) / 2 + a.top);
if (b && d) f.css({
left: g,
top: h
});
else if (d) f.css({
top: h
});
else b && f.css({
left: g
})
});
return this
};
c.fn.disableEnterKey = function () {
_.each(this, function (a) {
c(a).bind("keypress", function (b) {
if (b.keyCode == 13) return false
})
})
}
})(jQuery);
var like = {
hash: {},
loaded: false,
init: function () {
var c = {};
$(".zzlike").each(function (a, b) {
c[$(b).attr("data-zzid")] = $(b).attr("data-zztype")
});
if ($.isEmptyObject(c)) like.loaded = true;
else like.add_id_array(c)
},
add_id_array: function (c) {
$.isEmptyObject(c) || $.ajax({
type: "POST",
url: zz.path_prefix + "/likes.json",
data: {
wanted_subjects: c
},
success: function (a) {
if (like.loaded) {
$.extend(like.hash, a);
for (key in a) like.refresh_tag(key)
} else {
like.hash = a;
like.draw_tags();
like.loaded = true
}
},
dataType: "json"
})
},
add_id: function (c, a) {
if (typeof c != "undefined" && typeof like.hash[c] == "undefined") {
var b = {};
b[c] = a;
like.add_id_array(b)
} else like.refresh_tag(c)
},
toggle: function () {
var c = $(this).attr("data-zzid"),
a = $(this).attr("data-zztype"),
b = zz.path_prefix + "/likes/" + c,
d = "like." + a + ".",
e = "post";
if (like.hash[c].user == true) {
e = "delete";
d += "unlike"
} else d += "like";
like.toggle_in_hash(c);
$.ajax({
type: "POST",
url: b,
data: {
subject_type: a,
_method: e
},
success: function (f) {
$("body").append(f);
like.display_social_dialog(c)
},
error: function (f) {
like.toggle_in_hash(c);
if (f.status == 401) {
f = zz.path_prefix + "/" + a + "s/" + c + "/like";
document.location.href = path_helpers.rails_route("signin") + "?return_to=" + f
}
}
});
ZZAt.track(d)
},
toggle_in_hash: function (c) {
if (like.loaded && c in like.hash) {
if (like.hash[c].user == true) {
like.hash[c].user = false;
like.hash[c].count -= 1
} else {
like.hash[c].user = true;
like.hash[c].count += 1
}
like.refresh_tag(c)
}
},
draw_tags: function () {
$(".zzlike").each(function (c, a) {
var b = $(a),
d = b.attr("data-zzid");
if (b.attr("data-zzstyle") == "menu") b.find("span.like-count").html("(" + like.hash[d].count.toString() + ")");
else {
button = $(' <div class="zzlike-button">Like</div>');
icon = $("<span></span>");
counter = $('<div class="zzlike-count">' + like.hash[d].count + "</div>");
like.hash[d].user ? $(icon).addClass("zzlike-thumbup") : $(icon).addClass("zzlike-vader");
$(button).prepend(icon);
b.empty();
b.append(button).append(counter)
}
b.click(like.toggle)
})
},
refresh_tag: function (c) {
like.hash[c] && $('.zzlike[data-zzid="' + c + '"]').each(function () {
if ($(this).attr("data-zzstyle") == "menu") $(this).find("span.like-count").html("(" + like.hash[c].count.toString() + ")");
else {
like.hash[c].user ? $(this).find("span.zzlike-vader").addClass("zzlike-thumbup").removeClass("zzlike-vader") : $(this).find("span.zzlike-thumbup").addClass("zzlike-vader").removeClass("zzlike-thumbup");
$(this).find("div.zzlike-count").html(like.hash[c].count)
}
})
},
display_social_dialog: function (c) {
$("#facebook_box").click(function () {
if ($(this).is(":checked") && !$("#facebook_box").attr("authorized")) {
$(this).attr("checked", false);
oauthmanager.login(zz.path_prefix + "/facebook/sessions/new", function () {
$("#facebook_box").attr("checked", true);
$("#facebook_box").attr("authorized", "yes")
})
}
});
$("#twitter_box").click(function () {
if ($(this).is(":checked") && !$("#twitter_box").attr("authorized")) {
$(this).attr("checked", false);
oauthmanager.login(zz.path_prefix + "/twitter/sessions/new", function () {
$("#twitter_box").attr("checked", true);
$("#twitter_box").attr("authorized", "yes")
})
}
});
$("#social-like-dialog").zz_dialog({
autoOpen: false
});
$("#ld-cancel").click(function () {
$("#social-like-dialog").zz_dialog("close");
$("#social-like-dialog").zz_dialog().empty().remove()
});
$("#ld-ok").click(function () {
$.ajax({
type: "POST",
url: zz.path_prefix + "/likes/" + c + "/post",
data: $("#social_like_form_" + c).serialize()
});
$("#social-like-dialog").zz_dialog("close");
$("#social-like-dialog").zz_dialog().empty().remove()
});
$("#social-like-dialog").zz_dialog("open")
}
};
(function (c) {
c.widget("ui.zzlike_menu", {
options: {
anchor: false
},
_create: function () {
var a = this,
b = this.element;
b.css("display", "none").addClass("like-menu");
var d = c(b).find(".zzlike").attr("data-zzstyle", "menu");
switch (d.length) {
case 1:
b.addClass("one-item");
break;
case 2:
b.addClass("two-items");
break;
case 3:
b.addClass("three-items")
}
c.each(d, function () {
switch (c(this).attr("data-zztype")) {
case "user":
c(this).addClass("like-user").html('Person <span class="like-count"></span>');
break;
case "album":
c(this).addClass("like-album").html('Album <span class="like-count"></span>');
break;
case "photo":
c(this).addClass("like-photo").html('Photo <span class="like-count"></span>')
}
});
b.parent().size() <= 0 && c("body").append(b);
a.options.anchor && c(a.options.anchor).click(function () {
a.open(this)
})
},
open: function (a) {
var b = this.element;
if (b.is(":hidden")) if (this._trigger("beforeopen") !== false) {
var d = c(a).offset();
a = c(a).outerWidth() / 2 + d.left - b.width() / 2;
d = c(document).height() - d.top;
b.css({
left: a,
bottom: d
}).slideDown("fast");
c(b).hover(function () {}, function () {
c(this).slideUp("fast")
});
setTimeout(function () {
c(document).click(function () {
if (b.is(":visible")) {
c(document).unbind("click");
c(b).slideUp("fast")
}
return false
})
}, 0);
c(window).one("resize", function () {
c(b).css("display", "none")
});
this._trigger("open")
}
},
destroy: function () {
c.Widget.prototype.destroy.apply(this, arguments)
}
})
})(jQuery);
var logger = {
debug: function (c) {
typeof console != "undefined" && console.log(c)
}
},
pages = {};
pages.album_add_photos_tab = {
chooserWidget: null,
init: function (c, a) {
var b = $('<div class="photochooser-container"></div>');
c.html(b);
this.chooserWidget = b.zz_photochooser({
album_id: zz.album_id
}).data().zz_photochooser;
ZZAt.track("album.add_photos_tab.view");
a()
},
bounce: function (c) {
this.chooserWidget.destroy();
c()
}
};
pages.album_name_tab = {
original_album_name: "",
init: function (c, a) {
var b = zz.path_prefix + "/albums/" + zz.album_id + "/name_album";
ZZAt.track("album.name_tab.view");
var d = 0;
c.load(b, function () {
$("form.edit_album input").disableEnterKey();
pages.album_name_tab.original_album_name = $("#album_name").val();
$("#album-header-title").text(pages.album_name_tab.original_album_name);
$("#album_name").keypress(function () {
setTimeout(function () {
$("#album-header-title").text($("#album_name").val())
}, 10)
});
setTimeout(function () {
$("#album_name").select()
}, 100);
$("#album_name").keypress(function () {
d++;
setTimeout(function () {
d--;
d == 0 && $.ajax({
url: zz.path_prefix + "/albums/" + zz.album_id + "/preview_album_email?" + $.param({
album_name: $("#album_name").val()
}),
success: function (e) {
$("#album_email").text(e.email);
$("#album_url").text(e.url)
},
error: function () {
$("#album_name").val(pages.album_name_tab.original_album_name);
$("h2#album-header-title").text(pages.album_name_tab.original_album_name)
}
})
}, 1E3)
});
$.ajax({
dataType: "json",
url: zz.path_prefix + "/albums/" + zz.album_id + "/photos_json?" + (new Date).getTime(),
success: function (e) {
var f = -1,
g = $("#album_cover_photo").val();
e = $.map(e, function (h, i) {
var j = h.id;
if (j == g) f = i;
var k = h.thumb_url;
k = agent.checkAddCredentialsToUrl(k);
return {
id: j,
src: k
}
});
$("#album-cover-picker").zz_thumbtray({
photos: e,
selectedIndex: f,
onSelectPhoto: function (h, i) {
var j = "",
k = "/images/album-no-cover.png";
if (h !== -1) {
j = i.id;
k = i.src;
$("#album_cover_img").css({
height: 100,
width: null
})
} else $("#album_cover_img").css({
height: 100,
width: 150
});
$("#album_cover_photo").val(j);
$("#album_cover_img").attr("src", k)
}
})
}
});
a()
})
},
bounce: function (c) {
$.ajax({
type: "POST",
url: zz.path_prefix + "/albums/" + zz.album_id,
data: $(".edit_album").serialize(),
success: c,
error: function () {
$("#album_name").val(pages.album_name_tab.original_album_name);
$("h2#album-header-title").text(pages.album_name_tab.original_album_name);
$("#album_name").keypress()
}
})
}
};
pages.edit_album_tab = {
init: function () {
ZZAt.track("album.edit_tab.view");
$.ajax({
dataType: "json",
url: zz.path_prefix + "/albums/" + zz.album_id + "/photos_json?" + (new Date).getTime(),
success: function (c) {
for (var a = 0; a < c.length; a++) {
var b = c[a];
b.previewSrc = agent.checkAddCredentialsToUrl(b.stamp_url);
b.src = agent.checkAddCredentialsToUrl(b.thumb_url)
}
c.push({
id: null,
type: "blank",
caption: ""
});
a = $('<div class="photogrid"></div>');
$("#article").html(a);
$("#article").css("overflow", "hidden");
$("#article").css("top", "120px");
a.zz_photogrid({
photos: c,
allowDelete: true,
cellWidth: 230,
cellHeight: 230,
onDelete: function (d, e) {
$.ajax({
type: "POST",
dataType: "json",
data: {
_method: "delete"
},
url: zz.path_prefix + "/photos/" + e.id + ".json",
error: function () {},
success: function () {
agent.callAgent("/albums/" + zz.album_id + "/photos/" + e.id + "/cancel_upload")
}
});
return true
},
allowEditCaption: true,
onChangeCaption: function (d, e, f) {
$.ajax({
type: "PUT",
dataType: "json",
url: zz.path_prefix + "/photos/" + e.id + ".json",
data: {
"photo[caption]": f
},
error: function () {}
});
return true
},
allowReorder: true,
onChangeOrder: function (d, e, f) {
var g = {};
if (e) g.before_id = e;
if (f) g.after_id = f;
$.ajax({
type: "PUT",
data: g,
dataType: "json",
url: zz.path_prefix + "/photos/" + d + "/position",
error: function () {}
});
return true
},
showThumbscroller: false
}).data();
$("#article").show()
}
})
},
bounce: function (c) {
c()
}
};
pages.album_privacy_tab = {
init: function (c, a) {
ZZAt.track("album.privacy_tab.view");
c.load(zz.path_prefix + "/albums/" + zz.album_id + "/privacy", function () {
$("#privacy-public").click(function () {
$.post(zz.path_prefix + "/albums/" + zz.album_id, "_method=put&album%5Bprivacy%5D=public", function () {
$("img.select-button").attr("src", path_helpers.image_url("/images/btn-round-selected-off.png"));
$("#privacy-public img.select-button").attr("src", path_helpers.image_url("/images/btn-round-selected-on.png"))
})
});
$("#privacy-hidden").click(function () {
$.post(zz.path_prefix + "/albums/" + zz.album_id, "_method=put&album%5Bprivacy%5D=hidden");
$("img.select-button").attr("src", path_helpers.image_url("/images/btn-round-selected-off.png"));
$("#privacy-hidden img.select-button").attr("src", path_helpers.image_url("/images/btn-round-selected-on.png"))
});
$("#privacy-password").click(function () {
$.post(zz.path_prefix + "/albums/" + zz.album_id, "_method=put&album%5Bprivacy%5D=password");
$("img.select-button").attr("src", path_helpers.image_url("/images/btn-round-selected-off.png"));
$("#privacy-password img.select-button").attr("src", path_helpers.image_url("/images/btn-round-selected-on.png"))
});
a()
})
},
bounce: function (c) {
c()
}
};
pages.share = {
init: function (c, a, b, d) {
ZZAt.track("album.share_tab.view");
if (_.isUndefined(b)) b = "album";
if (_.isUndefined(d)) d = zz.album_id;
var e = this;
c.load(zz.path_prefix + "/shares/new", function () {
zz.wizard.resize_scroll_body();
$(".social-share").click(function () {
e.show_social(c, b, d)
});
$(".email-share").click(function () {
e.show_email(c, b, d)
});
a()
})
},
share_in_dialog: function (c, a, b) {
var d = this,
e = $('<div id="share-dialog-content"></div>');
$('<div id="share-dialog"></div>').html(e).zz_dialog({
height: 450,
width: 895,
modal: true,
autoOpen: true,
open: function () {
d.init(e, function () {}, c, a)
},
close: function () {
_.isUndefined(b) || b()
}
})
},
bounce: function (c) {
c()
},
show_social: function (c, a, b) {
var d = this;
$("div#share-body").fadeOut("fast", function () {
$("div#share-body").load(zz.path_prefix + "/shares/newpost", function () {
zz.wizard.resize_scroll_body();
$("#facebook_box").click(function () {
if ($(this).is(":checked") && !$("#facebook_box").attr("authorized")) {
$(this).attr("checked", false);
oauthmanager.login(zz.path_prefix + "/facebook/sessions/new", function () {
$("#facebook_box").attr("checked", true);
$("#facebook_box").attr("authorized", "yes")
})
}
});
$("#twitter_box").click(function () {
if ($(this).is(":checked") && !$("#twitter_box").attr("authorized")) {
$(this).attr("checked", false);
oauthmanager.login(zz.path_prefix + "/twitter/sessions/new", function () {
$("#twitter_box").attr("checked", true);
$("#twitter_box").attr("authorized", "yes")
})
}
});
$("#new_post_share").validate({
rules: {
"post_share[message]": {
required: true,
minlength: 0,
maxlength: 118
},
"post_share[facebook]": {
required: "#twitter_box:unchecked"
},
"post_share[twitter]": {
required: "#facebook_box:unchecked"
}
},
messages: {
"post_share[message]": "",
"post_share[facebook]": "",
"post_share[twitter]": ""
},
submitHandler: function () {
var e = $("#new_post_share").serialize();
$.post(zz.path_prefix + "/" + a + "s/" + b + "/shares.json", e, function (f, g, h) {
pages.share.reload_share(c, a, b, function () {
zz.wizard.display_flashes(h, 200)
})
})
}
});
$("#cancel-share").click(function () {
d.reload_share(c, a, b)
});
$("#post_share_button").click(function () {
$("form#new_post_share").submit()
});
$("#post_share_message").keypress(function () {
setTimeout(function () {
var e = "characters",
f = $("#post_share_message").val().length;
if (f === 1) e = "character";
$("#character-count").text(f + " " + e)
}, 10)
});
$("div#share-body").fadeIn("fast")
})
})
},
show_email: function (c, a, b) {
var d = this;
$("div#share-body").fadeOut("fast", function () {
$("div#share-body").load(zz.path_prefix + "/shares/newemail", function () {
$("#contact-list").tokenInput(zzcontacts.find, {
allowNewValues: true,
classes: {
tokenList: "token-input-list-facebook",
token: "token-input-token-facebook",
tokenDelete: "token-input-delete-token-facebook",
selectedToken: "token-input-selected-token-facebook",
highlightedToken: "token-input-highlighted-token-facebook",
dropdown: "token-input-dropdown-facebook",
dropdownItem: "token-input-dropdown-item-facebook",
dropdownItem2: "token-input-dropdown-item2-facebook",
selectedDropdownItem: "token-input-selected-dropdown-item-facebook",
inputToken: "token-input-input-token-facebook"
}
});
zzcontacts.init(zz.current_user_id);
zz.wizard.resize_scroll_body();
$("#new_email_share").validate({
rules: {
"email_share[to]": {
required: true,
minlength: 0
},
"email_share[message]": {
required: true,
minlength: 0
}
},
messages: {
"email_share[to]": "At least one recipient is required",
"email_share[message]": ""
},
submitHandler: function () {
var e = $("#new_email_share").serialize();
$.post(zz.path_prefix + "/" + a + "s/" + b + "/shares.json", e, function (f, g, h) {
d.reload_share(c, a, b, function () {
zz.wizard.display_flashes(h, 200)
})
}, "json")
}
});
$("#cancel-share").click(function () {
d.reload_share(c, a, b)
});
$("#mail-submit").click(function () {
$("form#new_email_share").submit()
});
$("div#share-body").fadeIn("fast")
})
})
},
reload_share: function (c, a, b, d) {
var e = this;
c.fadeOut("fast", function () {
e.init(c, function () {
c.fadeIn("fast");
typeof d != "undefined" && d()
}, a, b)
})
}
};
pages.contributors = {
present: false,
url: "",
init: function (c, a) {
ZZAt.track("album.contributors_tab.view");
this.url = zz.path_prefix + "/albums/" + zz.album_id + "/contributors";
pages.contributors.show_list(c, a)
},
bounce: function (c) {
c()
},
show_list: function (c, a, b) {
c.load(pages.contributors.url, function () {
if (tmp_contact_list.length <= 0) {
pages.contributors.present = false;
pages.contributors.show_new(c, a)
} else {
pages.contributors.present = true;
$("#contributors-list").tokenInput("", {
allowNewValues: false,
displayOnly: true,
prePopulate: {
data: tmp_contact_list,
forceDataFill: true
},
classes: {
tokenList: "token-input-list-facebook",
token: "token-input-token-facebook",
tokenDelete: "token-input-delete-token-facebook",
selectedToken: "token-input-selected-token-facebook",
highlightedToken: "token-input-highlighted-token-facebook",
dropdown: "token-input-dropdown-facebook",
dropdownItem: "token-input-dropdown-item-facebook",
dropdownItem2: "token-input-dropdown-item2-facebook",
selectedDropdownItem: "token-input-selected-dropdown-item-facebook",
inputToken: "token-input-input-token-facebook"
}
});
$("#contributors-list").bind("tokenDeleted", function (d, e, f, g) {
$.post(pages.contributors.url, {
_method: "delete",
id: e
}, function (h, i, j) {
zz.wizard.display_flashes(j, 200);
if (g <= 0) {
pages.contributors.present = false;
c.fadeOut("fast", function () {
pages.contributors.show_new(c)
})
}
})
});
zz.wizard.resize_scroll_body();
$("#add-contributors-btn").click(function () {
c.fadeOut("fast", function () {
pages.contributors.show_new(c)
})
});
c.fadeIn("fast", function () {
typeof b != "undefined" && zz.wizard.display_flashes(b, 200)
});
_.isUndefined(a) || a()
}
})
},
show_new: function (c, a) {
c.load(zz.path_prefix + "/albums/" + zz.album_id + "/contributors/new", function () {
$("#contact-list").tokenInput(zzcontacts.find, {
allowNewValues: true,
classes: {
tokenList: "token-input-list-facebook",
token: "token-input-token-facebook",
tokenDelete: "token-input-delete-token-facebook",
selectedToken: "token-input-selected-token-facebook",
highlightedToken: "token-input-highlighted-token-facebook",
dropdown: "token-input-dropdown-facebook",
dropdownItem: "token-input-dropdown-item-facebook",
dropdownItem2: "token-input-dropdown-item2-facebook",
selectedDropdownItem: "token-input-selected-dropdown-item-facebook",
inputToken: "token-input-input-token-facebook"
}
});
zzcontacts.init(zz.current_user_id);
zz.wizard.resize_scroll_body();
$("#new_contributors").validate({
rules: {
contact_list: {
required: true
},
contact_message: {
required: true
}
},
messages: {
contact_list: "Empty",
contact_message: ""
},
submitHandler: function () {
$.ajax({
type: "POST",
url: zz.path_prefix + "/albums/" + zz.album_id + "/contributors.json",
data: $("#new_contributors").serialize(),
success: function (b, d, e) {
c.fadeOut("fast", "swing", function () {
pages.contributors.show_list(c, a, e)
})
}
})
}
});
pages.contributors.present ? $("#cancel-new-contributors").click(function () {
c.fadeOut("fast", function () {
pages.contributors.show_list(c, a)
})
}) : $("#cancel-new-contributors").hide();
$("#submit-new-contributors").click(function () {
$("form#new_contributors").submit()
});
c.fadeIn("fast");
_.isUndefined(a) || a()
})
}
};
pages.no_agent = {
NO_AGENT_URL: "/static/connect_messages/no_agent.html",
OSX_10_5_URL: "/static/connect_messages/no_agent_unsupported_os.html",
get_message_url: function () {
if (navigator.appVersion.indexOf("Mac OS X 10_5") != -1) {
ZZAt.track("agentdownload.requested.osx10_5");
return this.OSX_10_5_URL
} else {
ZZAt.track("agentdownload.requested");
return this.NO_AGENT_URL
}
},
keep_polling: function () {
return $(".zangzing-downloader").length > 0
},
filechooser: function (c, a) {
c.load(pages.no_agent.get_message_url(), function () {
$(".zangzing-downloader").css({
top: "-70px"
});
$(".zangzing-downloader #download-btn").click(function () {
pages.no_agent.download()
});
pages.no_agent.keep_polling();
pages.no_agent.poll_agent(function () {
$.isFunction(a) && a()
})
})
},
dialog: function (c) {
$("<div></div>", {
id: "no-agent-dialog"
}).load(pages.no_agent.get_message_url(), function () {
$(".zangzing-downloader #download-btn").click(function () {
pages.no_agent.download()
});
$(this).zz_dialog({
modal: true,
width: 910,
height: 510,
close: function () {
c && c()
}
});
$(".zangzing-downloader #download-btn").click(function () {
pages.no_agent.download()
});
pages.no_agent.poll_agent(function () {
$("#no-agent-dialog").zz_dialog("close")
})
})
},
poll_agent: function (c) {
agent.getStatus(function (a) {
if (a == agent.STATUS.READY) {
$(".zangzing-downloader #download-btn").attr("disabled", "disabled");
$(".zangzing-downloader .step.four .graphic").addClass("ready");
c && setTimeout(c, 2E3);
ZZAt.track("agentdownload.ready")
} else if (a == agent.STATUS.BAD_SESSION) {
alert("Sorry, your session has expired. Please sign in again.");
document.location.href = path_helpers.rails_route("signin")
} else pages.no_agent.keep_polling() && setTimeout(function () {
pages.no_agent.poll_agent(c)
}, 1E3)
})
},
download: function () {
ZZAt.track("agentdownload.get");
if ($.client.os == "Mac") document.location.href = zz.mac_download_url;
else if ($.client.browser == "Chrome") window.open(zz.win_download_url);
else document.location.href = zz.win_download_url
}
};
pages.alert_dialog = {
show: function (c) {
typeof c != "undefined" && $.ajax({
type: "GET",
url: c,
success: function (a) {
$("body").append(a)
}
})
}
};
var path_helpers = {
image_url: function (c) {
return zz.rails_asset_host ? "http://" + zz.rails_asset_host.replace("%d", c.length % 4) + c + "?" + zz.rails_asset_id : c + "?" + zz.rails_asset_id
},
rails_route: function (c, a) {
if (c == "edit_user") return "/" + a + "/settings";
else if (c == "delete_identity") return "/service/" + a + "/sessions/destroy";
else if (c == "new_identity") return "/service/" + a + "/sessions/new";
else if (c == "signin") return "/signin";
return null
}
};
(function (c, a) {
c.widget("ui.zz_photo", {
options: {
allowDelete: false,
onDelete: jQuery.noop,
maxHeight: 120,
maxWidth: 120,
caption: null,
allowEditCaption: false,
onChangeCaption: jQuery.noop,
src: null,
previewSrc: null,
rolloverSrc: null,
scrollContainer: null,
lazyLoadThreshold: 0,
onClick: jQuery.noop,
onMagnify: jQuery.noop,
photoId: null,
aspectRatio: 0,
isUploading: false,
isUploading: false,
isError: false,
showButtonBar: false,
onClickShare: jQuery.noop,
context: null,
type: "photo"
},
_create: function () {
var b = this;
if (b.options.scrollContainer.data().zz_photogrid) b.photoGrid = b.options.scrollContainer.data().zz_photogrid;
var d = "";
d += '<div class="photo-caption"></div>';
d += '<div class="photo-border">';
d += ' <img class="photo-image" src="' + path_helpers.image_url("/images/blank.png") + '">';
d += ' <div class="photo-delete-button"></div>';
d += ' <div class="photo-uploading-icon"></div>';
d += ' <div class="photo-error-icon"></div>';
d += ' <img class="bottom-shadow" src="' + path_helpers.image_url("/images/photo/bottom-full.png") + '">';
if (b.options.context.indexOf("chooser") === 0 && b.options.type === "photo") {
d += ' <div class="photo-add-button"></div>';
d += ' <div class="magnify-button"></div>'
}
d += "</div>";
c(d).appendTo(this.element);
b.borderElement = this.element.find(".photo-border");
b.imageElement = this.element.find(".photo-image");
b.captionElement = this.element.find(".photo-caption");
b.deleteButtonElement = this.element.find(".photo-delete-button");
b.uploadingElement = this.element.find(".photo-uploading-icon");
b.errorElement = this.element.find(".photo-error-icon");
b.bottomShadow = this.element.find(".bottom-shadow");
b.captionElement.text(b.options.caption);
if (b.options.type === "blank") {
b.borderElement.hide();
b.captionElement.hide()
}
if (b.options.context.indexOf("chooser") === 0) {
this.element.find(".magnify-button").click(function () {
b.options.onClick("magnify")
});
b.element.find(".photo-add-button").click(function () {
b.options.onClick("main")
});
b.options.type !== "photo" && b.borderElement.addClass("no-shadow")
}
b.imageElement.click(function () {
b.options.onClick("main")
});
b.captionHeight = 30;
var e;
if (b.options.aspectRatio) {
e = image_utils.scale({
width: 1 * b.options.aspectRatio,
height: 1
}, {
width: b.options.maxWidth,
height: b.options.maxHeight - b.captionHeight
});
d = e.height;
e = e.width
} else e = d = Math.min(b.options.maxWidth, b.options.maxHeight);
b.imageElement.css({
width: e,
height: d
});
b.bottomShadow.css({
width: e + 14 + "px"
});
b.width = parseInt(b.element.css("width"));
b.height = parseInt(b.element.css("height"));
e += 10;
d += 10;
b.borderElement.css({
position: "relative",
top: (b.height - d - b.captionHeight) / 2,
left: (b.width - e) / 2,
width: e,
height: d
});
b.options.isUploading && !b.options.isError && b.uploadingElement.show();
b.options.isError && b.errorElement.show();
b.options.allowDelete ? b.deleteButtonElement.click(function () {
if (b.options.onDelete()) {
b.captionElement.hide();
b.deleteButtonElement.hide();
b.borderElement.hide("scale", {}, 300, function () {
b.element.animate({
width: 0
}, 500, function () {
b.element.remove();
b.photoGrid && b.photoGrid.resetLayout()
})
})
}
}) : b.deleteButtonElement.remove();
b.options.allowEditCaption && b.captionElement.click(function () {
b.editCaption()
});
b.options.type !== "photo" ? b._loadImage() : b.imageElement.attr("src", path_helpers.image_url("/images/photo_placeholder.png"));
if (b.options.rolloverSrc) {
image_utils.pre_load_image(b.options.rolloverSrc);
b.element.mouseover(function () {
b.imageElement.attr("src", b.options.rolloverSrc)
});
b.element.mouseout(function () {
b.imageElement.attr("src", b.options.src)
})
}
if (b.options.showButtonBar) {
b.borderElement.mouseenter(function () {
b.toolbarElement = c('<div class="photo-toolbar"><div class="buttons"><div class="share-button"></div><div class="like-button"></div><div class="info-button"></div></div></div>');
b.borderElement.append(b.toolbarElement);
b.borderElement.css({
"padding-bottom": "30px"
});
b.imageElement.css({
"border-bottom": "35px solid #fff"
});
b.toolbarElement.find(".share-button").click(function () {
b.options.onClickShare(b.options.photoId)
});
b.toolbarElement.find(".like-button").click(function () {
alert("This feature is still under construction. This will allow you to like an individual photo.")
});
b.toolbarElement.find(".info-button").click(function () {
alert("This feature is still under construction. This will show a menu with options for downloading original photo, etc.")
})
});
b.borderElement.mouseleave(function () {
b.borderElement.css({
"padding-bottom": "0px"
});
b.imageElement.css({
"border-bottom": "5px solid #fff"
});
b.toolbarElement.remove()
})
}
},
checked: false,
isChecked: function () {
return this.checked
},
setChecked: function (b) {
this.checked = b;
if (this.options.context.indexOf("chooser") === 0) b ? this.element.find(".photo-add-button").addClass("checked") : this.element.find(".photo-add-button").removeClass("checked")
},
loadIfVisible: function (b) {
this.imageLoaded || this._inLazyLoadRegion(b) && this._loadImage()
},
_loadImage: function () {
var b = this,
d = b.options.src;
if (b.options.previewSrc) d = b.options.previewSrc;
image_utils.pre_load_image(d, function (e) {
b.imageObject = e;
b.imageLoaded = true;
b._resize(1);
b.imageElement.attr("src", d);
image_utils.pre_load_image(b.options.src, function () {
b.imageElement.attr("src", b.options.src)
})
})
},
_resize: function () {
var b = image_utils.scale({
width: this.imageObject.width,
height: this.imageObject.height
}, {
width: this.options.maxWidth,
height: this.options.maxHeight - this.captionHeight
}),
d = b.width + 10,
e = b.height + 10;
this.borderElement.css({
top: (this.height - e - this.captionHeight) / 2,
left: (this.width - d) / 2,
width: d,
height: e
});
this.imageElement.css({
width: b.width,
height: b.height
});
this.bottomShadow.css({
width: b.width + 14 + "px"
})
},
_inLazyLoadRegion: function (b) {
var d = this.options.scrollContainer,
e = this.options.lazyLoadThreshold;
if (b) var f = b.offset,
g = b.height,
h = b.width;
else {
f = c(d).offset();
g = c(d).height();
h = c(d).width()
}
b = c(this.element).offset();
var i = this.options.maxWidth,
j = this.options.maxHeight;
if (d === a || d === window) {
d = c(window).height() + c(window).scrollTop();
g = c(window).width() + c(window).scrollLeft();
h = c(window).scrollTop();
f = c(window).scrollLeft()
} else {
d = f.top + g;
g = f.left + h;
h = f.top;
f = f.left
}
j = h >= b.top + e + j;
g = g <= b.left - e;
d = d <= b.top - e;
return !(f >= b.left + e + i) && !g && !j && !d
},
editCaption: function () {
var b = this;
if (!b.isEditingCaption) {
b.isEditingCaption = true;
var d = c('<div class="edit-caption-border"><input type="text"><div class="caption-ok-button"></div></div>');
b.captionElement.html(d);
var e = d.find("input"),
f = function () {
var g = e.val();
if (g !== b.options.caption) {
b.options.caption = g;
b.options.onChangeCaption(g)
}
b.captionElement.text(g);
b.isEditingCaption = false
};
e.val(b.options.caption);
e.focus();
e.select();
e.blur(function () {
f()
});
e.keydown(function (g) {
if (g.which == 13) {
f();
return false
} else if (g.which == 9) {
if (g.shiftKey) {
e.blur();
b.element.prev().length !== 0 ? b.element.prev().data().zz_photo.editCaption() : b.element.parent().children().last().data().zz_photo.editCaption()
} else {
e.blur();
b.element.next().length !== 0 ? b.element.next().data().zz_photo.editCaption() : b.element.parent().children().first().data().zz_photo.editCaption()
}
g.stopPropagation();
return false
}
});
d.find(".caption-ok-button").click(function (g) {
f();
g.stopPropagation();
return false
})
}
},
getPhotoId: function () {
return this.options.photoId
},
dragStart: function () {
this.element.addClass("dragging")
},
dragEnd: function () {
this.element.removeClass("dragging")
},
dragHelper: function () {
var b = this.element.clone();
b.find(".photo-delete-button").hide();
return b
},
destroy: function () {
c.Widget.prototype.destroy.apply(this, arguments)
}
})
})(jQuery);
var photochooser = {
open_in_dialog: function (c, a) {
var b = null,
d = $('<div class="photochooser-container"></div>');
$('<div id="add-photos-dialog"></div>').html(d).zz_dialog({
height: $(document).height() - 200,
width: 895,
modal: true,
autoOpen: true,
open: function () {
b = d.zz_photochooser({
album_id: c
}).data().zz_photochooser
},
close: function () {
b.destroy();
$.ajax({
url: zz.path_prefix + "/albums/" + c + "/close_batch",
complete: function (e, f) {
logger.debug("Batch closed because Add photos dialog was closed. Call to close_batch returned with status= " + f)
},
success: function () {
a && a()
}
})
}
});
d.height($(document).height() - 192)
}
};
(function (c) {
c.widget("ui.zz_photochooser", {
options: {
album_id: null
},
stack: [],
grid: null,
destroyed: false,
_create: function () {
var a = this,
b = c('<div class="photochooser"> <div class="photochooser-body"></div> <div class="photochooser-header"> <a class="back-button"><span>Back</span></a> <h3>Folder Name</h3> <h4>Choose pictures from folders on your computer or other photo sites</h4> </div> <div class="photochooser-footer"> <div class="added-pictures-tray"></div> <div class="added-pictures-tab"></div> </div></div>');
a.backButtonCaptionElement = b.find(".back-button span");
a.backButtonElement = b.find(".back-button");
a.folderNameElement = b.find("h3");
a.bodyElement = b.find(".photochooser-body");
a.element.html(b);
a.backButtonElement.click(function () {
c(".photochooser-header h3").show();
c(".photochooser-header h4").show();
a.goBack()
});
a.showRoots();
a.init_tray()
},
destroy: function () {
this.destroyed = true;
c.Widget.prototype.destroy.apply(this, arguments)
},
callAgentOrServer: function (a) {
var b = a.url,
d = a.success,
e = a.error;
if (agent.isAgentUrl(b)) {
b = agent.checkAddCredentialsToUrl(b);
c.jsonp({
url: b,
success: function (f) {
f.headers.status == 200 ? d(f.body) : e(f)
},
error: e
})
} else async_ajax.get(b, d, e)
},
goBack: function () {
this.stack.pop();
this.openFolder(this.stack.pop())
},
showRoots: function () {
this.openFolder({
name: "Home",
children: this.roots()
})
},
openFolder: function (a) {
var b = this;
b.folderNameElement.text(a.name);
if (b.stack.length > 0) {
b.backButtonCaptionElement.text(_.last(b.stack).name);
b.backButtonElement.show()
} else b.backButtonElement.hide();
b.stack.push(a);
b.bodyElement.html('<img class="progress-indicator" src="' + path_helpers.image_url("/images/loading.gif") + '">');
_.isUndefined(a.children) ? b.callAgentOrServer({
url: a.open_url,
success: function (d) {
a.children = d;
b.showFolder(a, d)
},
error: function (d) {
if (_.isUndefined(a.on_error)) alert("Sorry, there was a problem opening this folder. Please try again later.");
else a.on_error(d)
}
}) : b.showFolder(a, a.children)
},
showFolder: function (a, b) {
var d = this;
if (b.length) {
var e = false;
b = c.map(b, function (h) {
if (h.type === "folder") {
if (typeof h.src === "undefined") {
h.src = path_helpers.image_url("/images/folders/blank_off.jpg");
h.rolloverSrc = path_helpers.image_url("/images/folders/blank_on.jpg")
}
} else {
h.src = agent.checkAddCredentialsToUrl(h.thumb_url);
h.id = h.source_guid;
e = true
}
h.caption = h.name;
return h
});
if (e) {
var f = {
id: "add-all-photos",
src: path_helpers.image_url("/images/blank.png"),
caption: "",
type: "blank"
};
b.unshift(f)
}
var g = c('<div class="photogrid"></div>');
d.bodyElement.html(g);
d.grid = g.zz_photogrid({
photos: b,
showThumbscroller: false,
cellWidth: 190,
cellHeight: 190,
context: "chooser-grid",
onClickPhoto: function (h, i, j, k) {
if (i.type === "folder") d.openFolder(i);
else if (k === "main") c(j).data().zz_photo.isChecked() ? d.remove_photo_by_guid(i.id) : d.add_photo_to_album(i.add_url, j);
else if (k === "magnify") {
e && b.shift();
d.singlePictureView(a, b, i.id)
}
}
}).data().zz_photogrid;
if (e) {
f = c('<img class="add-all-button" src="' + path_helpers.image_url("/images/folders/add_all_photos.png") + '">');
f.click(function () {
d.add_folder_to_album(a.add_url, f)
});
c(".photochooser .photochooser-body .photogrid").append(f)
}
d.updateCheckmarks()
} else d.bodyElement.html('<div class="no-photos">There are no photos in this folder</div>')
},
singlePictureView: function (a, b, d) {
var e = this;
b = c.map(b, function (h) {
h.previewSrc = agent.checkAddCredentialsToUrl(h.thumb_url);
h.src = agent.checkAddCredentialsToUrl(h.screen_url);
return h
});
var f = c('<a class="prev-button"></a><div class="singlepicture-wrapper"><div class="photogrid"></div></div><a class="next-button"></a>'),
g = f.find(".photogrid");
e.bodyElement.html(f);
f.filter(".next-button").css({
top: e.bodyElement.height() / 2 - 36
});
f.filter(".prev-button").css({
top: e.bodyElement.height() / 2 - 36
});
e.grid = g.zz_photogrid({
photos: b,
showThumbscroller: false,
hideNativeScroller: true,
cellWidth: 720,
cellHeight: e.element.parent().height() - 130,
singlePictureMode: true,
currentPhotoId: d,
context: "chooser-picture",
lazyLoadThreshold: 0,
onClickPhoto: function (h, i, j, k) {
if (i.type === "folder") e.openFolder(i);
else if (k === "main") c(j).data().zz_photo.isChecked() ? e.remove_photo_by_guid(i.id) : e.add_photo_to_album(i.add_url, j);
else k === "magnify" && e.showFolder(a, b)
}
}).data().zz_photogrid;
e.updateCheckmarks();
f.filter(".prev-button").click(function () {
e.grid.previousPicture()
});
f.filter(".next-button").click(function () {
e.grid.nextPicture()
})
},
open_login_window: function (a, b) {
var d = this;
oauthmanager.login(b, function () {
d.openFolder(a)
})
},
roots: function () {
var a = this,
b = [],
d = function (e) {
if (typeof e.status === "undefined") {
c(".photochooser-header h3").hide();
c(".photochooser-header h4").hide();
pages.no_agent.filechooser(a.bodyElement, function () {
a.openFolder(a.stack.pop());
c(".photochooser-header h3").show();
c(".photochooser-header h4").show()
});
a.bodyElement.fadeIn("fast")
} else if (e.status === 401) a.bodyElement.hide().load("/static/connect_messages/wrong_agent_account.html", function () {
a.bodyElement.fadeIn("fast")
});
else e.status === 500 && a.bodyElement.hide().load("/static/connect_messages/general_agent_error.html", function () {
a.bodyElement.fadeIn("fast")
})
};
if (navigator.appVersion.indexOf("Mac") != -1) {
b.push({
open_url: agent.buildAgentUrl("/filesystem/folders/fi9QaWN0dXJlcw=="),
add_url: agent.buildAgentUrl("/filesystem/folders/fi9QaWN0dXJlcw==/add_to_album"),
type: "folder",
name: "My Pictures",
on_error: d,
src: path_helpers.image_url("/images/folders/mypictures_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/mypictures_on.jpg"),
state: "ready"
});
b.push({
open_url: agent.buildAgentUrl("/iphoto/folders"),
type: "folder",
name: "iPhoto",
on_error: d,
src: path_helpers.image_url("/images/folders/iphoto_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/iphoto_on.jpg"),
state: "ready"
});
b.push({
open_url: agent.buildAgentUrl("/picasa/folders"),
type: "folder",
name: "Picasa",
on_error: d,
src: path_helpers.image_url("/images/folders/picasa_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/picasa_on.jpg"),
state: "ready"
});
b.push({
open_url: agent.buildAgentUrl("/filesystem/folders/fg=="),
add_url: agent.buildAgentUrl("/filesystem/folders/fg==/add_to_album"),
type: "folder",
name: "My Home",
on_error: d,
src: path_helpers.image_url("/images/folders/myhome_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/myhome_on.jpg"),
state: "ready"
});
b.push({
open_url: agent.buildAgentUrl("/filesystem/folders/L1ZvbHVtZXM="),
type: "folder",
name: "My Computer",
on_error: d,
src: path_helpers.image_url("/images/folders/mycomputer_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/mycomputer_on.jpg"),
state: "ready"
})
}
if (navigator.appVersion.indexOf("Win") != -1) {
b.push({
open_url: agent.buildAgentUrl("/filesystem/folders/flxNeSBEb2N1bWVudHNcTXkgUGljdHVyZXM="),
add_url: agent.buildAgentUrl("/filesystem/folders/flxNeSBEb2N1bWVudHNcTXkgUGljdHVyZXM=/add_to_album"),
type: "folder",
name: "My Pictures",
on_error: d,
src: path_helpers.image_url("/images/folders/mypictures_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/mypictures_on.jpg"),
state: "ready"
});
b.push({
open_url: agent.buildAgentUrl("/picasa/folders"),
type: "folder",
name: "Picasa",
on_error: d,
src: path_helpers.image_url("/images/folders/picasa_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/picasa_on.jpg"),
state: "ready"
});
b.push({
open_url: agent.buildAgentUrl("/filesystem/folders/fg=="),
add_url: agent.buildAgentUrl("/filesystem/folders/fg==/add_to_album"),
type: "folder",
name: "My Home",
on_error: d,
src: path_helpers.image_url("/images/folders/myhome_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/myhome_on.jpg"),
state: "ready"
});
b.push({
open_url: agent.buildAgentUrl("/filesystem/folders"),
type: "folder",
name: "My Computer",
on_error: d,
src: path_helpers.image_url("/images/folders/mycomputer_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/mycomputer_on.jpg"),
state: "ready"
})
}
b.push({
open_url: zz.path_prefix + "/facebook/folders.json",
type: "folder",
name: "Facebook",
src: path_helpers.image_url("/images/folders/facebook_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/facebook_on.jpg"),
on_error: function () {
var e = this;
a.bodyElement.hide().load("/static/connect_messages/connect_to_facebook.html", function () {
a.bodyElement.find("#connect-button").click(function () {
a.open_login_window(e, zz.path_prefix + "/facebook/sessions/new")
});
a.bodyElement.fadeIn("fast")
})
}
});
b.push({
open_url: zz.path_prefix + "/instagram/folders.json",
type: "folder",
name: "Instagram",
src: path_helpers.image_url("/images/folders/instagram_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/instagram_on.jpg"),
on_error: function () {
var e = this;
a.bodyElement.hide().load("/static/connect_messages/connect_to_instagram.html", function () {
a.bodyElement.find("#connect-button").click(function () {
a.open_login_window(e, zz.path_prefix + "/instagram/sessions/new")
});
a.bodyElement.fadeIn("fast")
})
}
});
b.push({
open_url: zz.path_prefix + "/shutterfly/folders.json",
type: "folder",
name: "Shutterfly",
src: path_helpers.image_url("/images/folders/shutterfly_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/shutterfly_on.jpg"),
on_error: function () {
var e = this;
a.bodyElement.hide().load("/static/connect_messages/connect_to_shutterfly.html", function () {
a.bodyElement.find("#connect-button").click(function () {
a.open_login_window(e, zz.path_prefix + "/shutterfly/sessions/new")
});
a.bodyElement.fadeIn("fast")
})
}
});
b.push({
open_url: zz.path_prefix + "/kodak/folders.json",
type: "folder",
name: "Kodak",
src: path_helpers.image_url("/images/folders/kodak_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/kodak_on.jpg"),
on_error: function () {
var e = this;
a.bodyElement.hide().load("/static/connect_messages/connect_to_kodak.html", function () {
a.bodyElement.find("#connect-button").click(function () {
a.open_login_window(e, zz.path_prefix + "/kodak/sessions/new")
});
a.bodyElement.fadeIn("fast")
})
}
});
b.push({
open_url: zz.path_prefix + "/smugmug/folders.json",
type: "folder",
name: "SmugMug",
src: path_helpers.image_url("/images/folders/smugmug_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/smugmug_on.jpg"),
on_error: function () {
var e = this;
a.bodyElement.hide().load("/static/connect_messages/connect_to_smugmug.html", function () {
a.bodyElement.find("#connect-button").click(function () {
a.open_login_window(e, zz.path_prefix + "/smugmug/sessions/new")
});
a.bodyElement.fadeIn("fast")
})
}
});
b.push({
open_url: zz.path_prefix + "/flickr/folders.json",
type: "folder",
name: "Flickr",
src: path_helpers.image_url("/images/folders/flickr_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/flickr_on.jpg"),
on_error: function () {
var e = this;
a.bodyElement.hide().load("/static/connect_messages/connect_to_flickr.html", function () {
a.bodyElement.find("#connect-button").click(function () {
a.open_login_window(e, zz.path_prefix + "/flickr/sessions/new")
});
a.bodyElement.fadeIn("fast")
})
}
});
b.push({
open_url: zz.path_prefix + "/picasa/folders.json",
type: "folder",
name: "Picasa Web",
src: path_helpers.image_url("/images/folders/picasa_web_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/picasa_web_on.jpg"),
on_error: function () {
var e = this;
a.bodyElement.hide().load("/static/connect_messages/connect_to_picasa_web.html", function () {
a.bodyElement.find("#connect-button").click(function () {
a.open_login_window(e, zz.path_prefix + "/picasa/sessions/new")
});
a.bodyElement.fadeIn("fast")
})
}
});
b.push({
open_url: zz.path_prefix + "/photobucket/folders",
type: "folder",
name: "Photobucket",
src: path_helpers.image_url("/images/folders/photobucket_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/photobucket_on.jpg"),
add_url: zz.path_prefix + "/photobucket/folders/import?album_path=/",
on_error: function () {
var e = this;
a.bodyElement.hide().load("/static/connect_messages/connect_to_photobucket.html", function () {
a.bodyElement.find("#connect-button").click(function () {
a.open_login_window(e, zz.path_prefix + "/photobucket/sessions/new")
});
a.bodyElement.fadeIn("fast")
})
}
});
b.push({
open_url: zz.path_prefix + "/zangzing/folders.json",
type: "folder",
name: "ZangZing",
src: path_helpers.image_url("/images/folders/zangzing_off.jpg"),
rolloverSrc: path_helpers.image_url("/images/folders/zangzing_on.jpg")
});
return b
},
updateCheckmarks: function () {
var a = this;
c.each(a.grid.cells(), function (b, d) {
c(d).data().zz_photo.setChecked(false)
});
c.each(a.tray_photos, function (b, d) {
var e = a.grid.cellForId(d.source_guid);
e && e.data().zz_photo.setChecked(true)
})
},
tray_widget: null,
tray_photos: [],
tray_element: null,
init_tray: function () {
var a = this;
a.tray_element = a.element.find(".added-pictures-tray");
a.tray_widget = a.tray_element.zz_thumbtray({
photos: [],
allowDelete: true,
allowSelect: false,
onDeletePhoto: function (b, d) {
a.remove_photo(d.id)
}
}).data().zz_thumbtray;
a.reload_tray()
},
remove_photo_by_guid: function (a) {
var b = _.detect(this.tray_photos, function (d) {
return d.source_guid == a
});
b && this.remove_photo(b.id)
},
remove_photo: function (a) {
var b = this;
c.ajax({
type: "POST",
dataType: "json",
data: {
_method: "delete"
},
url: zz.path_prefix + "/photos/" + a + ".json",
success: function () {
agent.callAgent("/albums/" + b.options.album_id + "/photos/" + a + "/cancel_upload");
b.reload_tray()
},
error: function (d) {
logger.debug(d)
}
})
},
reload_tray: function () {
var a = this;
c.ajax({
dataType: "json",
url: zz.path_prefix + "/albums/" + a.options.album_id + "/photos_json?" + (new Date).getTime(),
success: function (b) {
a.tray_photos = _.filter(b, function (d) {
return zz.current_user_id == d.user_id
});
a.tray_widget.setPhotos(a.map_photos(a.tray_photos));
a.updateCheckmarks()
}
})
},
add_photo_to_album: function (a, b) {
var d = this;
d.animate_to_tray(b, function () {
d.add_to_album(a)
});
b.data().zz_photo.setChecked(true)
},
add_folder_to_album: function (a, b) {
var d = this,
e, f = function () {
e.close()
};
d.animate_to_tray(b, function () {
var g = '<span class="processing-photos-dialog-content"><img src="{{src}}">Processing photos...</span>'.replace("{{src}}", path_helpers.image_url("/images/loading.gif"));
e = zz_dialog.show_dialog(g, {
width: 300,
height: 100,
modal: true,
autoOpen: true,
cancelButton: false
});
d.add_to_album(a, f, f)
});
c.each(d.grid.cells(), function (g, h) {
c(h).data().zz_photo.setChecked(true)
})
},
animate_to_tray: function (a, b) {
var d;
d = a.hasClass("add-all-button") ? a : a.find(".photo-image");
var e = d.offset().top,
f = d.offset().left,
g = this.tray_element.offset().top,
h = this.tray_next_thumb_offset_x();
d.clone().css({
position: "absolute",
left: f,
top: e,
border: "1px solid #ffffff"
}).appendTo("body").addClass("animate-photo-to-tray").animate({
width: "20px",
height: "20px",
top: g + "px",
left: h + "px"
}, 1E3, "easeInOutCubic", function () {
b();
c(this).remove()
})
},
add_to_album: function (a, b, d) {
var e = this;
a += a.indexOf("?") == -1 ? "?" : "&";
a += "album_id=" + e.options.album_id;
e.tray_widget.showLoadingIndicator();
e.callAgentOrServer({
url: a,
success: function (f) {
e.tray_photos = e.tray_photos.concat(f);
e.tray_widget.setPhotos(e.map_photos(e.tray_photos));
e.tray_widget.hideLoadingIndicator();
b && b()
},
error: function (f) {
if (!e.destroyed) {
e.tray_widget.hideLoadingIndicator();
alert("Sorry, there was a problem adding photos to your album. Please try again.");
d && d(f)
}
}
})
},
get_photos: function () {
return self.tray_photos
},
map_photos: function (a) {
c.isArray(a) || (a = [a]);
return a = c.map(a, function (b) {
var d = b.id;
b = b.thumb_url;
b = agent.checkAddCredentialsToUrl(b);
return {
id: d,
src: b
}
})
},
tray_next_thumb_offset_x: function () {
return this.tray_widget.nextThumbOffsetX()
}
})
})(jQuery);
(function (c, a) {
c.widget("ui.zz_photogrid", {
options: {
photos: [],
cellWidth: 200,
cellHeight: 200,
allowDelete: false,
onDelete: jQuery.noop,
allowEditCaption: false,
onChangeCaption: jQuery.noop,
allowReorder: false,
onChangeOrder: jQuery.noop,
onClickPhoto: jQuery.noop,
showThumbscroller: true,
hideNativeScroller: false,
singlePictureMode: false,
currentPhotoId: null,
onScrollToPhoto: jQuery.noop,
context: "album-grid",
lazyLoadThreshold: null,
showButtonBar: false,
onClickShare: jQuery.noop
},
animatedScrollActive: false,
_create: function () {
var b = this;
b.options.singlePictureMode ? b.element.css({
"overflow-y": "hidden",
"overflow-x": "scroll"
}) : b.element.css({
"overflow-y": "auto",
"overflow-x": "hidden"
});
b.width = parseInt(b.element.css("width"));
b.height = parseInt(b.element.css("height"));
var d = c('<div class="photogrid-cell"><div class="photogrid-droppable"></div></div>');
d.css({
width: b.options.cellWidth,
height: b.options.cellHeight
});
b.element.hide();
var e = Math.floor(b.options.cellHeight * 0.8),
f = Math.floor(b.options.cellWidth * 1),
g = -1 * Math.floor(f / 2),
h = Math.floor((b.options.cellHeight - e) / 2),
i = [];
if (b.options.lazyLoadThreshold != 0 && !b.options.lazyLoadThreshold && b.options.singlePictureMode) b.options.lazyLoadThreshold = b.options.cellWidth * 3;
c.each(b.options.photos, function (l, m) {
var o = d.clone();
i.push(o);
o.appendTo(b.element);
o.zz_photo({
photo: m,
photoId: m.id,
previewSrc: m.previewSrc,
src: m.src,
rolloverSrc: m.rolloverSrc,
maxWidth: Math.floor(b.options.cellWidth - 50),
maxHeight: Math.floor(b.options.cellHeight - 50),
allowDelete: b.options.allowDelete,
caption: m.caption,
aspectRatio: m.aspect_ratio,
onDelete: function () {
return b.options.onDelete(l, m)
},
allowEditCaption: b.options.allowEditCaption,
onChangeCaption: function (s) {
return b.options.onChangeCaption(l, m, s)
},
onClick: function (s) {
b.options.onClickPhoto(l, m, o, s)
},
scrollContainer: b.element,
lazyLoadThreshold: b.options.lazyLoadThreshold,
isUploading: !_.isUndefined(m.state) ? m.state !== "ready" : false,
isError: m.state === "error",
context: b.options.context,
type: _.isUndefined(m.type) ? "photo" : m.type,
showButtonBar: b.options.showButtonBar,
onClickShare: b.options.onClickShare
});
if (b.options.allowReorder) {
var t = o.find(".photogrid-droppable");
t.css({
top: h,
height: e,
width: f,
left: g
});
o.draggable({
start: function () {
o.data().zz_photo.dragStart()
},
stop: function () {
o.data().zz_photo.dragEnd()
},
drag: function () {},
revert: "invalid",
revertDuration: 400,
zIndex: 2700,
opacity: 0.5,
helper: function () {
return o.data().zz_photo.dragHelper()
},
scroll: true,
scrollSensitivity: b.options.cellHeight / 8,
scrollSpeed: b.options.cellHeight / 3
});
var w = Math.floor(b.options.cellWidth / 2);
t.droppable({
tolerance: "pointer",
over: function (s, v) {
if (v.draggable[0] != t.parent().prev()[0]) {
o.rowLeft().animateRelative(-1 * w, 0, 100);
o.rowRight().add(o).animateRelative(w, 0, 100)
}
},
out: function () {
b.resetLayout(100)
},
drop: function (s, v) {
var q = v.draggable,
x = q.clone().appendTo(q.parent());
x.fadeOut(400, function () {
x.remove()
});
var u = t.parent();
q.insertBefore(u);
q.css({
top: parseInt(u.css("top")),
left: parseInt(u.css("left")) - b.options.cellWidth
});
b.resetLayout(800, "easeInOutCubic");
var z = q.data().zz_photo.getPhotoId(),
y = null;
if (c(q).prev().length !== 0) y = c(q).prev().data().zz_photo.getPhotoId();
q = u.data().zz_photo.getPhotoId();
b.options.onChangeOrder(z, y, q)
}
})
}
});
b.resetLayout();
b.element.show();
this.element.children(".photogrid-cell").each(function (l, m) {
c(m).data().zz_photo.loadIfVisible()
});
var j = null;
c(window).resize(function () {
if (j) {
clearTimeout(j);
j = null
}
j = setTimeout(function () {
b.width = parseInt(b.element.css("width"));
b.height = parseInt(b.element.css("height"));
b.resetLayout();
b.element.children(".photogrid-cell").each(function (l, m) {
_.isUndefined(c(m).data().zz_photo) || c(m).data().zz_photo.loadIfVisible()
})
}, 100)
});
var k = null;
b.element.scroll(function () {
if (k) {
clearTimeout(k);
k = null
}
k = setTimeout(function () {
var l = {
offset: b.element.offset(),
height: b.element.height(),
width: b.element.width()
};
b.element.children(".photogrid-cell").each(function (m, o) {
c(o).data().zz_photo && c(o).data().zz_photo.loadIfVisible(l)
})
}, 200)
});
if (b.options.hideNativeScroller) b.thumbscrollerElement = b.options.singlePictureMode ? c('<div class="photogrid-hide-native-scroller-horizontal"></div>').appendTo(b.element.parent()) : c('<div class="photogrid-hide-native-scroller-vertical"></div>').appendTo(b.element.parent());
if (b.options.showThumbscroller) {
var n = false;
b.thumbscrollerElement = b.options.singlePictureMode ? c('<div class="photogrid-thumbscroller-horizontal"></div>').appendTo(b.element.parent()) : c('<div class="photogrid-thumbscroller-vertical"></div>').appendTo(b.element.parent());
var r = c.map(b.options.photos, function (l) {
return l.type == "blank" ? null : l
});
b.thumbscroller = b.thumbscrollerElement.zz_thumbtray({
photos: r,
srcAttribute: "previewSrc",
showSelection: false,
thumbnailSize: 20,
showSelectedIndexIndicator: true,
repaintOnResize: true,
onSelectPhoto: function (l, m) {
if (typeof m != "undefined") n || b.scrollToPhoto(m.id, 500, true)
}
}).data().zz_thumbtray;
b.element.scroll(function () {
if (!b.animateScrollActive) {
n = true;
var l;
l = b.options.singlePictureMode ? Math.floor(b.element.scrollLeft() / b.options.cellWidth) : Math.floor(b.element.scrollTop() / b.options.cellHeight * b.cellsPerRow());
b.thumbscroller.setSelectedIndex(l);
n = false
}
})
}
if (b.options.singlePictureMode) {
this.element.mousewheel(function (l) {
(typeof l.wheelDelta !== "undefined" ? l.wheelDelta : -1 * l.detail) < 0 ? b.nextPicture() : b.previousPicture();
return false
});
c(document.documentElement).keydown(function (l) {
if (l.keyCode === 40) b.nextPicture();
else if (l.keyCode === 39) b.nextPicture();
else if (l.keyCode === 34) b.nextPicture();
else if (l.keyCode === 38) b.previousPicture();
else if (l.keyCode === 37) b.previousPicture();
else l.keyCode === 33 && b.previousPicture()
});
c(this.element).keydown(function (l) {
l.preventDefault()
})
}
b.options.currentPhotoId && b.scrollToPhoto(b.options.currentPhotoId, 0, false)
},
hideThumbScroller: function () {
this.thumbscrollerElement && this.thumbscrollerElement.hide()
},
nextPrevActive: false,
nextPicture: function () {
var b = this;
if (!b.nextPrevActive) {
var d = b.indexOfPhoto(b.currentPhotoId());
d++;
if (!(d > b.options.photos.length - 1)) {
d = b.options.photos[d].id;
b.nextPrevActive = true;
b.scrollToPhoto(d, 500, true, function () {
b.nextPrevActive = false
})
}
}
},
previousPicture: function () {
var b = this;
if (!b.nextPrevActive) {
var d = b.indexOfPhoto(b.currentPhotoId());
d--;
if (!(d < 0)) {
d = b.options.photos[d].id;
b.nextPrevActive = true;
b.scrollToPhoto(d, 500, true, function () {
b.nextPrevActive = false
})
}
}
},
currentPhotoId: function () {
return this.options.currentPhotoId ? this.options.currentPhotoId : this.options.photos[0].id
},
indexOfPhoto: function (b) {
for (var d = 0; d < this.options.photos.length; d++) if (this.options.photos[d].id == b) return d;
return -1
},
scrollToPhoto: function (b, d, e, f) {
var g = this;
e = g.indexOfPhoto(b);
var h = function () {
g.options.currentPhotoId = b;
g.options.onScrollToPhoto(b);
typeof f !== "undefined" && f()
};
if (g.options.singlePictureMode) {
e *= g.options.cellWidth;
g.animateScrollActive = true;
g.element.animate({
scrollLeft: e
}, d, "easeOutCubic", function () {
g.animateScrollActive = false;
h()
})
} else {
e = Math.floor(e / g.cellsPerRow()) * g.options.cellHeight;
g.animateScrollActive = true;
g.element.animate({
scrollTop: e
}, d, "easeOutCubic", function () {
g.animateScrollActive = false;
h()
})
}
},
resetLayout: function (b, d) {
var e = this;
if (b === a) b = 0;
this.element.children(".photogrid-cell").each(function (f, g) {
if (c(g).data().zz_photo) {
var h = e.positionForIndex(f);
h = {
top: h.top,
left: h.left
};
b > 0 ? c(g).animate(h, b, d) : c(g).css(h)
}
})
},
cellForId: function (b) {
return this.cellAtIndex(this.indexOfPhoto(b))
},
cellAtIndex: function (b) {
b = this.element.children(":nth-child(" + (b + 1) + ")");
return b.length === 0 ? null : b
},
cells: function () {
return this.element.children(".photogrid-cell")
},
cellsPerRow: function () {
return this.options.singlePictureMode ? this.options.photos.length : Math.floor(this.width / this.options.cellWidth)
},
positionForIndex: function (b) {
if (this.options.singlePictureMode) return {
top: 0,
left: b * this.options.cellWidth
};
else {
var d = this.cellsPerRow(),
e = Math.floor(b / d),
f = Math.floor((this.width - d * this.options.cellWidth) / 2);
f -= 10;
return {
top: e * this.options.cellHeight,
left: f + b % d * this.options.cellWidth
}
}
},
destroy: function () {
this.thumbscrollerElement && this.thumbscrollerElement.remove();
c.Widget.prototype.destroy.apply(this, arguments)
}
})
})(jQuery);
(function (c) {
c.widget("ui.zz_picon", {
options: {
caption: "",
coverUrl: "",
onClick: function () {},
onLike: function () {},
onShare: function () {},
onDelete: function () {},
allowDelete: false,
stackAngles: [
[-6, -3],
[-3, 3],
[6, 3]
],
maxCoverWidth: 180,
maxCoverHeight: 150
},
_create: function () {
var a = this;
a.template = c('<div class="picon"><div class="caption"></div><div class="stacked-image"></div><div class="stacked-image"></div><div class="stacked-image"><img class="cover-photo" src="' + path_helpers.image_url("/images/photo_placeholder.png") + '"><div class="button-bar"><div class="buttons"><div class="share-button"></div><div class="like-button"></div><div class="delete-button"></div></div></div></div></div>');
a.captionHeight = 80;
this.element.append(a.template);
var b = Math.floor(Math.random() * a.options.stackAngles.length);
a.template.find(".stacked-image:eq(0)").rotate(a.options.stackAngles[b][0]);
a.template.find(".stacked-image:eq(1)").rotate(a.options.stackAngles[b][1]);
a.template.find(".caption").text(a.options.caption);
a.template.find(".cover-photo").click(function () {
a.options.onClick()
});
a.template.find(".share-button").click(function () {
a.options.onShare()
});
a.template.find(".like-button").click(function () {
a.options.onLike()
});
a.options.allowDelete ? a.template.find(".delete-button").click(function () {
a.options.onDelete()
}) : a.template.find(".delete-button").hide();
var d = function () {
a.topOfStack = a.template.find(".stacked-image:last");
var e = a.topOfStack.height();
a.topOfStack.mouseover(function () {
a.topOfStack.css({
height: e + 30
});
a.topOfStack.find(".button-bar").show()
});
a.topOfStack.mouseout(function () {
a.topOfStack.css({
height: e
});
a.topOfStack.find(".button-bar").hide()
})
};
a._resize(a.options.maxCoverWidth, a.options.maxCoverHeight);
a.options.coverUrl ? image_utils.pre_load_image(a.options.coverUrl, function (e) {
var f = image_utils.scale(e, {
width: a.options.maxCoverWidth,
height: a.options.maxCoverHeight
});
a._resize(f.width, f.height);
a.template.find(".cover-photo").attr("src", e.src);
d()
}, function () {
d()
}) : d()
},
_resize: function (a, b) {
this.template.find(".cover-photo").css({
height: b,
width: a
});
this.template.find(".stacked-image").css({
height: b + 10,
width: a + 10
});
this.template.find(".stacked-image").center_xy({
top: 40,
left: 0,
width: this.element.width(),
height: this.element.height() - (this.captionHeight + 40)
})
},
destroy: function () {
c.Widget.prototype.destroy.apply(this, arguments)
}
})
})(jQuery);
var profile_pictures = {
init_profile_pictures: function () {
_.each($(".profile-picture"), function (c) {
var a = $(c),
b = a.find("img"),
d = b.attr("data-src");
image_utils.pre_load_image(d, function (e) {
e = image_utils.scale_center_and_crop(e, {
width: a.width(),
height: a.height()
});
b.css(e);
b.attr("src", d)
})
})
}
};
(function (c) {
c.widget("ui.zz_thumbtray", {
options: {
photos: [],
srcAttribute: "src",
previewSize: 120,
selectionSize: 140,
allowDelete: false,
showSelection: false,
selectedIndex: -1,
thumbnailSize: 20,
showSelectedIndexIndicator: false,
repaintOnResize: false,
onDeletePhoto: function () {},
onSelectPhoto: function () {},
onPreviewPhoto: function () {}
},
currentIndex: -1,
selectedIndex: -1,
traySize: null,
orientation: null,
ORIENTATION_X: "x",
ORIENTATION_Y: "y",
PLACEHOLDER_IMAGE: "/images/photo_placeholder.png",
_create: function () {
var a = this,
b = "";
b += '<div class="thumbtray-wrapper">';
b += '<div class="thumbtray-thumbnails"></div>';
b += '<div class="thumbtray-selection">';
b += '<img src="' + path_helpers.image_url("/images/photo_placeholder.png") + '">';
b += "</div>";
b += '<div class="thumbtray-preview">';
b += '<img src="' + path_helpers.image_url("/images/photo_placeholder.png") + '">';
b += '<div class="thumbtray-delete-button"></div>';
b += "</div>";
b += '<img class="thumbtray-loading-indicator" src="' + path_helpers.image_url("/images/loading.gif") + '"/>';
b += '<div class="thumbtray-mask"></div>';
b += '<div class="thumbtray-current-index-indicator"></div>';
b += '<div class="thumbtray-scrim"></div>';
b += "</div>";
this.element.html(b);
this.wrapperElement = this.element.find(".thumbtray-wrapper");
this.scrimElement = this.element.find(".thumbtray-scrim");
this.maskElement = this.element.find(".thumbtray-mask");
this.previewElement = this.element.find(".thumbtray-preview");
this.selectionElement = this.element.find(".thumbtray-selection");
this.thumbnailsElement = this.element.find(".thumbtray-thumbnails");
this.loadingIndicator = this.element.find(".thumbtray-loading-indicator");
this.selectedIndexIndicator = this.element.find(".thumbtray-current-index-indicator");
var d = function () {
var h = a.element.width(),
i = a.element.height();
a.orientation = h > i ? a.ORIENTATION_X : a.ORIENTATION_Y;
a.wrapperElement.css({
width: h,
height: i
});
a.scrimElement.css({
width: h,
height: i
});
a.maskElement.css({
width: h,
height: i
});
a.thumbnailsElement.css({
width: h,
height: i
});
if (a.orientation === a.ORIENTATION_X) {
a.previewElement.addClass("x");
a.selectionElement.addClass("x");
a.selectionElement.find("img").css({
height: a.options.selectionSize
});
a.previewElement.find("img").css({
height: a.options.previewSize
});
a.traySize = h
} else {
a.previewElement.addClass("y");
a.selectionElement.addClass("y");
a.selectionElement.find("img").css({
width: a.options.selectionSize
});
a.previewElement.find("img").css({
width: a.options.previewSize
});
a.traySize = i
}
};
d();
a.options.repaintOnResize && c(window).resize(function () {
d();
a._repaintThumbnails()
});
this._repaintThumbnails();
this._setSelectedIndex(this.options.selectedIndex);
this.options.allowDelete && a.previewElement.find(".thumbtray-delete-button").show().click(function () {
a.previewElement.find(".thumbtray-delete-button").hide();
a.removePhoto(a._getCurrentIndex());
a.previewElement.hide("scale", {}, 300, function () {
a.previewElement.find(".thumbtray-delete-button").show()
})
});
var e = false,
f = function () {
e = true;
a.previewElement.fadeIn("fast")
},
g = function () {
e = false;
setTimeout(function () {
if (!e) {
a.previewElement.fadeOut("fast");
a.options.showSelection && a.selectionElement.animate({
opacity: 1
}, 100)
}
}, 100)
};
a.scrimElement.mousemove(function (h) {
a.orientation === a.ORIENTATION_X ? a._getIndexForPosition(h.pageX - a.element.offset().left) : a._getIndexForPosition(h.pageY - a.element.offset().top);
if (null !== -1) a.orientation === a.ORIENTATION_X ? a.showPreviewForPosition(h.pageX - a.element.offset().left) : a.showPreviewForPosition(h.pageY - a.element.offset().top);
else {
g();
a._setCurrentIndex(-1)
}
});
a.scrimElement.mouseover(function () {
f()
});
a.scrimElement.mouseout(function () {
g()
});
a.scrimElement.mousedown(function () {
a._setSelectedIndex(a._getCurrentIndex());
if (a.options.showSelection === true) {
a.previewElement.hide();
a.selectionElement.css({
opacity: 1
})
}
});
a.previewElement.mouseover(function () {
f()
});
a.previewElement.mouseout(function () {
g()
});
a.previewElement.click(function () {
a._setSelectedIndex(a._getCurrentIndex());
a.options.showSelection === true && a.previewElement.hide()
})
},
showPreviewForPosition: function (a) {
a = this._getIndexForPosition(a);
this._setCurrentIndex(a);
this.options.onPreviewPhoto(a, this.options.photos[a]);
this.previewElement.show()
},
_getMaxVisibleThumbnails: function () {
return this.traySize / this.options.thumbnailSize
},
_getThumbnailActiveSize: function () {
var a = this.options.photos.length;
return a * this.options.thumbnailSize < this.traySize ? this.options.thumbnailSize : this.traySize / a
},
_getThumbnailSize: function () {
return this.options.thumbnailSize
},
_setCurrentIndex: function (a) {
if (a !== this.currentIndex) {
this.currentIndex = a;
if (a !== -1) {
this.previewElement.find("img").attr("src", this.PLACEHOLDER_IMAGE);
this.previewElement.find("img").attr("src", this.options.photos[a][this.options.srcAttribute]);
this.orientation === this.ORIENTATION_X ? this.previewElement.css("left", Math.round(this._getPositionForIndex(a) - this.previewElement.width() / 2)) : this.previewElement.css("top", Math.round(this._getPositionForIndex(a) - this.previewElement.height() / 2));
this.options.showSelection && this.selectionElement.css({
opacity: 0.5
})
}
}
},
_getCurrentIndex: function () {
return this.currentIndex
},
_setSelectedIndex: function (a) {
this.selectedItem = a;
if (a !== -1) {
if (this.options.showSelection === true) {
this.selectionElement.find("img").attr("src", this.PLACEHOLDER_IMAGE);
this.selectionElement.find("img").attr("src", this.options.photos[a][this.options.srcAttribute]);
this.selectionElement.show();
this.selectionElement.css({
opacity: 1
});
this.orientation === this.ORIENTATION_X ? this.selectionElement.css("left", this._getPositionForIndex(a) - this.selectionElement.width() / 2) : this.selectionElement.css("top", this._getPositionForIndex(a) - this.selectionElement.height() / 2)
}
if (this.options.showSelectedIndexIndicator) {
this.orientation === this.ORIENTATION_X ? this.selectedIndexIndicator.css("left", this._getPositionForIndex(a) - this.selectedIndexIndicator.width()) : this.selectedIndexIndicator.css("top", this._getPositionForIndex(a) - this.selectedIndexIndicator.height());
this.selectedIndexIndicator.show()
}
}
this.options.onSelectPhoto(a, this.options.photos[a])
},
_getSelectedIndex: function () {
return this.selectedItem
},
_getIndexForPosition: function (a) {
var b = this.options.photos.length;
a = Math.floor(a / this._getThumbnailActiveSize());
if (!(a >= b)) return a
},
_getPositionForIndex: function (a) {
return a * this._getThumbnailActiveSize() + this._getThumbnailActiveSize() / 2
},
_repaintThumbnails: function () {
var a = "",
b = this.options.photos.slice();
if (b.length > this._getMaxVisibleThumbnails()) for (var d = b.length - this._getMaxVisibleThumbnails(), e = (b.length - 2) / d; d > 0; d--) b.splice(Math.round(d * e), 1);
for (d = 0; d < b.length; d++) {
e = b[d];
a += '<img style="height:' + this._getThumbnailSize() + "px; width:" + this._getThumbnailSize() + 'px" src="' + e[this.options.srcAttribute] + '">'
}
this.thumbnailsElement.html(a);
this.orientation === this.ORIENTATION_X ? this.scrimElement.css("width", b.length * this._getThumbnailSize()) : this.scrimElement.css("height", b.length * this._getThumbnailSize())
},
destroy: function () {
this.element.html("");
c.Widget.prototype.destroy.apply(this, arguments)
},
removePhoto: function (a) {
this.options.onDeletePhoto(a, this.options.photos[a]);
this.options.photos.splice(a, 1);
this._repaintThumbnails()
},
setPhotos: function (a) {
this.options.photos = a.slice();
this._setSelectedIndex(-1);
this._repaintThumbnails()
},
addPhotos: function (a) {
this.options.photos = this.options.photos.concat(a);
this._repaintThumbnails()
},
nextThumbOffsetX: function () {
return this.options.photos.length === 0 ? this.thumbnailsElement.offset().left : this.options.photos.length >= this._getMaxVisibleThumbnails() ? this.thumbnailsElement.offset().left + this.thumbnailsElement.width() - 20 : this.thumbnailsElement.offset().left + this.options.photos.length * 20
},
setSelectedIndex: function (a) {
this._setSelectedIndex(a)
},
showLoadingIndicator: function () {
this.loadingIndicator.css("left", this.nextThumbOffsetX() - this.wrapperElement.offset().left);
this.loadingIndicator.show()
},
hideLoadingIndicator: function () {
this.loadingIndicator.hide()
}
})
})(jQuery);
var zz = {
view: "undefined",
DRAWER_CLOSED: 0,
DRAWER_OPEN: 1,
DRAWER_PARTIAL: 2,
drawer_state: 0,
screen_gap: 150,
path_prefix: "/service",
open_drawer: function (c) {
zz.screen_height = $(window).height();
zz.drawer_height = zz.screen_height - zz.screen_gap;
$("#article").empty();
$("div#drawer").show().animate({
height: zz.drawer_height + "px",
top: "52px"
}, c);
$("div#drawer-content").animate({
height: zz.drawer_height - 14 + "px"
}, c);
zz.wizard.resize_scroll_body();
zz.drawer_state = zz.DRAWER_OPEN
},
resize_drawer: function (c, a) {
zz.screen_height = $(window).height();
zz.drawer_height = zz.screen_height - zz.screen_gap;
if (typeof a != "undefined" && a < zz.drawer_height) zz.drawer_height = a;
$("div#drawer").animate({
height: zz.drawer_height + "px",
top: "52px"
}, c);
$("div#drawer-content").animate({
height: zz.drawer_height - 0 + "px"
}, c)
},
close_drawer_partially: function (c, a) {
zz.resize_drawer(c, a);
$("#article").animate({
opacity: 1
}, c * 1.1);
zz.drawer_state = zz.DRAWER_PARTIAL
},
close_drawer: function (c) {
$("#indicator").fadeOut("fast");
$("div#drawer").animate({
height: 0,
top: "10px"
}, c);
$("div#drawer-content").animate({
height: 0,
top: "10px"
}, c);
$("#article").animate({
opacity: 1
}, c * 1.1);
zz.drawer_state = zz.DRAWER_CLOSED
},
easy_drawer: function (c, a, b, d) {
zz.open_drawer(c, a);
$("#tab-content").load(b, function () {
$("div#drawer-content div#scroll-body").css({
height: zz.drawer_height - 52 + "px"
});
d()
})
}
};
zz.drawers = {
group_album: {
first: "add",
last: "share",
show_next_button: true,
numbers: 1,
percent: 0,
style: "create",
time: 600,
init: function () {
zz.album_type = "group"
},
on_close: function () {
ZZAt.track("album.done.click");
$.ajax({
url: zz.path_prefix + "/albums/" + zz.album_id + "/close_batch",
complete: function (c, a) {
logger.debug("Batch closed because drawer was closed. Call to close_batch returned with status= " + a);
window.location = zz.path_prefix + "/albums/" + zz.album_id + "/photos"
}
})
},
steps: {
add: {
next: "name",
title: "Add Photos",
type: "full",
url: zz.path_prefix + "/albums/$$/add_photos",
url_type: "album",
init: function (c, a) {
pages.album_add_photos_tab.init(c, a, zz.drawers.group_album.style)
},
bounce: function (c, a) {
pages.album_add_photos_tab.bounce(c, a)
}
},
name: {
id: "name",
next: "edit",
title: "Name",
type: "full",
init: function (c, a) {
pages.album_name_tab.init(c, a)
},
bounce: function (c, a) {
pages.album_name_tab.bounce(c, a)
}
},
edit: {
next: "privacy",
title: "Edit",
type: "partial",
init: function (c, a) {
pages.edit_album_tab.init(c, a)
},
bounce: function (c, a) {
pages.edit_album_tab.bounce(c, a)
}
},
privacy: {
next: "contributors",
title: "Privacy",
type: "full",
init: function (c, a) {
pages.album_privacy_tab.init(c, a)
},
bounce: function (c, a) {
pages.album_privacy_tab.bounce(c, a)
}
},
contributors: {
next: "share",
title: "Contributors",
type: "full",
init: function (c, a) {
pages.contributors.init(c, a)
},
bounce: function (c, a) {
pages.contributors.bounce(c, a)
}
},
share: {
next: 0,
title: "Share",
type: "full",
init: function (c, a) {
pages.share.init(c, a)
},
bounce: function (c, a) {
pages.share.bounce(c, a)
}
}
}
},
settings: {
first: "profile",
last: "linked_accts",
show_next_button: false,
numbers: 0,
percent: 0,
style: "edit",
time: 600,
init: function () {},
on_close: function () {},
steps: {
profile: {
next: "account",
title: "Profile",
type: "full",
init: function (c, a) {
pages.acct_profile.init(c, a)
},
bounce: function (c, a) {
pages.acct_profile.bounce(c, a)
}
},
account: {
next: "notifications",
title: "Account",
type: "full",
init: function (c, a) {
pages.account_setings_account_tab.init(c, a)
},
bounce: function (c, a) {
pages.account_setings_account_tab.bounce(c, a)
}
},
notifications: {
next: "linked-accts",
title: "Notifications",
type: "full",
init: function (c, a) {
pages.account_setings_notifications_tab.init(c, a)
},
bounce: function (c, a) {
pages.account_setings_notifications_tab.bounce(c, a)
}
},
linked_accts: {
next: 0,
title: "Linked Accounts",
type: "full",
init: function (c, a) {
pages.linked_accounts.init(c, a)
},
bounce: function (c, a) {
pages.linked_accounts.bounce(c, a)
}
}
}
}
};
zz.init = {
disable_buttons: function () {
$("#header #back-button").addClass("disabled");
$("#header #view-buttons").children().addClass("disabled");
$("#header #account-badge").addClass("disabled");
$("#footer #play-button").addClass("disabled");
$("#footer #next-button").addClass("disabled");
$("#footer #prev-button").addClass("disabled");
$("#footer #new-album-button").addClass("disabled");
$("#footer #add-photos-button").addClass("disabled");
$("#footer #share-button").addClass("disabled");
$("#footer #edit-album-button").addClass("disabled");
$("#footer #buy-button").addClass("disabled");
$("#footer #like-button").addClass("disabled")
},
enable_buttons: function () {
$("#header #back-button").removeClass("disabled");
$("#header #view-buttons").children().removeClass("disabled");
$("#header #account-badge").removeClass("disabled");
$("#footer #play-button").removeClass("disabled");
$("#footer #next-button").removeClass("disabled");
$("#footer #prev-button").removeClass("disabled");
$("#footer #new-album-button").removeClass("disabled");
$("#footer #add-photos-button").removeClass("disabled");
$("#footer #share-button").removeClass("disabled");
$("#footer #edit-album-button").removeClass("disabled");
$("#footer #buy-button").removeClass("disabled");
$("#footer #like-button").removeClass("disabled")
},
template: function () {
$(document).ajaxSend(function (c, a, b) {
b.data = b.data || "";
b.data += (b.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(zz.rails_authenticity_token)
});
$('<span class="tooltip">&nbsp;</span>').appendTo("body");
$(".has-tooltip").each(function () {
$(this).tooltip({
tip: ".tooltip",
effect: "fade",
fadeOutSpeed: 100,
predelay: 100,
offset: [$(this).height() * 0.5, $(this).width() * 0.75]
})
});
$("#join-banner #close-button").click(function () {
$("#join-banner").fadeOut(200, function () {
$("#page-wrapper").animate({
top: 0
}, 200);
$("body").removeClass("show-join-banner");
jQuery.cookie("hide_join_banner", "true")
})
});
$("#join-banner #join-button").click(function () {
document.location.href = "/join"
});
$("#join-banner #signin-button").click(function () {
document.location.href = "/signin"
});
$("#header #home-button").click(function () {
document.location.href = zz.path_prefix + "/";
ZZAt.track("button.home.click")
});
if (zz.rails_controller_name == "photos") $("#header #view-buttons #grid-view-button").addClass("selected");
else if (zz.rails_controller_name == "people") $("#header #view-buttons #people-view-button").addClass("selected");
else zz.rails_controller_name == "activities" && $("#header #view-buttons #activities-view-button").addClass("selected");
$("#header #view-buttons #grid-view-button").click(function () {
if (!($(this).hasClass("disabled") || $(this).hasClass("selected"))) {
ZZAt.track("button.gridview.click");
$("#header #view-buttons").children().removeClass("selected");
$("#header #view-buttons #grid-view-button").addClass("selected");
$("#article").fadeOut(200);
document.location.href = zz.album_base_url + "/photos"
}
});
$("#header #view-buttons #picture-view-button").click(function () {
if (!($(this).hasClass("disabled") || $(this).hasClass("selected"))) {
ZZAt.track("button.pictureview.click");
$("#header #view-buttons").children().removeClass("selected");
$("#header #view-buttons #picture-view-button").addClass("selected");
$("#article").fadeOut(200);
document.location.href = zz.album_base_url + "/photos/#!"
}
});
$("#header #view-buttons #people-view-button").click(function () {
if (!($(this).hasClass("disabled") || $(this).hasClass("selected"))) {
ZZAt.track("button.peopleview.click");
$("#header #view-buttons").children().removeClass("selected");
$("#header #view-buttons #people-view-button").addClass("selected");
$("#article").fadeOut(200);
document.location.href = zz.album_base_url + "/people"
}
});
$("#header #view-buttons #activities-view-button").click(function () {
if (!($(this).hasClass("disabled") || $(this).hasClass("selected"))) {
ZZAt.track("button.activitiesview.click");
$("#header #view-buttons").children().removeClass("selected");
$("#header #view-buttons #activities-view-button").addClass("selected");
$("#article").fadeOut(200);
document.location.href = zz.album_base_url + "/activities"
}
});
$("#header #help-button").click(function (c) {
ZZAt.track("button.help.click");
Zenbox.show(c);
$("#zenbox_body").css({
height: jQuery(window).height() - 100
})
});
$("#header #sign-in-button").click(function () {
ZZAt.track("button.signin.click");
document.location.href = "/signin"
});
$("#footer #play-button").click(function () {
if (!($(this).hasClass("disabled") || $(this).hasClass("selected"))) {
ZZAt.track("button.play.click");
$("<div></div>").css({
position: "absolute",
top: 0,
left: 0,
height: "100%",
width: "100%",
"z-index": 3E3,
"background-color": "#000000",
opacity: 0
}).appendTo("body").animate({
opacity: 1
}, 500, function () {
document.location.href = zz.album_base_url + "/movie"
})
}
});
$("#footer #new-album-button").click(function () {
if (!($(this).hasClass("disabled") || $(this).hasClass("selected"))) {
ZZAt.track("button.createalbum.click");
zz.init.disable_buttons();
$("#footer #new-album-button").removeClass("disabled").addClass("selected");
zz.toolbars.init_new_album();
zz.wizard.create_group_album()
}
});
$("#footer #add-photos-button").click(function () {
if (!($(this).hasClass("disabled") || $(this).hasClass("selected"))) {
zz.init.disable_buttons();
$("#footer #add-photos-button").removeClass("disabled").addClass("selected");
photochooser.open_in_dialog(zz.album_id, function () {
window.location.reload(false)
})
}
});
$("#footer #share-button").click(function () {
if (!($(this).hasClass("disabled") || $(this).hasClass("selected"))) {
ZZAt.track("button.share.click");
zz.init.disable_buttons();
$("#footer #share-button").removeClass("disabled").addClass("selected");
if (document.location.href.indexOf("/photos/#!") !== -1 || document.location.href.indexOf("/photos#!") !== -1) {
$("#footer #share-button").removeClass("selected");
zz.init.enable_buttons();
alert("This feature is still under construction.")
} else pages.share.share_in_dialog("album", zz.album_id, function () {
zz.init.enable_buttons();
$("#footer #share-button").removeClass("selected")
})
}
});
$("#footer #edit-album-button").click(function () {
if (!($(this).hasClass("disabled") || $(this).hasClass("selected"))) {
ZZAt.track("button.editalbum.click");
zz.init.disable_buttons();
$("#footer #edit-album-button").removeClass("disabled").addClass("selected");
zz.wizard.open_edit_album_wizard("add")
}
});
$("#footer #buy-button").click(function () {
alert("This feature is still under construction.")
});
zz.init.acct_badge();
zz.init.like_menu();
setTimeout(function () {
zz.init.preload_rollover_images()
}, 500);
profile_pictures.init_profile_pictures()
},
show_welcome_dialog: function () {
$('<iframe frameborder="0" height="450" width="780" border="0" src="/static/welcome_dialog/index.html"></iframe>').zz_dialog({
height: 420,
width: 750,
modal: true,
autoOpen: true
})
},
loaded: function () {
$("#drawer-content").ajaxError(function (c, a) {
zz.wizard.display_errors(a, 50);
zz.wizard.display_flashes(a, 50)
});
$("#drawer-content").ajaxSuccess(function (c, a) {
zz.wizard.display_flashes(a, 50)
})
},
resized: function () {
zz.drawer_state == zz.DRAWER_OPEN && zz.resize_drawer(50)
},
init_back_button: function (c, a) {
$("#header #back-button span").text(c);
$("#header #back-button").click(function () {
if (!($(this).hasClass("disabled") || $(this).hasClass("selected"))) {
$("#article").animate({
left: $("#article").width()
}, 500, "easeOutQuart");
document.location.href = a
}
})
},
filterPhotosForUser: function (c) {
return $.map(c, function (a) {
if (a.state !== "ready") if (_.isUndefined(zz.current_user_id) || a.user_id != zz.current_user_id) return null;
return a
})
},
album: function () {
var c = "grid";
if (document.location.href.indexOf("#!") !== -1) c = "picture";
c === "grid" ? this.init_back_button("All Albums", zz.back_to_home_page_url) : this.init_back_button(zz.album_name, zz.album_base_url + "/photos");
$.ajax({
dataType: "json",
url: zz.path_prefix + "/albums/" + zz.album_id + "/photos_json?" + zz.album_lastmod,
success: function (a) {
ZZAt.track("album.view", {
id: zz.album_id
});
a = zz.init.filterPhotosForUser(a);
a.length == 0 && $("#footer #play-button").addClass("disabled");
if (c === "grid") {
var b = $('<div class="photogrid"></div>');
$("#article").html(b);
$("#article").css("overflow", "hidden");
for (var d = 0; d < a.length; d++) {
var e = a[d];
e.previewSrc = agent.checkAddCredentialsToUrl(e.stamp_url);
e.src = agent.checkAddCredentialsToUrl(e.thumb_url)
}
var f = b.zz_photogrid({
photos: a,
allowDelete: false,
allowEditCaption: false,
allowReorder: false,
cellWidth: 230,
cellHeight: 230,
showThumbscroller: false,
onClickPhoto: function (i, j) {
f.hideThumbScroller();
b.css({
overflow: "hidden"
});
$("#article").css({
overflow: "hidden"
}).animate({
left: -1 * $("#article").width()
}, 500, "easeOutQuart");
document.location.href = zz.album_base_url + "/photos/#!" + j.id
},
currentPhotoId: $.param.fragment(),
showButtonBar: true,
onClickShare: function () {
alert("This feature is still under construction.")
}
}).data().zz_photogrid
} else {
$("#view-buttons").hide();
var g = function () {
var i = $('<div class="photogrid"></div>');
$("#article").html(i);
$("#article").css("overflow", "hidden");
for (var j = $(window).width() > 1200 && $(window).height() > 1E3, k = 0; k < a.length; k++) {
var n = a[k];
n.previewSrc = agent.checkAddCredentialsToUrl(n.stamp_url);
n.src = j ? agent.checkAddCredentialsToUrl(n.full_screen_url) : agent.checkAddCredentialsToUrl(n.screen_url)
}
j = null;
k = jQuery.param.fragment();
if (k !== "") j = k.slice(1);
var r = i.zz_photogrid({
photos: a,
allowDelete: false,
allowEditCaption: false,
allowReorder: false,
cellWidth: i.width(),
cellHeight: i.height() - 20,
onClickPhoto: function () {
r.nextPicture();
ZZAt.track("button.next.click")
},
singlePictureMode: true,
currentPhotoId: j,
onScrollToPhoto: function (l) {
window.location.hash = "#!" + l;
ZZAt.track("photo.view", {
id: l
})
}
}).data().zz_photogrid;
$("#footer #next-button").unbind("click");
$("#footer #next-button").show().click(function () {
r.nextPicture();
ZZAt.track("button.next.click")
});
$("#footer #prev-button").unbind("click");
$("#footer #prev-button").show().click(function () {
r.previousPicture();
ZZAt.track("button.previous.click")
})
};
g();
var h = null;
$(window).resize(function () {
if (h) {
clearTimeout(h);
h = null
}
h = setTimeout(function () {
g()
}, 100)
})
}
if (typeof like != "undefined") {
d = {};
for (key in a) {
id = a[key].id;
d[id] = "photo"
}
like.add_id_array(d)
}
}
})
},
preload_rollover_images: function () {
for (var c = 1; c <= 6; c++) {
var a = "/images/wiz-num-" + c + "-on.png";
image_utils.pre_load_image(path_helpers.image_url(a));
a = "/images/wiz-num-" + c + ".png";
image_utils.pre_load_image(path_helpers.image_url(a))
}
},
album_people_view: function () {
zz.init.album_timeline_or_people_view("people")
},
album_timeline_view: function () {
zz.init.album_timeline_or_people_view("timeline")
},
album_timeline_or_people_view: function (c) {
this.init_back_button("All Albums", zz.back_to_home_page_url);
$.ajax({
dataType: "json",
url: zz.path_prefix + "/albums/" + zz.album_id + "/photos_json?" + zz.album_lastmod,
success: function (a) {
a = zz.init.filterPhotosForUser(a);
a.length == 0 && $("#footer #play-button").addClass("disabled");
for (var b = 0; b < a.length; b++) {
var d = a[b];
d.previewSrc = agent.checkAddCredentialsToUrl(d.stamp_url);
d.src = agent.checkAddCredentialsToUrl(d.thumb_url)
}
$(".timeline-grid").each(function (e, f) {
$(f).empty();
var g = null;
if (c === "timeline") {
var h = parseInt($(f).attr("data-upload-batch-id"));
g = $(a).filter(function (n) {
return a[n].upload_batch_id === h
});
var i = $('.viewlist .more-less-btn[data-upload-batch-id="' + h.toString() + '"]')
} else {
var j = parseInt($(f).attr("data-user-id"));
g = $(a).filter(function (n) {
return a[n].user_id === j
});
i = $('.viewlist .more-less-btn[data-user-id="' + j.toString() + '"]')
}
$(f).zz_photogrid({
photos: g,
allowDelete: false,
allowEditCaption: false,
allowReorder: false,
cellWidth: 230,
cellHeight: 230,
onClickPhoto: function (n, r) {
$("#article").css({
overflow: "hidden"
}).animate({
left: -1 * $("#article").width()
}, 500, "easeOutQuart");
document.location.href = zz.album_base_url + "/photos/#!" + r.id
},
showThumbscroller: false,
showButtonBar: true,
onClickShare: function (n) {
pages.share.share_in_dialog("photo", n)
}
}).data();
$(f).css({
"overflow-x": "hidden",
"overflow-y": "hidden"
});
var k = false;
i.click(function () {
if (k) {
i.find("span").html("Show more photos");
i.removeClass("open");
$(f).animate({
height: 230
}, 500, "swing", function () {});
k = false
} else {
i.find("span").html("Show fewer photos");
i.addClass("open");
$(f).animate({
height: $(f).children().last().position().top + 180
}, 500, "swing", function () {
$(f).trigger("scroll")
});
k = true
}
})
})
}
})
},
acct_badge: function () {
zz.toolbars.init_acct_badge_menu();
$("#account-badge").click(function () {
$(this).hasClass("disabled") || $(this).hasClass("selected") || zz.toolbars.show_acct_badge_menu()
})
},
like_menu: function () {
var c = $(zz.toolbars.build_like_menu()).zzlike_menu();
like.init();
$("#footer #like-button").click(function (a) {
if (!($(this).hasClass("disabled") || $(this).hasClass("selected"))) {
ZZAt.track("button.like.click");
$(c).zzlike_menu("open", this);
a.stopPropagation()
}
})
}
};
zz.toolbars = {
init_new_album: function () {
$("#user-info").css("display", "none");
$("#album-info h2").text("New Album");
$("#album-info h3").text("by " + zz.current_user_name);
$("#header .album-cover").attr("src", path_helpers.image_url("/images/album-no-cover.png"));
$("#header .album-cover").css({
width: "60px"
});
$("#album-info").css("display", "inline-block");
zz.wizard.set_wizard_style("create");
$("div#cancel-drawer-btn").unbind("click").click(function () {
if (confirm("Are you sure you want to cancel creating this album?")) {
albums.deleteAlbum(zz.album_id);
$("#drawer .body").fadeOut("fast", function () {
window.location.reload()
});
zz.close_drawer(400);
ZZAt.track("album.cancel.click")
}
})
},
init_acct_badge_menu: function () {
$("ul.dropdown").hover(function () {}, function () {
$(this).slideUp("fast")
});
$("ul.dropdown li a").click(function () {
$(this).parent().parent().slideUp("fast")
});
$("#acct-settings-btn").click(function () {
zz.init.disable_buttons();
$("#header #account-badge").removeClass("disabled").addClass("selected");
document.location.href = path_helpers.rails_route("edit_user", zz.current_user_name)
});
$("#acct-signout-btn").click(function () {
window.location = zz.path_prefix + "/signout"
})
},
show_acct_badge_menu: function () {
$("#acct-dropdown").is(":visible") ? $("#acct-dropdown").slideUp("fast") : $("#acct-dropdown").slideDown("fast")
},
build_like_menu: function () {
var c = "",
a = "",
b = "",
d = "";
if (typeof zz.album_id != "undefined") b = $('<li class="zzlike" data-zzid="' + zz.album_id + '" data-zztype="album"></li>');
if (typeof zz.displayed_user_id != "undefined" && zz.displayed_user_id != zz.current_user_id) a = $('<li class="zzlike" data-zzid="' + zz.displayed_user_id + '" data-zztype="user"></li>');
if (location.hash && location.hash.length > 2) {
d = $('<li id="like-menu-photo" class="zzlike" data-zzid="' + location.hash.substr(2) + '" data-zztype="photo"></li>');
$(window).bind("hashchange", function () {
var e = location.hash.substr(2);
$("#like-menu-photo").attr("data-zzid", e);
like.add_id(e, "photo")
})
}
c = $('<ul id="like-menu"></ul>');
c.append(b);
c.append(a);
c.append(d);
return c
}
};
jQuery.validator.addMethod("regex", function (c, a, b) {
b = RegExp(b);
return this.optional(a) || b.test(c)
}, "Please check your input.");
zz.validate = {
sign_in: {
element: "#new_user_session",
errorContainer: "div#sign-in p.error-notice",
rules: {
"user_session[email]": {
required: true,
minlength: 1
},
"user_session[password]": {
required: true,
minlength: 5
}
},
messages: {
"user_session[email]": "Please enter your username or email address.",
"user_session[password]": "Please enter your password."
},
errorPlacement: function () {
$("div#sign-in p.error-notice").text("Please check the highlighted field(s) below...")
}
},
join: {
element: "#join-form",
errorContainer: "div#sign-up p.error-notice",
rules: {
"user[name]": {
required: true,
minlength: 5
},
"user[username]": {
required: true,
minlength: 1,
maxlength: 25,
regex: "(^[a-z0-9]+$|^[a-z0-9]+:.{8}$)",
remote: zz.path_prefix + "/users/validate_username"
},
"user[email]": {
required: true,
email: true,
remote: zz.path_prefix + "/users/validate_email"
},
"user[password]": {
required: true,
minlength: 5
}
},
messages: {
"user[name]": {
required: "Please enter your name.",
minlength: "Please enter at least 5 letters"
},
"user[username]": {
required: "A username is required.",
regex: "Only lowercase alphanumeric characters allowed",
remote: "username not available"
},
"user[email]": {
required: "We promise we won&rsquo;t spam you.",
email: "Is that a valid email?",
remote: "Email already used"
},
"user[password]": "Six characters or more please."
}
}
};
zz.wizard = {
make_drawer: function (c, a) {
c.init();
zz.drawer_state == zz.DRAWER_CLOSED && zz.open_drawer(c.time, c.percent);
zz.wizard.build_nav(c, a);
var b = $("#tab-content");
c.steps[a].init(b, function () {
zz.wizard.resize_scroll_body()
});
$("body").addClass("drawer")
},
change_step: function (c, a) {
var b = $("#tab-content");
if (a.steps[c].type == "partial" && zz.drawer_state == zz.DRAWER_OPEN) {
$("#tab-content").fadeOut("fast");
zz.close_drawer_partially(a.time, 40);
zz.wizard.build_nav(a, c);
a.steps[c].init(b, function () {
zz.wizard.resize_scroll_body()
})
} else if (a.steps[c].type == "partial" && zz.drawer_state == zz.DRAWER_PARTIAL) {
zz.wizard.build_nav(a, c);
a.steps[c].init(b, function () {
zz.wizard.resize_scroll_body()
})
} else if (a.steps[c].type == "full" && zz.drawer_state == zz.DRAWER_PARTIAL) {
zz.wizard.build_nav(a, c);
$("#tab-content").empty().show();
zz.open_drawer(a.time);
setTimeout(function () {
a.steps[c].init(b, function () {
zz.wizard.resize_scroll_body()
})
}, a.time)
} else if (a.steps[c].type == "full" && zz.drawer_state == zz.DRAWER_OPEN) {
zz.wizard.build_nav(a, c);
$("#tab-content").fadeOut(100, function () {
$("#tab-content").empty();
$("#tab-content").show();
a.steps[c].init(b, function () {
zz.wizard.resize_scroll_body()
})
})
} else if (a.steps[c].type == "partial" && zz.drawer_state == zz.DRAWER_CLOSED) {
zz.open_drawer(80, a.percent);
zz.close_drawer_partially(a.time);
zz.wizard.build_nav(a, c);
a.steps[c].init(b, function () {
zz.wizard.resize_scroll_body()
})
} else console.warn("This should never happen. Context: zz.wizard.change_step, Type: " + a.steps[c].type + ", Drawer State: " + zz.drawer_state)
},
build_nav: function (c, a, b) {
var d = 1,
e = "";
$.each(c.steps, function (f, g) {
if (f == a && c.numbers == 1) {
value = d;
e += '<li id="wizard-' + f + '" class="tab on">';
e += '<img src="' + path_helpers.image_url("/images/wiz-num-" + d + "-on.png") + '" class="num"> ' + g.title + "</li>"
} else if (f == a) {
value = d;
e += '<li id="wizard-' + f + '" class="tab on">' + g.title + "</li>"
} else if (c.numbers == 1) {
e += '<li id="wizard-' + f + '" class="tab">';
e += '<img src="' + path_helpers.image_url("/images/wiz-num-" + d + ".png") + '" class="num"> ' + g.title + "</li>"
} else e += '<li id="wizard-' + f + '" class="tab">' + g.title + "</li>";
d++
});
d--;
if (c.show_next_button === true) {
if (c.steps[a].next == 0 || c.style == "edit") {
e += '<li class="next-done">';
e += '<a id="next-step" class="green-button"><span>Done</span></a>'
} else {
e += '<li class="next-done">';
e += '<a id="next-step" class="next-button"><span>Next</span></a>'
}
e += "</li>"
}
b && $("#drawer-tabs").hide();
c.style == "edit" ? $("#drawer-tabs").html($("#clone-indicator").clone().attr("id", "indicator-" + d).addClass("edit-" + value + "-" + d).html(e)) : $("#drawer-tabs").html($("#clone-indicator").clone().attr("id", "indicator-" + d).addClass("step-" + value + "-" + d).html(e));
b && $("#drawer-tabs").fadeIn("fast");
zz.wizard.resize_scroll_body();
$.each(c.steps, function (f) {
$("li#wizard-" + f).click(function (g) {
g.preventDefault();
d = $(this).attr("id").split("wizard-")[1];
c.steps[a].bounce(function () {
zz.wizard.change_step(d, c)
})
})
});
if (c.show_next_button === true) c.last == a || c.style == "edit" ? $("#next-step").click(function () {
c.steps[a].bounce(function () {
$("#drawer .body").fadeOut("fast");
zz.close_drawer(400);
c.on_close()
})
}) : $("#next-step").click(function (f) {
f.preventDefault();
c.steps[a].bounce(function () {
d = c.steps[a].next;
zz.wizard.change_step(d, c)
})
})
},
resize_scroll_body: function () {
$("div#drawer-content div#scroll-body").css({
height: zz.drawer_height - 140 + "px"
})
},
set_wizard_style: function (c) {
if (c == "edit") {
$("div#drawer").css("background-image", "url(" + path_helpers.image_url("/images/bg-drawer-bottom-cap.png") + ")");
$("div#cancel-drawer-btn").hide()
} else {
$("div#drawer").css("background-image", "url(" + path_helpers.image_url("/images/bg-drawer-bottom-cap-with-cancel.png") + ")");
$("div#cancel-drawer-btn").show()
}
zz.screen_gap = 160
},
create_group_album: function () {
$.post(zz.path_prefix + "/users/" + zz.current_user_id + "/albums", {
album_type: "GroupAlbum"
}, function (c) {
zz.album_id = c;
zz.wizard.make_drawer(zz.drawers.group_album, "add")
})
},
open_edit_album_wizard: function (c) {
switch (zz.album_type) {
case "profile":
case "group":
if (typeof zz.drawers.edit_group_album == "undefined") {
zz.drawers.edit_group_album = zz.drawers.group_album;
zz.drawers.edit_group_album.style = "edit"
}
zz.wizard.make_drawer(zz.drawers.edit_group_album, c);
break;
default:
logger.debug("zz.wizard.open_edit_album_wizard: Albums of type: " + zz.album_type + " are not supported yet.")
}
},
open_settings_drawer: function (c) {
zz.wizard.make_drawer(zz.drawers.settings, c)
},
close_settings_drawer: function () {
$("#drawer .body").fadeOut("fast");
zz.close_drawer(400);
setTimeout(function () {
window.location.reload(false)
}, 1)
},
display_flashes: function (c, a) {
var b = c.getResponseHeader("X-Flash");
if (b && b.length > 0 && $("#flashes-notice")) {
b = $.parseJSON(b);
b.notice && $("#flashes-notice").text(b.notice).fadeIn("fast", function () {
setTimeout(function () {
$("#flashes-notice").fadeOut("fast", function () {
$("#flashes-notice").text(" ")
})
}, a + 3E3)
});
b.error && $("#error-notice").text(b.error).fadeIn("fast", function () {
setTimeout(function () {
$("#error-notice").fadeOut("fast", function () {
$("#error-notice").text(" ")
})
}, a + 3E3)
})
}
},
display_errors: function (c, a) {
var b = c.getResponseHeader("X-Errors");
if (b) {
b = $.parseJSON(b);
var d = "",
e;
for (e in b) if (typeof e !== "undefined") {
d = b[e];
break
}
$("#error-notice").text(d).fadeIn("fast", function () {
a > 0 && setTimeout(function () {
$("#error-notice").fadeOut("fast", function () {
$("#error-notice").text(" ")
})
}, a + 3E3)
})
}
}
};
function loadScript(c, a, b) {
var d = document.createElement("script");
d.type = "text/javascript";
if (d.readyState) d.onreadystatechange = function () {
if (d.readyState == "loaded" || d.readyState == "complete") {
d.onreadystatechange = null;
b && b()
}
};
else d.onload = function () {
b && b()
};
d.src = "https:" == document.location.protocol ? a : c;
c = document.getElementsByTagName("script")[0];
c.parentNode.insertBefore(d, c)
}
function initGoogle() {
loadScript("http://www.google-analytics.com/ga.js", "https://ssl.google-analytics.com/ga.js", function () {
window._gaq = window._gaq || [];
window._gaq.push(["_setAccount", zza_config_GOOGLE_ANALYTICS_TOKEN]);
window._gaq.push(["_trackPageview"])
})
}
function initMixpanel() {
loadScript("http://api.mixpanel.com/site_media/js/api/mixpanel.js", "https://api.mixpanel.com/site_media/js/api/mixpanel.js", function () {
try {
window.mpmetrics = new MixpanelLib(zza_config_MIXPANEL_TOKEN);
mpmetrics.register({
referrer: document.referrer
});
_zza.mixpanel_ready()
} catch (c) {
var a = function () {};
window.mpmetrics = {
track: a,
track_funnel: a,
register: a,
register_once: a,
register_funnel: a
}
}
})
}
function initZZA() {
$(window).bind("beforeunload", function () {
window._zza.close()
});
window._zza = new ZZA(zza_config_ZZA_ID, zuserid, true);
_zza.init();
window.ZZAt = {
track: function (c, a) {
if (typeof a == "undefined") {
_zza.track_event2(c, null);
if (typeof _gaq != "undefined") {
_gaq.push(["_trackPageview", "/event/" + c]);
_gaq.push(["_trackEvent", "potd", c])
}
typeof console != "undefined" && console.log("ZZA event: " + c)
} else {
_zza.track_event2(c, a);
if (typeof _gaq != "undefined") {
var b = "?",
d;
for (d in a) b += d + "=" + a[d] + "&";
b = b.substring(0, b.length - 1);
_gaq.push(["_trackPageview", "/event/" + c + b]);
_gaq.push(["_trackEvent", "potd", c])
}
if (typeof console != "undefined") {
console.log("ZZA event: " + c);
console.log("ZZA properties: " + a)
}
}
}
};
ZZAt.track("page.visit", {
ua: navigator.userAgent
});
window.onerror = function (c, a, b) {
try {
a.indexOf("http://localhost:30777") == -1 && ZZAt.track("js.error", {
message: c,
url: a,
line: b
})
} catch (d) {}
return true
}
}
initZZA();
$(document).ready(function () {
setTimeout(function () {
initGoogle();
initMixpanel()
}, 1)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment