Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +function($) {
- $(function() {
- var invites = function() {
- /**
- * @param {Object} element
- * @return {undefined}
- */
- function init(element) {
- var list = element.find(".invite-card .card-info .hint time");
- /** @type {number} */
- var y = Date.now();
- /** @type {number} */
- var resolution = 1E3;
- /** @type {number} */
- var total = 60;
- /** @type {number} */
- var max = 60 * total;
- /** @type {number} */
- var base = 24 * max;
- /** @type {number} */
- var i = 0;
- for (;i < list.length;i++) {
- var x = list.eq(i).attr("data-time");
- if ("undefined" != typeof x) {
- x -= 0;
- /** @type {number} */
- list[i].targetTime = parseInt(x + y / resolution);
- clearInterval(list[i].counting);
- (function(pos) {
- /** @type {number} */
- list[pos].counting = setInterval(function() {
- /** @type {number} */
- var n = parseInt(list[pos].targetTime - Date.now() / resolution);
- /** @type {number} */
- n = 0 >= n ? 0 : n;
- /** @type {number} */
- var str = n % total;
- n -= str;
- /** @type {string} */
- str = ("00" + str).substr(-2) + "s";
- /** @type {number} */
- var m = parseInt(n % max / total);
- n -= m;
- /** @type {string} */
- m = ("00" + m).substr(-2) + "m ";
- /** @type {number} */
- var num = parseInt(n % base / max);
- n -= num;
- /** @type {string} */
- num = ("00" + num).substr(-2) + "h ";
- /** @type {number} */
- var y = parseInt(n / base);
- /** @type {string} */
- y = ("00" + y).substr(-2) + "d ";
- list.eq(pos).text(y + num + m + str);
- }, 300);
- })(i);
- }
- }
- }
- var element = $(document).find(".my-invites, .share-invites, .invites, .js-off-canvas-invites");
- element.find(".invite-card .card-action .share-it");
- return init(element), $(document).on("click", ".invite-card .card-action .share-it", function(event) {
- event.preventDefault();
- event.stopPropagation();
- var submit = $(this);
- var record = submit.parents(".invite-card");
- var compiled = record.clone();
- compiled.find(".card").removeClass("has-action").find(".card-action").remove();
- element.find(".misc .invite-card-placeholder").html(compiled);
- element.find(".misc").show();
- }), element.find(".misc .attach-msg").on("click", function(types) {
- types.preventDefault();
- $(this).hide();
- $("#attachedMsg").parents(".form-group").eq(0).removeClass("hidden");
- }), element.find(".misc button[type=reset]").on("click", function() {
- element.find(".misc .attach-msg").show();
- $("#attachedMsg").parents(".form-group").eq(0).addClass("hidden");
- element.find(".misc").hide();
- }), element.on("inputValidated.oneplus", ".js-try-again", function() {
- var href = ($(this), $("#invite_section_one").val() + "-" + $("#invite_section_two").val() + "-" + $("#invite_section_three").val() + "-" + $("#invite_section_four").val());
- /** @type {string} */
- var nameAnchor = window.location.href;
- /** @type {string} */
- window.location.href = nameAnchor.split("/claim")[0] + "/claim/" + href;
- }), element.on("paste", "#invite_section_one", function(dataAndEvents) {
- var $target = $(this);
- $target.attr("maxlength", 1E3);
- setTimeout(function() {
- var parts = $target.val();
- parts = parts.split("-");
- $target.val("");
- $("#invite_section_one").val(parts[0] ? parts[0].substr(0, 4) : "");
- $("#invite_section_two").val(parts[1] ? parts[1].substr(0, 4) : "");
- $("#invite_section_three").val(parts[2] ? parts[2].substr(0, 4) : "");
- $("#invite_section_four").val(parts[3] ? parts[3].substr(0, 4) : "").focus();
- $target.attr("maxlength", 4);
- }, 0);
- $target.parents("form").find(".form-control").removeClass("invalid");
- }), element.on("input", ".claim-invite input", function(dataAndEvents) {
- var $target = $(this);
- if ($target.val().length >= 4) {
- var set = $target.parents(".claim-invite").find(":input");
- var inputEl = set.eq(set.index(this) + 1);
- inputEl.val("");
- inputEl.focus();
- }
- }), element.on("keydown", ".claim-invite input", function(event) {
- var $target = $(this);
- if ($target.val().length <= 0 && 8 === event.keyCode) {
- var set = $target.parents(".claim-invite").find(":input");
- var submenu = set.eq(set.index(this) - 1);
- event.preventDefault();
- submenu.focus();
- }
- }), element.on("inputValidated.oneplus", ".js-send-code", function(dataAndEvents) {
- var invite = ($(this), $("#invite_section_one").val() + "-" + $("#invite_section_two").val() + "-" + $("#invite_section_three").val() + "-" + $("#invite_section_four").val());
- if (modules) {
- if (modules.misc) {
- if (modules.misc.load) {
- modules.misc.load.start();
- }
- }
- }
- $.ajax({
- type : "GET",
- url : ONEPLUS_NET.REQUEST.CLAIM_INVITE,
- data : {
- invite : invite
- },
- dataType : "json",
- /**
- * @param {?} data
- * @return {undefined}
- */
- success : function(data) {
- if (modules) {
- if (modules.misc) {
- if (modules.misc.load) {
- modules.misc.load.finish();
- }
- }
- }
- if (0 === data.ret) {
- window.location.reload();
- } else {
- if (modules.misc) {
- if (modules.misc.dialog) {
- modules.misc.dialog.show(data.errMsg);
- }
- }
- }
- },
- timeout : 3E4,
- /**
- * @param {?} textStatus
- * @param {?} jqXHR
- * @param {?} origError
- * @return {undefined}
- */
- error : function(textStatus, jqXHR, origError) {
- if (modules) {
- if (modules.misc) {
- if (modules.misc.load) {
- modules.misc.load.finish();
- }
- }
- }
- }
- });
- }), element.on("inputValidated.oneplus", ".js-btn-register-for-invite", function(dataAndEvents) {
- var $target = $(this);
- if (modules) {
- if (modules.misc) {
- if (modules.misc.load) {
- modules.misc.load.start();
- }
- }
- }
- $.ajax({
- type : "POST",
- url : ONEPLUS_NET.REQUEST.CLAIM_INVITE,
- data : {
- email : $target.parents("form").find("[name=email]").val()
- },
- dataType : "jsonp",
- jsonp : "jsonp",
- /**
- * @param {?} data
- * @return {undefined}
- */
- success : function(data) {
- if (modules) {
- if (modules.misc) {
- if (modules.misc.load) {
- modules.misc.load.finish();
- }
- }
- }
- if (0 === data.ret) {
- $target.addClass("has-feedback");
- etTimeout(function() {
- $target.removeClass("has-feedback");
- }, 2E3);
- } else {
- if (modules.misc) {
- if (modules.misc.dialog) {
- modules.misc.dialog.show(data.errMsg);
- }
- }
- }
- },
- timeout : 3E4,
- /**
- * @param {?} textStatus
- * @param {?} jqXHR
- * @param {?} origError
- * @return {undefined}
- */
- error : function(textStatus, jqXHR, origError) {
- if (modules) {
- if (modules.misc) {
- if (modules.misc.load) {
- modules.misc.load.finish();
- }
- }
- }
- }
- });
- }), element.on("inputValidated.oneplus", ".js-share-via-email", function(dataAndEvents) {
- var $target = $(this);
- if (modules) {
- if (modules.misc) {
- if (modules.misc.load) {
- modules.misc.load.start();
- }
- }
- }
- $.ajax({
- type : "GET",
- url : ONEPLUS_NET.REQUEST.SHARE_VIA_EMAIL,
- data : {
- invite : $target.parents("form").find(".invite-card .invite-code").text().replace(/ /g, "-"),
- email : $("#shareEmail").val(),
- message : $("#attachedMsg").val()
- },
- dataType : "json",
- /**
- * @param {?} data
- * @return {undefined}
- */
- success : function(data) {
- if (modules) {
- if (modules.misc) {
- if (modules.misc.load) {
- modules.misc.load.finish();
- }
- }
- }
- if (0 === data.ret) {
- $target.addClass("has-feedback");
- setTimeout(function() {
- $target.removeClass("has-feedback");
- }, 2E3);
- } else {
- if (modules.misc) {
- if (modules.misc.dialog) {
- modules.misc.dialog.show(data.errMsg);
- }
- }
- }
- },
- timeout : 3E4,
- /**
- * @param {?} textStatus
- * @param {?} jqXHR
- * @param {?} origError
- * @return {undefined}
- */
- error : function(textStatus, jqXHR, origError) {
- if (modules) {
- if (modules.misc) {
- if (modules.misc.load) {
- modules.misc.load.finish();
- }
- }
- }
- }
- });
- }), {
- AUTHOR : "Michael",
- VERSION : "1.0.0",
- LAST_MODIFIED : "2015-07-16",
- $element : element,
- /** @type {function (Object): undefined} */
- countingDown : init
- };
- }();
- window.modules = window.modules || {};
- window.modules.invites = invites;
- });
- }(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment