Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setCue(a, b, c) {
- $.withCSRF(function(d) {
- $.ajax({url:"/site-api/users/set-template-cue/", type:"POST", data:JSON.stringify({cue:a, value:b, csrftoken:d})}).done(c).error(function(d, e, f) {
- document.cookie = "cue_" + a + "=" + b;
- c(d, e, f);
- });
- });
- }
- function openDialogue(a, b) {
- $(a).dialog(b);
- }
- function openResendDialogue() {
- var a = {title:gettext("Want to share on Scratch?"), open:function(a, c) {
- var b = this;
- $("#close-resend-dialog").off();
- $("#close-resend-dialog").click(function() {
- $(b).dialog("close");
- });
- $("#email-resend-box form").submit(function(a) {
- a.preventDefault();
- $.ajax({url:"/accounts/email_resend/", type:"POST", data:{email_address:$("#hidden-email-address").val()}, success:function(a) {
- $("#submit-resend", b).attr("disabled", "disabled");
- $("#submit-resend", b).val("Resent");
- }});
- });
- $("#email-resend-box :link").blur();
- }, close:function(a, c) {
- $(this).dialog("destroy");
- $(".ui-widget-overlay.ui-front").remove();
- }, show:{effect:"clip", duration:250}, hide:{effect:"clip", duration:250}};
- 0 < $("#email-resend-box").length ? openDialogue("#email-resend-box", a) : $.ajax({url:"/accounts/email_resend/"}).done(function(b) {
- b = $(_.template(b)());
- openDialogue(b, a);
- });
- }
- !function(a) {
- var b = function(a, b) {
- this.init("tooltip", a, b);
- };
- b.prototype = {constructor:b, init:function(b, c, e) {
- var d, g;
- this.type = b;
- this.$element = a(c);
- this.options = this.getOptions(e);
- this.enabled = !0;
- b = this.options.trigger.split(" ");
- for (e = b.length; e--;) {
- c = b[e], "click" == c ? this.$element.on("click." + this.type, this.options.selector, a.proxy(this.toggle, this)) : "manual" != c && (d = "hover" == c ? "mouseenter" : "focus", g = "hover" == c ? "mouseleave" : "blur", this.$element.on(d + "." + this.type, this.options.selector, a.proxy(this.enter, this)), this.$element.on(g + "." + this.type, this.options.selector, a.proxy(this.leave, this)));
- }
- this.options.selector ? this._options = a.extend({}, this.options, {trigger:"manual", selector:""}) : this.fixTitle();
- }, getOptions:function(b) {
- return b = a.extend({}, a.fn[this.type].defaults, this.$element.data(), b), b.delay && "number" == typeof b.delay && (b.delay = {show:b.delay, hide:b.delay}), b;
- }, enter:function(b) {
- var d = a.fn[this.type].defaults, c = {};
- this._options && a.each(this._options, function(a, b) {
- d[a] != b && (c[a] = b);
- }, this);
- var f = a(b.currentTarget)[this.type](c).data(this.type);
- if (!f.options.delay || !f.options.delay.show) {
- return f.show();
- }
- clearTimeout(this.timeout);
- f.hoverState = "in";
- this.timeout = setTimeout(function() {
- "in" == f.hoverState && f.show();
- }, f.options.delay.show);
- }, leave:function(b) {
- var d = a(b.currentTarget)[this.type](this._options).data(this.type);
- this.timeout && clearTimeout(this.timeout);
- if (!d.options.delay || !d.options.delay.hide) {
- return d.hide();
- }
- d.hoverState = "out";
- this.timeout = setTimeout(function() {
- "out" == d.hoverState && d.hide();
- }, d.options.delay.hide);
- }, show:function() {
- var b = a.Event("show");
- if (this.hasContent() && this.enabled && (this.$element.trigger(b), !b.isDefaultPrevented())) {
- var c = this.tip();
- this.setContent();
- this.options.animation && c.addClass("fade");
- var e = "function" == typeof this.options.placement ? this.options.placement.call(this, c[0], this.$element[0]) : this.options.placement;
- c.detach().css({top:0, left:0, display:"block"});
- this.options.container ? c.appendTo(this.options.container) : c.insertAfter(this.$element);
- b = this.getPosition();
- var f = c[0].offsetWidth;
- c = c[0].offsetHeight;
- switch(e) {
- case "bottom":
- var h = {top:b.top + b.height, left:b.left + b.width / 2 - f / 2};
- break;
- case "top":
- h = {top:b.top - c, left:b.left + b.width / 2 - f / 2};
- break;
- case "left":
- h = {top:b.top + b.height / 2 - c / 2, left:b.left - f};
- break;
- case "right":
- h = {top:b.top + b.height / 2 - c / 2, left:b.left + b.width};
- }
- this.applyPlacement(h, e);
- this.$element.trigger("shown");
- }
- }, applyPlacement:function(a, b) {
- var c = this.tip(), d = c[0].offsetWidth, g = c[0].offsetHeight, k, n;
- c.offset(a).addClass(b).addClass("in");
- var m = c[0].offsetWidth;
- var l = c[0].offsetHeight;
- "top" == b && l != g && (a.top = a.top + g - l, n = !0);
- "bottom" == b || "top" == b ? (k = 0, 0 > a.left && (k = -2 * a.left, a.left = 0, c.offset(a), m = c[0].offsetWidth), this.replaceArrow(k - d + m, m, "left")) : this.replaceArrow(l - g, l, "top");
- n && c.offset(a);
- }, replaceArrow:function(a, b, c) {
- this.arrow().css(c, a ? 50 * (1 - a / b) + "%" : "");
- }, setContent:function() {
- var a = this.tip(), b = this.getTitle();
- a.find(".tooltip-inner")[this.options.html ? "html" : "text"](b);
- a.removeClass("fade in top bottom left right");
- }, hide:function() {
- function b() {
- var b = setTimeout(function() {
- c.off(a.support.transition.end).detach();
- }, 500);
- c.one(a.support.transition.end, function() {
- clearTimeout(b);
- c.detach();
- });
- }
- var c = this.tip(), e = a.Event("hide");
- this.$element.trigger(e);
- if (!e.isDefaultPrevented()) {
- return c.removeClass("in"), a.support.transition && this.$tip.hasClass("fade") ? b() : c.detach(), this.$element.trigger("hidden"), this;
- }
- }, fixTitle:function() {
- var a = this.$element;
- (a.attr("title") || "string" != typeof a.attr("data-original-title")) && a.attr("data-original-title", a.attr("title") || "").attr("title", "");
- }, hasContent:function() {
- return this.getTitle();
- }, getPosition:function() {
- var b = this.$element[0];
- return a.extend({}, "function" == typeof b.getBoundingClientRect ? b.getBoundingClientRect() : {width:b.offsetWidth, height:b.offsetHeight}, this.$element.offset());
- }, getTitle:function() {
- var a, b = this.$element, c = this.options;
- return a = b.attr("data-original-title") || ("function" == typeof c.title ? c.title.call(b[0]) : c.title), a;
- }, tip:function() {
- return this.$tip = this.$tip || a(this.options.template);
- }, arrow:function() {
- return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow");
- }, validate:function() {
- this.$element[0].parentNode || (this.hide(), this.$element = null, this.options = null);
- }, enable:function() {
- this.enabled = !0;
- }, disable:function() {
- this.enabled = !1;
- }, toggleEnabled:function() {
- this.enabled = !this.enabled;
- }, toggle:function(b) {
- b = b ? a(b.currentTarget)[this.type](this._options).data(this.type) : this;
- b.tip().hasClass("in") ? b.hide() : b.show();
- }, destroy:function() {
- this.hide().$element.off("." + this.type).removeData(this.type);
- }};
- var c = a.fn.tooltip;
- a.fn.tooltip = function(c) {
- return this.each(function() {
- var d = a(this), e = d.data("tooltip"), f = "object" == typeof c && c;
- e || d.data("tooltip", e = new b(this, f));
- "string" == typeof c && e[c]();
- });
- };
- a.fn.tooltip.Constructor = b;
- a.fn.tooltip.defaults = {animation:!0, placement:"top", selector:!1, template:'<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>', trigger:"hover focus", title:"", delay:0, html:!1, container:!1};
- a.fn.tooltip.noConflict = function() {
- return a.fn.tooltip = c, this;
- };
- }(window.jQuery);
- !function(a) {
- var b = function(a, b) {
- this.init("popover", a, b);
- };
- b.prototype = a.extend({}, a.fn.tooltip.Constructor.prototype, {constructor:b, setContent:function() {
- var a = this.tip(), b = this.getTitle(), c = this.getContent();
- a.find(".popover-title")[this.options.html ? "html" : "text"](b);
- a.find(".popover-content")[this.options.html ? "html" : "text"](c);
- a.removeClass("fade top bottom left right in");
- }, hasContent:function() {
- return this.getTitle() || this.getContent();
- }, getContent:function() {
- var a, b = this.$element, c = this.options;
- return a = ("function" == typeof c.content ? c.content.call(b[0]) : c.content) || b.attr("data-content"), a;
- }, tip:function() {
- return this.$tip || (this.$tip = a(this.options.template)), this.$tip;
- }, destroy:function() {
- this.hide().$element.off("." + this.type).removeData(this.type);
- }});
- var c = a.fn.popover;
- a.fn.popover = function(c) {
- return this.each(function() {
- var d = a(this), e = d.data("popover"), f = "object" == typeof c && c;
- e || d.data("popover", e = new b(this, f));
- "string" == typeof c && e[c]();
- });
- };
- a.fn.popover.Constructor = b;
- a.fn.popover.defaults = a.extend({}, a.fn.tooltip.defaults, {placement:"right", trigger:"click", content:"", template:'<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'});
- a.fn.popover.noConflict = function() {
- return a.fn.popover = c, this;
- };
- }(window.jQuery);
- Backbone.View.prototype.close = function(a) {
- a = a || {};
- a.persist || this.remove();
- this.unbind();
- this.undelegateEvents();
- this.onClose && this.onClose();
- };
- Backbone.View.prototype.open = function(a) {
- this.initialize();
- this.model.fetch();
- this.delegateEvents();
- };
- Backbone.View.prototype._super = function(a) {
- var b = this.constructor.__super__[a];
- return "function" == typeof b ? b.apply(this, _.rest(arguments)) : b;
- };
- var Scratch = Scratch || {};
- Scratch.Model = Backbone.Model.extend({initialize:function(a, b) {
- _.bindAll(this, "report");
- if (b && b.related) {
- this.related = b.related;
- var c = this;
- $.each(this.related, function(a, b) {
- b.parentModel = c;
- });
- }
- this.init(b);
- }, url:function() {
- return this.urlRoot + this.getId() + "/";
- }, getId:function() {
- return this.slug ? this.get(this.slug) : this.id;
- }, init:function(a) {
- }, parse:function(a) {
- return a.fields ? $.extend(a.fields, {id:a.pk}) : a;
- }, create:function(a) {
- return a = a || {}, a.url = this.urlRoot + "create/", this.isNew() ? (a.error || (a.error = function() {
- console.error && console.error("in model.create, error arguments:", arguments);
- }), Backbone.sync("create", this, a), !0) : !1;
- }, fetchRelated:function(a) {
- a ? this.related[a].fetch() : $.each(this.related, function(a, c) {
- c.fetch();
- });
- }, report:function(a, b) {
- a || (a = {});
- var c = this.url() + "report/";
- $.ajax(c, {type:"POST", data:JSON.stringify(a), dataType:"json", success:b});
- }});
- Scratch.Collection = Backbone.Collection.extend({paginationData:{page:1, ascsort:"", descsort:""}, hasMore:!0, count:0, url:function() {
- var a = this.urlRoot;
- return a += this.options.collectionType ? this.options.collectionType + "/" : "", a += this.parentModel ? this.parentModel.getId() + "/" : "", a;
- }, addItems:function(a, b) {
- b = b || {};
- var c = this.slug ? this.slug + "s" : "pks", d = _.isArray(a) ? a.length : 1;
- a = _.isArray(a) ? a.join(",") : a;
- b.url = this.url() + "add/?" + c + "=" + a;
- var g = b.success, e = this;
- b.success = function(a, b, c) {
- e.add(a);
- g && g(this, a);
- e.trigger("addItemsSuccess", d);
- };
- Backbone.sync("update", this.parentModel, b);
- }, removeItems:function(a, b) {
- b = b || {};
- var c = this.slug ? this.slug + "s" : "pks", d = _.isArray(a) ? a.length : 1;
- a = _.isArray(a) ? a.join(",") : a;
- b.url = this.url() + "remove/?" + c + "=" + a;
- var g = b.success, e = this;
- b.success = function(a, b, c) {
- b = [];
- for (i = 0; i < a.length; i++) {
- b[i] = a[i].id;
- }
- e.remove(b);
- g && g(this, a);
- e.trigger("removeItemsSuccess", d);
- };
- Backbone.sync("update", this.parentModel, b);
- }, loadMore:function(a) {
- if (!this.hasMore) {
- return !1;
- }
- a = a || {};
- this.paginationData.page += 1;
- var b = this, c = a.error || {};
- a.error = function(a, g, e) {
- b.hasMore = !1;
- c();
- };
- a.add = !0;
- a.data = this.paginationData;
- this.fetch(a);
- }, ajaxSort:function(a, b) {
- b = b || {};
- this.paginationData.page = 1;
- $.extend(this.paginationData, a);
- b.data = this.paginationData;
- b.add = !1;
- this.fetch(b);
- }, ajaxFilter:function(a, b) {
- self.hasMore = !0;
- b = b || {};
- this.paginationData.page = 1;
- this.options.collectionType = a;
- b.data = this.paginationData;
- b.add = !1;
- this.fetch(b);
- }});
- Scratch = Scratch || {};
- Scratch.Utils = {};
- Scratch.Utils.viewMixin = function(a) {
- var b = this.prototype;
- _.defaults(b, a);
- _.defaults(b.events, a.events);
- Scratch.Utils.extendMethod(b, a, "initialize");
- Scratch.Utils.extendMethod(b, a, "render");
- };
- Scratch.Utils.extendMethod = function(a, b, c) {
- if (!_.isUndefined(b[c])) {
- var d = a[c];
- a[c] = function() {
- var a = d.apply(this, arguments);
- return b[c].apply(this, arguments), a;
- };
- }
- };
- Backbone.View.mixin = Scratch.Utils.viewMixin;
- Scratch.Mixins = Scratch.Mixins || {};
- Scratch.Mixins.Followable = {events:{'click [data-control="follow"]':"follow", 'click [data-control="unfollow"]':"unfollow"}, initialize:function() {
- _.bindAll(this, "followed");
- _.bindAll(this, "unfollowed");
- }, follow:function() {
- this.model.related.followers.addItems(Scratch.LoggedInUser.get("username"), {success:this.followed, error:this.onFollowError});
- }, followed:function(a, b) {
- this.$('[data-control="follow"]').removeClass("blue notfollowing").addClass("grey following").attr("data-control", "unfollow");
- this.onFollowSuccess(a, b);
- }, onFollowSuccess:function(a, b) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"success", msg:Scratch.ALERT_MSGS.followed});
- }, onFollowError:function(a, b) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"error", msg:a.responseJSON[0].errors.join(",")});
- }, unfollow:function(a, b) {
- this.model.related.followers.removeItems(Scratch.LoggedInUser.get("username"), {success:this.unfollowed});
- }, unfollowed:function(a, b) {
- this.$('[data-control="unfollow"]').removeClass("grey following").addClass("blue notfollowing").attr("data-control", "follow");
- this.onUnfollowSuccess(a, b);
- }, onUnfollowSuccess:function(a, b) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"success", msg:Scratch.ALERT_MSGS.unfollowed});
- }};
- Scratch.ModelView = Backbone.View.extend({initialize:function(a, b) {
- this.model.bind("error", this.onError, this);
- this.model.bind("changeSuccess", this.onChangeSuccess, this);
- }, onError:function(a) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"error", msg:Scratch.ALERT_MSGS.error});
- }, onChangeSuccess:function(a) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"success", msg:Scratch.ALERT_MSGS["changes-saved"]});
- }});
- Scratch.CollectionView = Backbone.View.extend({events:{'click [data-control="load-more"]':"loadMore", 'click [data-control="sort"]':"sort", 'click [data-control="filter"]':"filter", 'click [data-control="remove-item"]':"removeItem"}, initialize:function(a) {
- this.options = a || {};
- if (this.options.template || this.options.collectionTemplate) {
- this.wrapperTemplate = this.options.template, this.listTemplate = this.options.collectionTemplate;
- }
- this.model.bind("add", this.render, this);
- this.model.bind("remove", this.render, this);
- this.model.bind("remove", this.onRemove, this);
- this.model.bind("reset", this.render, this);
- this.model.bind("addItemsSuccess", this.onAddSuccess, this);
- this.model.bind("removeItemsSuccess", this.onRemoveSuccess, this);
- this.model.bind("error", this.onError, this);
- this.wrapperTemplate && $(this.el).html(this.wrapperTemplate({collection:[]}));
- }, onClose:function() {
- this.model.unbind("add", this.render);
- this.model.unbind("remove", this.render);
- this.model.unbind("remove", this.onRemove);
- this.model.unbind("reset", this.render);
- this.model.unbind("addItemsSuccess", this.onAddSuccess);
- this.model.unbind("removeItemsSuccess", this.onRemoveSuccess);
- this.model.unbind("error", this.onError);
- }, render:function() {
- return this.renderCollection(), this;
- }, renderCollection:function() {
- this.$('[data-content="collection"]').html(this.listTemplate({collection:this.model.toJSON()}));
- }, removeItem:function(a) {
- this.model.removeItems([$(a.currentTarget).parent(["data-id"]).data("id")]);
- }, loadMore:function(a) {
- var b = this, c = $(a.currentTarget).addClass("loading");
- b.model.loadMore({success:function() {
- b.render();
- c.removeClass("loading");
- }, error:function(a) {
- c.remove();
- }});
- }, sort:function(a) {
- a = {ascsort:$(a.target).data("ascsort") || "", descsort:$(a.target).data("descsort") || ""};
- this.model.ajaxSort(a);
- }, filter:function(a) {
- this.model.ajaxFilter($(a.target).data("filter"));
- }, onRemove:function(a) {
- }, onAdd:function(a) {
- }, onError:function(a) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"error", msg:Scratch.ALERT_MSGS.error});
- }});
- Scratch.ExploreBar = Scratch.CollectionView.extend({events:function() {
- return _.extend({}, Scratch.CollectionView.prototype.events, {'click [data-control="open"]':"openBar", 'click [data-control="close"]':"closeBar", "click #explore-buttons":"stopEvent", 'click [data-control="next"]':"next", 'click [data-control="prev"]':"prev", 'click [data-control="draggable"]':"itemClicked", 'click [data-control="open-explore-bar"]':"openBar"});
- }, initialize:function(a) {
- Scratch.CollectionView.prototype.initialize.apply(this, [a]);
- this.model.unbind("add");
- this.$scrollArea = this.$(".carousel-inner ul");
- this.$arrowLeft = this.$(".arrow-left");
- this.$arrowRight = this.$(".arrow-right");
- _.bindAll(this, "openBar", "preLoadSuccess", "preLoadError");
- Scratch.EventMgr = Scratch.EventMgr || _.extend({}, Backbone.Events);
- Scratch.EventMgr.on("explore-open", this.openBar, this);
- }, render:function() {
- Scratch.CollectionView.prototype.render.apply(this);
- this.$items = this.$(".carousel-inner li");
- this.$scrollArea.width(this.$items.outerWidth(!0) * this.model.length);
- this.scrollPageWidth = this.$(".carousel-inner").width() + parseInt(this.$items.css("padding-right"), 10) - 10;
- this.scrollMax = this.$scrollArea.width() - this.scrollPageWidth;
- }, next:function() {
- if (!this.sliding) {
- return this.slide("next");
- }
- }, prev:function() {
- if (!this.sliding) {
- return this.slide("prev");
- }
- }, toggleArrows:function(a) {
- 0 >= a ? this.$arrowLeft.addClass("off").removeClass("on") : a >= this.scrollMax ? this.$arrowRight.addClass("off").removeClass("on") : (this.$arrowRight.removeClass("off").addClass("on"), this.$arrowLeft.removeClass("off").addClass("on"));
- }, slide:function(a) {
- var b = "start" == a ? 0 : this.$(".carousel-inner").scrollLeft() + ("next" == a ? this.scrollPageWidth : -this.scrollPageWidth);
- return this.toggleArrows(b), this.sliding = !0, this.$(".carousel-inner").animate({scrollLeft:b}, 800, "swing", $.proxy(function() {
- this.sliding = !1;
- this.preLoad(b);
- }, this)), this;
- }, preLoad:function(a) {
- this.model.hasMore && a >= this.scrollMax - this.scrollPageWidth && (this.$(".carousel-inner").addClass("loading"), this.model.loadMore({success:this.preLoadSuccess, error:this.preLoadError}));
- }, preLoadSuccess:function(a, b, c) {
- this.render();
- this.$(".carousel-inner").removeClass("loading");
- }, preLoadError:function(a, b, c) {
- this.$(".carousel-inner").removeClass("loading");
- }, openBar:function() {
- $("body").addClass("explore-bar-visible");
- this.$("#related-projects").animate({height:"160px"});
- this.$("#explore-header").attr("data-control", "close");
- this.$("#explore-header-open").removeClass("hidden");
- this.$("#explore-header-closed").addClass("hidden");
- this.$(".carousel-control").css("display", "inline");
- this.model.fetch();
- this.isOpenBar = !0;
- }, closeBar:function() {
- $("body").removeClass("explore-bar-visible");
- $("#related-projects").animate({height:"0px"});
- this.$("#explore-header").attr("data-control", "open");
- $("#explore-header-closed").removeClass("hidden");
- $("#explore-header-open").addClass("hidden");
- this.$(".carousel-control").css("display", "none");
- this.isOpenBar = !1;
- }, stopEvent:function(a) {
- a.stopPropagation();
- }, open:function() {
- this.model.fetch();
- this.delegateEvents();
- }, filter:function(a) {
- Scratch.CollectionView.prototype.filter.apply(this, [a]);
- this.$(".carousel-inner").scrollLeft(0);
- }, itemClicked:function(a) {
- a.preventDefault();
- Scratch.EventMgr.trigger("explore-item-clicked", $(a.currentTarget).data());
- }});
- Scratch.CollectionCountView = Backbone.View.extend({initialize:function(a) {
- this.template = _.template($("#template-collection-count").html());
- this.count = a.count || null;
- this.model.bind("add", this.add, this);
- this.model.bind("remove", this.remove, this);
- this.model.bind("reset", this.render, this);
- this.model.bind("change", this.render, this);
- }, render:function() {
- count = this.count ? this.count : this.model.length;
- this.$el.html(this.template({count:count}));
- }, add:function() {
- count = this.count++ || this.model.length;
- this.render();
- }, remove:function() {
- count = this.count-- || this.model.length;
- this.render();
- }});
- Scratch.ViewManager = Backbone.View.extend({initialize:function(a) {
- this.views = a.views;
- }, swapView:function(a) {
- this.currentView && this.currentView.close();
- (this.currentView = this.views[a]) ? (this.currentView.open(), this.$('[data-content="view"]').html(this.currentView.el)) : this.$('[data-content="view"]').html("");
- this.trigger("swapped", a);
- }});
- Scratch.TabsView = Scratch.ViewManager.extend({events:{'click [data-control="tab"]':"switchTab"}, switchTab:function(a) {
- a = $(a.target.parentNode);
- this.$('[data-control="tab"]').removeClass("active");
- a.addClass("active");
- this.swapView(a.data("tab"));
- }, selectTab:function(a) {
- this.$("[data-tab]").removeClass("active");
- this.$('[data-tab="' + a + '"]').addClass("active");
- this.swapView(a);
- }});
- Scratch.LogoutView = Backbone.View.extend({events:{"submit form":"logout"}, logout:function(a) {
- a.preventDefault();
- $.ajax({type:"POST", url:"/accounts/logout/", success:function(a, c, d) {
- window.location.href = "/";
- }});
- }});
- Scratch.LoginView = Backbone.View.extend({initialize:function(a) {
- _.bindAll(this, "onLoginSuccess", "onLoginError");
- }, events:{"submit form":"login", "click .dropdown-menu":"formClick"}, formClick:function(a) {
- a.stopPropagation();
- }, login:function(a) {
- a.preventDefault();
- this.$("button").hide();
- this.$(".ajax-loader").show();
- if (this.$el.is("#login-dialog") && "undefined" != typeof this.recaptchaWidget) {
- var b = !0, c = grecaptcha.getResponse();
- } else {
- b = !1, c = "";
- }
- $.withCSRF(function(a) {
- this.model.login({username:this.$('[name="username"]').val(), password:this.$('[name="password"]').val(), "g-recaptcha-response":c, embed_captcha:b, timezone:jstz.determine().name(), csrfmiddlewaretoken:a}, {success:this.onLoginSuccess, error:this.onLoginError});
- }.bind(this));
- }, onLoginSuccess:function(a, b) {
- Scratch.LoggedInUser.set(this.model.attributes);
- this.$el.is("#login-dialog") ? 0 > location.href.indexOf("editor") && 0 > location.href.indexOf("pathways") ? location.reload() : (this.$el.modal("hide"), setAccountNavFromJson()) : (this.$el.removeClass("open"), location.reload());
- }, onLoginError:function(a, b) {
- if (400 === b.status) {
- return this.onLoginSuccess(a, b);
- }
- var c = b.responseJSON[0] || {msg:"An unknown error occurred"};
- "redirect" in c ? this.$el.is("#login-dialog") ? ("undefined" == typeof this.recaptchaWidget ? this.recaptchaWidget = grecaptcha.render("recaptcha-container") : grecaptcha.reset(this.recaptchaWidget), this.$(".error").html(c.msg).show(), this.$("button").show(), this.$(".ajax-loader").hide(), this.model.currentLoginUrl = this.model.loginRetryUrl) : window.location = c.redirect : (this.$(".error").html(c.msg).show(), this.$("button").show(), this.$(".ajax-loader").hide());
- }});
- Scratch.LanguageDropdownView = Backbone.View.extend({events:{"change #language-selection":"changeLanguage"}, changeLanguage:function(a) {
- var b = this;
- $.withCSRF(function(a) {
- $("<input>").attr({type:"hidden", name:"csrfmiddlewaretoken", value:a}).prependTo(b.$el);
- b.$el.submit();
- });
- }});
- Scratch.AlertView = Backbone.View.extend({className:"alert fade in", alerts:["success", "error", "info"], template:_.template('<span class="close">×</span><%= message %>'), events:{"click .close":"closeAlert"}, initialize:function(a) {
- var b = a.msg || "", c = a.hasOwnProperty("alert") ? a.alert : "info", d = void 0 === a.timer ? 3e3 : a.timer;
- a = a.memory || !1;
- if (-1 === _.indexOf(this.alerts, c)) {
- throw Error("Invalid alert: [" + c + "] Must be one of:" + this.alerts.join(", "));
- }
- this.alert = c;
- this.message = b;
- this.timer = d;
- this.memory = a;
- _.bindAll(this, "closeAlert");
- }, render:function() {
- var a = this.template({message:this.message});
- a = this.$el.addClass("alert-" + this.alert).html(a).show();
- return this.timer && a.delay(this.timer).fadeOut("slow"), this;
- }, closeAlert:function(a) {
- this.$el.stop().fadeOut("fast");
- }});
- Scratch.AlertView.msg = function(a, b) {
- var c = new Scratch.AlertView(b), d = a.html(c.render().el).width();
- return a.css({marginLeft:-d / 2, left:"50%"}), c;
- };
- Scratch.Comments = Backbone.View.extend({page:0, events:{'click [data-control="load-more"]':"getNextPage", 'click [data-control="post"]':function(a) {
- this.hideError(a);
- this.postComment(a);
- }, 'click [data-control="reply-to"]':"showReplyForm", 'click [data-control="cancel"]':"cancel", 'click [data-control="delete"]':"deleteComment", 'click [data-control="undelete"]':"undeleteComment", 'click [data-control="report"]':"report", 'click [data-control="unreport"]':"unreport", "click .more-replies":"showMoreReplies", "focus #comments textarea":"hideError", "change #comments-enabled":"toggleComments", "hover .tenmil":"confetti"}, initialize:function(a) {
- this.type = a.type;
- this.typeId = a.typeId;
- this.gaqType = "user" == this.type ? "profile" : "gallery" == this.type ? "studio" : this.type;
- this.commentPostingAllowed = $("#main-post-form").is(":visible");
- this.student_usernames = [];
- if (Scratch.INIT_DATA.LOGGED_IN_USER.model && Scratch.INIT_DATA.LOGGED_IN_USER.model.is_educator) {
- var b = new Scratch.UserThumbnailCollection([], {url:"/site-api/classrooms/students/of/" + Scratch.INIT_DATA.LOGGED_IN_USER.model.username, model:Scratch.UserThumbnail});
- this.gotStudents = $.Deferred();
- var c = function(a) {
- return "undefined" == typeof a && (a = 1), b.fetch({url:b.options.url, data:{page:a}, add:!0}).then(function(b) {
- return c(a + 1);
- }.bind(this)).fail(function() {
- this.student_usernames = b.models.map(function(a) {
- return a.get("user").username;
- });
- this.gotStudents.resolve();
- }.bind(this));
- }.bind(this);
- c();
- } else {
- this.gotStudents = $.Deferred(function(a) {
- a.resolve();
- });
- }
- this.commentReplyTemplate = _.template($("#template-comment-reply").html());
- Scratch.INIT_DATA.IS_SOCIAL ? (this.$("#main-post-form textarea").limit("500", "#chars-left"), this.$("#main-post-form textarea").keydown(function(a) {
- a.ctrlKey && (13 == a.keyCode || 10 == a.keyCode) && this.postComment(a);
- })) : (this.$("#main-post-form textarea").limit("0"), this.$("#main-post-form textarea").focus(function() {
- openResendDialogue();
- }));
- this.$commentContainer = $("<div>");
- a.scrollTo ? (this.scrollTo(".comments"), this.getNextPage("#comments" + a.scrollTo)) : this.getNextPage();
- }, hideError:function() {
- this.$(".control-group.tooltip").removeClass("error");
- }, render:function() {
- var a = this.$('[data-content="comments"]');
- a.find("#comments-loading").remove();
- a.append(this.$commentContainer.html());
- this.$commentContainer.html("");
- "project" == this.type && (a = $("[data-control-comment-count]").attr("data-control-comment-count") || "", 0 == a.length && (a = "0"), $("#comment-count").text("(" + a + ")"));
- }, confetti:function(a) {
- window.confettiRunning || (window.confettiRunning = !0, $("#content").confetti({x:a.pageX, y:a.pageY, complate:function() {
- window.confettiRunning = !1;
- }}));
- }, getNextPage:function(a) {
- this.$('[data-control="load-more"]').remove();
- var b = this, c = "";
- return Scratch.INIT_DATA.ADMIN && (c = "with-deleted/"), b.page++, $.ajax({url:"/site-api/comments/" + c + this.type + "/" + this.typeId + "/?page=" + this.page}).done(function(c) {
- if (40 < b.page) {
- throw "more than 40 pages of comments shouldn't be happening";
- }
- b.$commentContainer.append(c);
- !a || a instanceof $.Event ? (b.render(), b.$("span.time").timeago()) : -1 < c.indexOf(a.slice(1)) ? (b.render(), b.$("span.time").timeago(), setTimeout(function() {
- b.scrollTo(a);
- }, 0)) : (b.$commentContainer.find('[data-control="load-more"]').remove(), b.getNextPage(a));
- b.showCommentOptions();
- });
- }, showCommentOptions:function(a) {
- if (Scratch.INIT_DATA.LOGGED_IN_USER.options.authenticated && !Scratch.INIT_DATA.ADMIN) {
- a = a || this.$el;
- var b = this, c = !1, d = !1;
- Scratch.INIT_DATA.ADMIN && (c = !0);
- "project" == b.type ? (Scratch.INIT_DATA.PROJECT.model.creator == Scratch.INIT_DATA.LOGGED_IN_USER.model.username && (c = !0), d = Scratch.INIT_DATA.PROJECT.model.comments_allowed) : "user" == b.type ? (Scratch.INIT_DATA.PROFILE.model.username == Scratch.INIT_DATA.LOGGED_IN_USER.model.username && (c = !0), d = Scratch.INIT_DATA.PROFILE.model.comments_allowed) : "gallery" == b.type && (Scratch.INIT_DATA.GALLERY.model.is_owner && (c = !0), d = Scratch.INIT_DATA.GALLERY.model.comments_allowed);
- $.when(this.gotStudents).then(function() {
- a.find("div.comment").each(function() {
- var a = {can_delete:c, current_user:Scratch.INIT_DATA.LOGGED_IN_USER.model.username, comment_user:$(this).find("#comment-user").data("comment-user"), type:b.type, is_staff:Scratch.INIT_DATA.ADMIN};
- a.student_of_educator = 0 <= b.student_usernames.indexOf(a.comment_user);
- var e = _.template($("#template-comment-actions").html());
- $(this).find(".actions-wrap").html(e(a));
- $(this).find("a.reply").attr("data-control", "reply-to");
- d && Scratch.INIT_DATA.comment_posting && b.commentPostingAllowed && $(this).find("a.reply").css("display", "inline");
- });
- });
- }
- }, postComment:function(a) {
- a.preventDefault();
- var b = $(a.currentTarget), c = b.closest("form");
- a = $.trim(c.find("textarea").val());
- var d = {content:a, parent_id:b.data("parent-thread") || "", commentee_id:b.data("commentee-id") || ""}, g = !1, e = this;
- d.parent_id && (g = !0);
- var f = function(a) {
- c.find('[data-control="error"] .text').html(a);
- c.find('[data-control="info"]').hide();
- c.find(".control-group").addClass("error");
- };
- Scratch.INIT_DATA.IS_IP_BANNED ? $("#ip-mute-ban").modal() : "" == a ? f(Scratch.ALERT_MSGS["empty-comment"]) : (b.removeAttr("data-control").addClass("posting"), $.ajax({type:"POST", dataType:"html", data:JSON.stringify(d), url:"/site-api/comments/" + this.type + "/" + this.typeId + "/add/"}).done(function(a) {
- var c = $.trim(a);
- if ("isBad" == c) {
- f(Scratch.ALERT_MSGS["inappropriate-comment"]), _gaq.push(["_trackEvent", e.gaqType, "comment_rejected:bad_word"]);
- } else {
- if ("hasChatSite" == c) {
- f(Scratch.ALERT_MSGS["comment-has-chat-site"]), _gaq.push(["_trackEvent", e.gaqType, "comment_rejected:chat_site"]);
- } else {
- if ("isSpam" == c) {
- f(Scratch.ALERT_MSGS["comment-spam"]);
- } else {
- if ("isFlood" == c) {
- f(Scratch.ALERT_MSGS["comment-flood"]);
- } else {
- if ("isMuted" == c) {
- f(Scratch.ALERT_MSGS["comment-muted"]);
- } else {
- if ("isUnconstructive" == c) {
- f(Scratch.ALERT_MSGS["comment-unconstructive"]);
- } else {
- if ("isDisallowed" == c) {
- f(Scratch.ALERT_MSGS["comment-disallowed"]);
- } else {
- if ("isIPMuted" == c) {
- $("#ip-mute-ban").modal();
- } else {
- if ("isEmpty" == c) {
- f(Scratch.ALERT_MSGS.error);
- } else {
- if ("isTooLong" == c) {
- return;
- }
- }
- _gaq.push(["_trackEvent", e.gaqType, "comment_add"]);
- c = $("<li></li>");
- g ? (e.$('[data-thread="' + d.parent_id + '"]').append(c.html(a)), b.closest('[data-content="reply-form"]').html("")) : (b.closest("form").find("textarea").val("").end().find("#chars-left").html("500"), e.$('[data-content="comments"]').prepend(c.html(a + '<ul class="replies" data-thread="' + $(a).data("comment-id") + '"></ul>')));
- e.scrollTo(null, c);
- e.$("span.time").timeago();
- e.showCommentOptions(c);
- }
- }
- }
- }
- }
- }
- }
- }
- }).error(function(a) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"error", msg:Scratch.ALERT_MSGS.error});
- }).always(function(a) {
- b.attr("data-control", "post").removeClass("posting");
- }));
- }, showReplyForm:function(a) {
- if (this.commentPostingAllowed) {
- var b = $(a.currentTarget), c = this, d = b.closest("li");
- this.showMoreReplies({useAnimation:d.closest(".top-level-reply").find(".truncated").length, $elem:d, callback:function() {
- var a = d.find('[data-content="reply-form"]:first').html(c.commentReplyTemplate({thread_id:b.data("parent-thread"), commentee_id:b.data("commentee-id"), comment_id:b.data("comment-id")}));
- Scratch.INIT_DATA.IS_SOCIAL ? a.find("textarea").focus().limit("500", "#chars-left-" + b.data("comment-id")) : (a.find("textarea").limit("0"), a.find("textarea").focus(function() {
- openResendDialogue();
- }));
- }});
- }
- }, cancel:function(a) {
- a.preventDefault();
- $(a.currentTarget).parents("form:first").find("textarea")[0].value = "";
- $(a.currentTarget).parents("form:first").find("#chars-left").html("500");
- $(a.currentTarget).parents('[data-content="reply-form"]:first').empty();
- }, submitDelete:function(a) {
- var b = $(a.currentTarget).closest("[data-comment-id]");
- a = b.attr("data-comment-id");
- $.ajax({url:"/site-api/comments/" + this.type + "/" + this.typeId + "/del/", type:"POST", dataType:"html", data:JSON.stringify({id:a})}).done(function(a) {
- b.parent("li").remove();
- _gaq.push(["_trackEvent", self.gaqType, "comment_deleted"]);
- });
- }, deleteComment:function(a) {
- var b = this;
- if (Scratch.INIT_DATA.ADMIN) {
- return b.submitDelete(a);
- }
- this.deleteDialogElem = this.deleteDialogElem || $(Scratch.ALERT_MSGS.delete_comment);
- this.deleteDialogElem.dialog({buttons:{Cancel:function() {
- $(this).dialog("close");
- }, Delete:function() {
- $(this).dialog("close");
- b.submitDelete(a);
- }, Report:function() {
- $(this).dialog("close");
- b.submitReport(a);
- }}});
- }, undeleteComment:function(a) {
- var b = $(a.currentTarget).closest("[data-comment-id]"), c = b.attr("data-comment-id"), d = this;
- $.ajax({url:"/site-api/comments/" + this.type + "/" + this.typeId + "/undel/", type:"POST", dataType:"html", data:JSON.stringify({id:c})}).done(function(a) {
- b.replaceWith(a);
- $("#comments-" + c).removeClass("removed");
- $("#comments-" + c).parents("li").removeClass("removed");
- _gaq.push(["_trackEvent", d.gaqType, "comment_undelete"]);
- });
- }, report:function(a) {
- var b = this;
- if (Scratch.INIT_DATA.ADMIN) {
- return b.submitReport(a);
- }
- var c = $(a.currentTarget).closest("[data-comment-id]").find("#comment-user").data("comment-user"), d = {Cancel:function() {
- $(this).dialog("close");
- }, Report:function() {
- $(this).dialog("close");
- b.submitReport(a);
- }};
- 0 <= b.student_usernames.indexOf(c) ? (this.educatorReportDialog = this.educatorReportDialog || $(Scratch.ALERT_MSGS.report_comment_educator), this.reportDialogElem = this.educatorReportDialog, d.Delete = d.Report, delete d.Report) : (this.reportDialog = this.reportDialog || $(Scratch.ALERT_MSGS.report_comment), this.reportDialogElem = this.reportDialog);
- this.reportDialogElem.dialog({buttons:d});
- }, submitReport:function(a) {
- var b = $(a.currentTarget).closest("[data-comment-id]");
- a = b.attr("data-comment-id");
- $.ajax({url:"/site-api/comments/" + this.type + "/" + this.typeId + "/rep/", type:"POST", dataType:"html", data:JSON.stringify({id:a})}).done(function(a) {
- b.replaceWith(a);
- _gaq.push(["_trackEvent", self.gaqType, "comment_report_add"]);
- });
- }, unreport:function(a) {
- var b = $(a.currentTarget).closest("[data-comment-id]"), c = b.attr("data-comment-id");
- a = $(a.currentTarget).data("report-id");
- var d = this;
- $.ajax({url:"/site-api/comments/" + this.type + "/" + this.typeId + "/unrep/", type:"POST", dataType:"html", data:JSON.stringify({id:c, rid:a})}).done(function(a) {
- b.replaceWith(a);
- _gaq.push(["_trackEvent", d.gaqType, "comment_report_remove"]);
- });
- }, scrollTo:function(a, b) {
- if (a || b) {
- var c = b || this.$(a);
- if (0 === c.length) {
- throw a + " is non-existent.";
- }
- var d = c.closest("li");
- d.addClass("highlighted");
- !c.is(":visible") && Scratch.INIT_DATA.ADMIN && $("#comments .removed").toggle();
- d.hasClass("truncated") && this.showMoreReplies({$elem:d, useAnimation:!1});
- d = $(window);
- var g = d.height();
- d = d.scrollTop();
- var e = d + g, f = c.outerHeight(!0);
- c = c.offset().top;
- g = c - g / 2 + f / 2;
- var h = g / 2;
- if (c < d || c + f > e) {
- return $("html,body").animate({scrollTop:g}, 1e3 < h ? 1e3 : h).promise();
- }
- }
- }, showMoreReplies:function(a) {
- function b() {
- e.first().prev().removeClass("lastvisible");
- e.removeClass("truncated");
- g.remove();
- c.callback && c.callback();
- }
- var c = a || {}, d, g;
- c.currentTarget ? (g = $(c.currentTarget), d = g.closest(".top-level-reply").find(".replies"), c.useAnimation = !0) : (d = c.$elem.closest(".top-level-reply").find(".replies"), g = d.next(".more-replies"));
- var e = d.find(".truncated");
- if (c.useAnimation) {
- g.slideUp("fast");
- var f = e.first().prev(".lastvisible");
- f.animate({height:f.children(":first").outerHeight()}, "fast");
- e.slideDown("fast").promise().always(function() {
- b();
- f.height("");
- });
- } else {
- b();
- }
- }, toggleComments:function(a) {
- var b = $(a.target), c = this.$(".comments-off"), d = this.$(".comments-on"), g = this.$('[data-content="reply-form"]'), e = this.$('.reply[data-control="reply-to"]'), f = b.is(":checked"), h = function() {
- c.show();
- d.hide();
- g.hide();
- e.hide();
- }, k = function() {
- c.hide();
- d.show();
- g.show();
- e.show();
- };
- f ? h() : k();
- $.post("/site-api/comments/" + this.type + "/" + this.typeId + "/toggle-comments/", {}).fail(function(a) {
- f ? (k(), b.removeAttr("checked")) : (h(), b.attr("checked", "checked"));
- });
- }});
- Scratch.ViewController = Backbone.View.extend({showView:function(a) {
- this.currentView && this.currentView.close();
- (this.currentView = a) && (this.currentView.render(), this.$el.html(this.currentView.el));
- }});
- Scratch.FollowButton = Backbone.View.extend({events:{'click [data-control="follow"]':"follow", 'click [data-control="unfollow"]':"unfollow"}, initialize:function(a) {
- _.bindAll(this, "followed");
- _.bindAll(this, "unfollowed");
- this.displayName = a.displayName;
- }, follow:function() {
- this.model.related.followers.addItems(Scratch.LoggedInUser.get("username"), {success:this.followed, error:this.onFollowError});
- }, followed:function(a, b) {
- this.$('[data-control="follow"]').removeClass("blue notfollowing").addClass("grey following").attr("data-control", "unfollow");
- Scratch.AlertView.msg($("#alert-view"), {alert:"success", msg:Scratch.ALERT_MSGS.followed + this.displayName});
- _gaq.push(["_trackEvent", "studio", "follow_add"]);
- }, onFollowError:function(a, b) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"error", msg:a.responseJSON[0].errors.join(",")});
- }, unfollow:function() {
- this.model.related.followers.removeItems(Scratch.LoggedInUser.get("username"), {success:this.unfollowed});
- }, unfollowed:function(a, b) {
- this.$('[data-control="unfollow"]').removeClass("grey following").addClass("blue notfollowing").attr("data-control", "follow");
- Scratch.AlertView.msg($("#alert-view"), {alert:"success", msg:Scratch.ALERT_MSGS.unfollowed + this.displayName});
- _gaq.push(["_trackEvent", "studio", "follow_remove"]);
- }});
- Scratch.EditableTextField = Backbone.View.extend({events:{"focusout textarea":"saveEditable", "focusout input":"saveEditable", click:"edit", "submit form":"preventFormSubmit"}, initialize:function(a, b) {
- _.bindAll(this, "success", "error", "saveEditable");
- this.$eField = this.$("input, textarea");
- this.eField = this.$eField[0];
- }, saveEditable:function(a) {
- if (this.eField.value != this.eField.defaultValue) {
- var b = {};
- b[this.eField.name] = this.eField.value;
- this.serverCall(b);
- "focusout" == a.type && this.$el.addClass("loading");
- this.eField.defaultValue = this.eField.value;
- }
- "focusout" == a.type && (clearInterval(this.saveInt), this.$el.removeClass("editable-empty").addClass("editable"), this.$el.addClass("read").removeClass("write"), this.eField.value || (this.$el.addClass("editable-empty").removeClass("editable"), this.$('[data-content="prompt"]').show()));
- }, serverCall:function(a) {
- this.model.save(a, {wait:!0, success:this.success, error:this.error});
- }, edit:function(a) {
- if (!this.$("form").length) {
- return this.undelegateEvents();
- }
- this.clearPrompt();
- this.$el.removeClass("read").addClass("write");
- this.$eField.focus();
- var b = this;
- clearInterval(this.saveInt);
- this.saveInt = setInterval(function() {
- b.saveEditable(a);
- }, 1e4);
- }, clearPrompt:function() {
- this.$('[data-content="prompt"]').hide();
- this.$eField.focus();
- }, preventFormSubmit:function(a) {
- a.preventDefault();
- this.saveEditable(a);
- }, success:function(a, b) {
- this.$el.removeClass("loading");
- if (b.errors) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"error", msg:Scratch.ALERT_MSGS[b.errors[0]], timer:1e4});
- } else {
- this.onEditSuccess();
- }
- }, onEditSuccess:function(a) {
- }, error:function(a, b, c) {
- throw "in Scratch.EditableTextField, error - responseText:" + b.responseText + " status:" + b.status;
- }});
- Scratch.EditableSelectField = Backbone.View.extend({events:{"change select":"saveEditable", "submit form":"preventFormSubmit"}, initialize:function(a, b) {
- _.bindAll(this, "success", "error", "saveEditable");
- this.$eField = this.$("select");
- this.eField = this.$eField[0];
- }, saveEditable:function(a) {
- a = {};
- a[this.eField.name] = this.$("select").val();
- this.serverCall(a);
- }, serverCall:function(a) {
- this.model.save(a, {wait:!0, success:this.success, error:this.error});
- }, preventFormSubmit:function(a) {
- a.preventDefault();
- this.saveEditable(a);
- }, success:function(a, b) {
- this.$el.removeClass("loading");
- if (b.isBad) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"error", msg:Scratch.ALERT_MSGS["inappropriate-generic"], timer:1e4});
- } else {
- this.onEditSuccess();
- }
- }, onEditSuccess:function(a) {
- }, error:function(a, b, c) {
- throw "in Scratch.EditableSelectField, error - responseText:" + b.responseText + " status:" + b.status;
- }});
- Scratch.EditableCheckboxField = Backbone.View.extend({events:{'click [type="checkbox"]':"saveEditable", "submit form":"preventFormSubmit"}, initialize:function(a, b) {
- _.bindAll(this, "success", "error", "saveEditable");
- this.$eField = this.$('input[type="checkbox"]');
- this.eField = this.$eField[0];
- }, saveEditable:function(a) {
- a = {};
- a[this.eField.name] = this.$eField.is(":checked") ? 1 : 0;
- this.serverCall(a);
- }, serverCall:function(a) {
- this.model.save(a, {wait:!0, success:this.success, error:this.error});
- }, preventFormSubmit:function(a) {
- a.preventDefault();
- this.saveEditable(a);
- }, success:function(a, b) {
- this.$el.removeClass("loading");
- if (b.isBad) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"error", msg:Scratch.ALERT_MSGS["inappropriate-generic"], timer:1e4});
- } else {
- this.onEditSuccess();
- }
- }, onEditSuccess:function(a) {
- }, error:function(a, b, c) {
- throw "in Scratch.EditableSelectField, error - responseText:" + b.responseText + " status:" + b.status;
- }});
- Scratch.EditableImage = Backbone.View.extend({events:{mouseover:"showEdit", mouseout:"hideEdit", 'change input[type="file"]':"submit"}, initialize:function() {
- _.bindAll(this, "imageUploadStart");
- _.bindAll(this, "imageUploadSuccess");
- this.$el.fileupload({url:this.model.url(), done:this.imageUploadSuccess, start:this.imageUploadStart, pasteZone:this.$el});
- }, showEdit:function(a) {
- this.$el.addClass("edit");
- }, hideEdit:function(a) {
- this.$el.removeClass("edit");
- }, imageUploadSuccess:function(a, b) {
- this.$el.removeClass("loading");
- if (b.result.error) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"error", msg:b.result.errors[0]});
- } else {
- if (b.result.errors) {
- Scratch.AlertView.msg($("#alert-view"), {alert:"error", msg:Scratch.ALERT_MSGS[b.result.errors[0]], timer:1e4});
- } else {
- var c = b.result.thumbnail_url + "#" + (new Date).getTime();
- this.$("img").attr("src", c);
- Scratch.AlertView.msg($("#alert-view"), {alert:"success", msg:"Thumbnail changed"});
- }
- }
- }, imageUploadStart:function() {
- this.$el.removeClass("edit");
- this.$el.addClass("loading");
- }, submit:function(a) {
- }});
- Scratch.UserThumbnail = Scratch.Model.extend({urlRoot:"/site-api/users/all/", slug:"username"});
- Scratch.UserThumbnailCollection = Scratch.Collection.extend({model:Scratch.UserThumbnail, urlRoot:"/site-api/users/", slug:"username", initialize:function(a, b) {
- this.options = this._meta = b;
- }, deleteItem:function(a, b) {
- this.remove(a);
- b.url = this.url() + "remove/" + this.url_params({usernames:a.get("fields").user.username});
- this.sync("update", a, b);
- }, addItem:function(a) {
- a.url = this.url() + "add/" + this.url_params({usernames:a.usernames});
- this.sync("update", new Scratch.UserThumbnail, a);
- }, meta:function(a, b) {
- if (void 0 === b) {
- return this._meta[a];
- }
- this._meta[a] = b;
- }});
- Scratch.LoggedInUserModel = Scratch.UserThumbnail.extend({authenticated:!1, admin:!1, loginUrl:"/login/", loginRetryUrl:"/login_retry/", currentLoginUrl:"/login/", initialize:function(a, b) {
- this.constructor.__super__.initialize.apply(this, [a, b]);
- this.authenticated = b.authenticated;
- }, login:function(a, b) {
- this.save(a, $.extend(b, {url:this.currentLoginUrl, wait:!0}));
- this.authenticated = !0;
- }, logout:function() {
- this.authenticated = !1;
- }});
- Scratch.ProjectThumbnail = Scratch.Model.extend({urlRoot:"/site-api/projects/all/"});
- Scratch.ProjectThumbnailCollection = Scratch.Collection.extend({model:Scratch.ProjectThumbnail, urlRoot:"/site-api/projects/", initialize:function(a, b) {
- _.bindAll(this, "added");
- _.bindAll(this, "deletedAll");
- this.options = this._meta = b;
- }, added:function(a, b) {
- this.fetch();
- }, deleteAll:function(a) {
- "trashed" == this._meta.collectionType && (a || (a = {}), _.extend(a, {url:this.url() + "empty/", success:this.deletedAll}), Backbone.sync("update", this, a));
- }, deletedAll:function(a, b) {
- this.fetch();
- }, meta:function(a, b) {
- if (void 0 === b) {
- return this._meta[a];
- }
- this._meta[a] = b;
- }});
- Scratch.GalleryThumbnail = Scratch.Model.extend({urlRoot:"/site-api/galleries/all/", deleteCurators:function(a, b) {
- b = b || {};
- b.url = "/site-api/users/curators/delete/?gallery_id=" + this.pk;
- this.sync("update", a, b);
- }, addCurators:function(a) {
- a = a || {};
- a.url = "/site-api/users/curators/add/?gallery_id=" + this.pk + "&usernames=" + a.usernames;
- this.sync("update", this, a);
- }, deleteProjects:function(a, b) {
- b = b || {};
- b.url = "/site-api/projects/in/?gallery_id=" + this.get("pk");
- this.sync("update", a, b);
- }, addProjects:function(a, b) {
- b = b || {};
- b.url = "/site-api/projects/in/?gallery_id" + this.get("pk");
- this.sync("update", a, b);
- }, follow:function(a) {
- options = options || {};
- options.url = "/site-api/users/bookmarkers/add/?gallery_id=" + this.get("pk");
- this.sync("update", this, options);
- }, unfollow:function(a) {
- a = a || {};
- a.url = "/site-api/users/bookmarkers/remove/?gallery_id=" + this.get("pk");
- this.sync("update", this, a);
- }});
- Scratch.GalleryThumbnailCollection = Scratch.Collection.extend({model:Scratch.GalleryThumbnail, urlRoot:"/site-api/galleries/", initialize:function(a, b) {
- this.options = this._meta = b;
- }, meta:function(a, b) {
- if (void 0 === b) {
- return this._meta[a];
- }
- this._meta[a] = b;
- }});
- Scratch.Comment = Scratch.Model.extend({urlRoot:"/site-api/comments/"});
- Scratch.CommentCollection = Scratch.Collection.extend({model:Scratch.Comment, urlRoot:"/site-api/comments/", initialize:function(a, b) {
- this.options = b;
- }, toggleDisabled:function() {
- }, addComment:function(a, b) {
- b = b || {};
- return b.url = this.url() + "add/?", b.data = JSON.stringify(a), Backbone.sync("create", this.parentModel, b);
- }, isCommentOkay:function(a) {
- }, report:function(a, b) {
- a || (a = {});
- var c = this.url() + "rep/";
- $.ajax(c, {type:"POST", data:JSON.stringify(a), dataType:"json", success:b});
- }, unreport:function(a, b) {
- a || (a = {});
- var c = this.url() + "unrep/";
- $.ajax(c, {type:"POST", data:JSON.stringify(a), dataType:"json", success:b});
- }});
- (function(a) {
- a.fn.scratchIncrementCount = function(a) {
- var b = parseInt(this.html(), 10);
- this.html(b + a);
- };
- a.withCSRF = function(b) {
- a.get("/csrf_token/", function(a, d, g) {
- csrf = ("; " + document.cookie).split("; scratchcsrftoken=")[1].split(";")[0];
- b(csrf);
- });
- };
- })(jQuery);
- $.ajaxSetup({jsonp:!1});
- $(document).ajaxSend(function(a, b, c) {
- function d(a) {
- var b = null;
- if (document.cookie && "" != document.cookie) {
- for (var c = document.cookie.split(";"), d = 0; d < c.length; d++) {
- var e = jQuery.trim(c[d]);
- if (e.substring(0, a.length + 1) == a + "=") {
- b = decodeURIComponent(e.substring(a.length + 1));
- break;
- }
- }
- }
- return b;
- }
- function g(a) {
- var b = "//" + document.location.host, c = document.location.protocol + b;
- return a == c || a.slice(0, c.length + 1) == c + "/" || a == b || a.slice(0, b.length + 1) == b + "/" || !/^(\/\/|http:|https:).*/.test(a);
- }
- !/^(GET|HEAD|OPTIONS|TRACE)$/.test(c.type) && g(c.url) && b.setRequestHeader("X-CSRFToken", d("scratchcsrftoken"));
- });
- $(document).ajaxError(function(a, b, c, d) {
- if (void 0 === c.error) {
- if ("" === location.port) {
- throw "Uncaught ajax error. Attempted URL: " + c.url + " Status: " + b.status;
- }
- 0 === b.status && (c.success(c.fakeResponseForDevPortAjaxFail, b.status, b), console.error("Status 0 ajax bug. Calling success(options.fakeResponseForDevPortAjaxFail, xhr.status, xhr)"));
- }
- });
- $(document).on("click", ".dropdown.select ul li", function() {
- var a = $(this).text(), b = $(this).closest(".dropdown"), c = b.find(".selected");
- b.find("li.hide").removeClass("hide");
- $(this).addClass("hide");
- c.text(a);
- });
- $(document).on("click", ".dropdown.radio-style ul li", function() {
- $(this).closest(".dropdown").find(".selected").removeClass("selected");
- $(this).addClass("selected");
- });
- $.urlParam = function(a) {
- return -1 == window.location.search.indexOf(a) ? null : (new RegExp("[\\?&]" + a + "=([^&#]*)")).exec(window.location.href)[1] || 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement