From 35ec3b0f1cdad8d2e8f7591f004be7697e1c810a Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 31 Mar 2024 22:57:04 +0000 Subject: [PATCH] Update content of files --- data/web/fragment.com/js/auction.js | 206 ++++++++++++++++++++-------- 1 file changed, 147 insertions(+), 59 deletions(-) diff --git a/data/web/fragment.com/js/auction.js b/data/web/fragment.com/js/auction.js index 7d045eaa66..389566ebb1 100644 --- a/data/web/fragment.com/js/auction.js +++ b/data/web/fragment.com/js/auction.js @@ -237,26 +237,6 @@ var Main = { e.preventDefault(); closePopup(Aj.state.$headerMenu); }, - openSimplePopup: function($popup) { - var onEnterPress = function(e) { - if (e.keyCode == Keys.RETURN) { - e.stopImmediatePropagation(); - closePopup($popup); - } - }; - var onClose = function(e) { - e.stopImmediatePropagation(); - closePopup($popup); - }; - openPopup($popup, { - onOpen: function() { - $(document).on('keydown', onEnterPress); - }, - onClose: function() { - $(document).off('keydown', onEnterPress); - } - }); - }, eAuctionUnavailable: function(e) { e.preventDefault(); var username = $(this).attr('data-username'); @@ -282,17 +262,56 @@ var Main = { eHowitworks: function(e) { e.preventDefault(); e.stopImmediatePropagation(); - Main.openSimplePopup(Aj.state.$howitworksPopup); + var onEnterPress = function(e) { + if (e.keyCode == Keys.RETURN) { + e.stopImmediatePropagation(); + closePopup(Aj.state.$howitworksPopup); + } + }; + openPopup(Aj.state.$howitworksPopup, { + onOpen: function() { + $(document).on('keydown', onEnterPress); + }, + onClose: function() { + $(document).off('keydown', onEnterPress); + } + }); }, eHowofferworks: function(e) { e.preventDefault(); e.stopImmediatePropagation(); - Main.openSimplePopup(Aj.state.$howofferworksPopup); + var onEnterPress = function(e) { + if (e.keyCode == Keys.RETURN) { + e.stopImmediatePropagation(); + closePopup(Aj.state.$howofferworksPopup); + } + }; + openPopup(Aj.state.$howofferworksPopup, { + onOpen: function() { + $(document).on('keydown', onEnterPress); + }, + onClose: function() { + $(document).off('keydown', onEnterPress); + } + }); }, eBotsAbout: function(e) { e.preventDefault(); e.stopImmediatePropagation(); - Main.openSimplePopup(Aj.state.$botsaboutPopup); + var onEnterPress = function(e) { + if (e.keyCode == Keys.RETURN) { + e.stopImmediatePropagation(); + closePopup(Aj.state.$botsaboutPopup); + } + }; + openPopup(Aj.state.$botsaboutPopup, { + onOpen: function() { + $(document).on('keydown', onEnterPress); + }, + onClose: function() { + $(document).off('keydown', onEnterPress); + } + }); }, amountFieldValue: function($form, field) { var $fieldEl = field ? $form.field(field) : $form; @@ -665,14 +684,9 @@ var Wallet = { sendTransaction: function(options) { if (Aj.globalState.tonConnectVersion == 2) { var tonConnectUI = Aj.globalState.tonConnectUI; - var sendTransaction = function(data) { - var transaction = data.transaction; + var sendTransaction = function(transaction) { tonConnectUI.sendTransaction(transaction).then(function(transaction) { options.onConfirm && options.onConfirm(true); - if (data.confirm_method) { - var params = $.extend({boc: transaction.boc}, data.confirm_params); - Aj.apiRequest(data.confirm_method, params); - } }).catch(function(){}); }; if (!tonConnectUI.connected) { @@ -683,10 +697,10 @@ var Wallet = { if (result.error) { return showAlert(result.error); } - sendTransaction(result); + sendTransaction(result.transaction); }); } else if (options.transaction) { - sendTransaction(options); + sendTransaction(options.transaction); } } else { QR.showPopup(options); @@ -2378,17 +2392,15 @@ var Ads = { init: function() { Aj.onLoad(function(state) { var cont = Aj.ajContainer; - $(cont).on('click.curPage', '.js-pay-for-ads', Ads.ePayForAds); - $(cont).on('click.curPage', '.js-howtopay-ton', Ads.eHowToPayTon); - $(cont).on('click.curPage', '.js-get-ad-rewards', Ads.eGetAdRewards); - state.$payForAdsPopup = $('.js-pay-for-ads-popup'); - state.$howToPayTonPopup = $('.js-how-to-pay-ton-popup'); - state.$howToGetRewardsPopup = $('.js-how-to-get-rewards-popup'); - $(cont).on('click.curPage', '.js-more-funds-btn', Ads.eAddMoreFunds); $(cont).on('click.curPage', '.js-recharge-btn', Ads.eRechargeAccount); state.$rechargeForm = $('.js-recharge-form', cont); + state.$searchField = $('.js-account-search-field', cont); Main.initForm(state.$rechargeForm); + state.$rechargeForm.on('submit', Ads.eSearchSubmit); + state.$rechargeForm.field('query').on('input', Ads.eSearchInput); + state.$rechargeForm.field('query').on('change', Ads.eSearchChange); + $('.js-form-clear', state.$rechargeForm).on('click', Ads.eSearchClear); state.$rechargeBtn = $('.js-recharge-btn', cont); state.updLastReq = +Date.now(); if (state.needUpdate) { @@ -2398,24 +2410,13 @@ var Ads = { Aj.onUnload(function(state) { clearTimeout(state.updStateTo); state.needUpdate = false; - Main.destroyForm(state.$rechargeForm); + Main.destroyForm(state.$giftPremiumForm); + state.$rechargeForm.off('submit', Ads.eSearchSubmit); + state.$rechargeForm.field('query').off('input', Ads.eSearchInput); + state.$rechargeForm.field('query').off('change', Ads.eSearchChange); + $('.js-form-clear', state.$rechargeForm).off('click', Ads.eSearchClear); }); }, - ePayForAds: function(e) { - e.preventDefault(); - e.stopImmediatePropagation(); - Main.openSimplePopup(Aj.state.$payForAdsPopup); - }, - eHowToPayTon: function(e) { - e.preventDefault(); - e.stopImmediatePropagation(); - Main.openSimplePopup(Aj.state.$howToPayTonPopup); - }, - eGetAdRewards: function(e) { - e.preventDefault(); - e.stopImmediatePropagation(); - Main.openSimplePopup(Aj.state.$howToGetRewardsPopup); - }, updateState: function() { var now = +Date.now(); if (document.hasFocus() || @@ -2450,6 +2451,97 @@ var Ads = { } } }, + eSearchInput: function(e) { + var $field = Aj.state.$searchField; + $('.js-search-field-error').html(''); + $field.removeClass('error'); + }, + eSearchChange: function(e) { + Ads.searchSubmit(); + }, + eSearchClear: function(e) { + var $form = Aj.state.$rechargeForm; + var $field = Aj.state.$searchField; + var $btn = Aj.state.$rechargeBtn; + $form.field('account').value(''); + $form.field('query').value('').prop('disabled', false); + $btn.prop('disabled', true); + $field.removeClass('found'); + $('.js-search-field-error').html(''); + $field.removeClass('error'); + Ads.updateUrl(); + $form.field('query').focus(); + }, + eSearchSubmit: function(e) { + e.preventDefault(); + Ads.searchSubmit(); + }, + searchSubmit: function() { + var $form = Aj.state.$rechargeForm; + var account = $form.field('account').value(); + var query = $form.field('query').value(); + if (!query.length) { + $form.field('query').focus(); + return; + } + Aj.state.$searchField.addClass('loading').removeClass('play').redraw().addClass('play'); + Aj.showProgress(); + Aj.apiRequest('searchAdsAccount', { + query: account || query + }, function(result) { + Aj.hideProgress(); + Ads.updateResult(result); + Aj.state.$searchField.removeClass('loading'); + }); + }, + updateResult: function(result) { + var $form = Aj.state.$rechargeForm; + var $field = Aj.state.$searchField; + var $btn = Aj.state.$rechargeBtn; + if (result.error) { + $('.js-search-field-error').html(result.error); + $field.addClass('error').removeClass('found'); + $form.field('query').prop('disabled', false); + } else { + $('.js-search-field-error').html(''); + $field.removeClass('error'); + if (result.found) { + if (result.found.photo) { + $('.js-account-search-photo', $field).html(result.found.photo); + } + if (result.found.name) { + var $form = Aj.state.$rechargeForm; + $form.field('query').value(uncleanHTML(result.found.name)); + } + $form.field('account').value(result.found.account); + $field.addClass('found'); + $form.field('query').prop('disabled', true); + $btn.prop('disabled', false); + } else { + $form.field('account').value(''); + $field.removeClass('found'); + $form.field('query').prop('disabled', false); + $btn.prop('disabled', true); + } + } + Ads.updateUrl(); + }, + updateUrl: function() { + var new_url = ''; + var $form = Aj.state.$rechargeForm; + var account = $form.field('account').value(); + if (account) { + new_url += '&account=' + encodeURIComponent(account); + } + if (new_url) { + new_url = '?' + new_url.substr(1); + } + var loc = Aj.location(), path = loc.pathname + loc.search; + if (!new_url) { + new_url = loc.pathname; + } + Aj.setLocation(new_url, path != '/ads'); + }, updateHistory: function(html) { $('.js-premium-history').replaceWith(html); }, @@ -2500,11 +2592,7 @@ var Ads = { if (result.error) { return showAlert(result.error); } - if (result.redirect_to) { - Aj.reload(); - } else { - - } + Aj.location('/ads'); }); } };