D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
psa
/
admin
/
htdocs
/
modules
/
xovi
/
js
/
Filename :
wizard.js
back
Copy
(function ($) { var SeoWizard = { currentStep: 1, settings: { addKeyword: null, addCompetitor: null, addItem: null, baseUrl: null, senginesUrl: null, stepsUrl: null }, sengines: { "hosts": { ".4f646e02": "google.com (Worldwide)" } }, sengineHost: ".4f646e02", gotoStep: function (step) { SeoWizard.loaderStart(); var pData = $('form#wizard-form').serializeArray(); pData.push({ 'name': 'step', 'value': step }); if (step === 5) { pData.push({ 'name': 'competitors_exist', 'value': $('#competitors_tagsinput span.readonlyTag').length }); } $.ajax({ type: 'POST', cache: false, url: SeoWizard.settings.stepsUrl, data: pData, dataType: 'json', success: function (data) { if (typeof data === "object") { if (typeof data['redirect'] === "string") { $(location).attr('href', data['redirect']); } else { SeoWizard.setStepData(step, data); } } else { SeoWizard.stepError(); } SeoWizard.loaderStop(); }, error: function () { SeoWizard.stepError(); SeoWizard.loaderStop(); } }); }, showStep: function (step) { $('.steps').hide(); $('.step' + step).show(); $('.log-bar-progress').removeClass('active').removeClass('done'); $('#barStep' + step).addClass('active'); $('.doneOn' + step).addClass('done'); $('.input-select').chosen("destroy").chosen(); }, loaderStart: function () { $('.stepWizard,.skipWizard').hide(); $('.loader').show(); }, loaderStop: function () { $('.stepWizard,.skipWizard').show(); $('.loader').hide(); SeoWizard.showStep(SeoWizard.currentStep); }, stepError: function (message) { console.log('stepError', message); location.reload(); }, setStepData: function (step, data) { $('.step' + step + ' .statusMessages').html(''); $.each(data['statuses'], function (tool, messages) { $.each(messages, function (i, message) { SeoWizard.addMessage(tool, message); }); }); switch (step) { case 2: $('.step2 .caption-head-wrap h2').html( $('.step2 .caption-head-wrap h2').html().replace(/"[^"]*"/gi, '"<b>' + data['domain'] + '</b>"') ); // set new SeoWizard.sengineHost for the next step var seRegex = new RegExp(data['seo']['sengine'].replace(/\./g, '\\.'), "i"); $.each(SeoWizard.sengines['hosts'], function (i, v) { if (v.match(seRegex) !== null) { SeoWizard.sengineHost = i; return false; } }); break; case 3: if (data['subdomains'] !== undefined) { $.each(data['subdomains'], function (key, value) { $('#subdomain') .append($("<option></option>") .attr("value", key) .text(value)); }); } // set keyword suggestions $('#suggested-keywords').html(''); $.setFormData({ 'suggestionUrl': data['suggestionUrl'], }, [ 'keywords' ], { 'available': data['availableKeys']['available'], 'total': data['availableKeys']['total'] } ); // set search engine SeoWizard.loaderStop(); $('.wizard #host').chosen("destroy").val(SeoWizard.sengineHost).chosen(); // hide keywordProposal if empty if ($('#suggested-keywords').html().length < 3) { $('#suggested-keywords').parents('.stepInfos').hide(); } else { $('#suggested-keywords').parents('.stepInfos').show(); } break; case 4: // set competitor suggestions $('#suggested-competitors').html(''); $.setFormData({ 'suggestionUrl': data['suggestionUrl'], 'competitorAllow': data['competitorAllow'], }, [ 'competitors' ], null ); // hide keywordProposal if empty SeoWizard.loaderStop(); if ($('#suggested-competitors').html().length < 3) { $('#suggested-competitors').parents('.stepInfos').hide(); } else { $('#suggested-competitors').parents('.stepInfos').show(); } break; case 5: $('a.wizDomainLink').each(function () { $(this).attr('href', $(this).attr('data-href') + '/id/' + data['domainId']); }); break; } }, addMessage: function (tool, message) { var html = '<div class="row pul-status pul-status--' + message['type'] + '">\n' + ' <div class="col-xs-1 end-xs">\n' + ' <span class="pul-icon pul-icon--size-16 pul-action__icon"><svg focusable="false"><use xlink:href="/javascript/externals/plesk-ui-library/images/symbols.svg#' + (message['type'] === 'success' ? 'circle-check-mark-filled' : 'circle-exclamation-mark-filled') + '"></use></svg></span>\n' + ' </div>\n' + ' <div class="col-xs-11 start-xs">' + message['text'] + '</div>\n' + '</div>'; $('.statusMessages[data-tool="' + tool + '"]').append(html); } }; /** * Init SEO wizard * * @param settings Object {addKeyword: null, addCompetitor: null, addItem: null, senginesUrl: null, stepsUrl: null} * @param skipFirstStep Boolean * @returns SeoWizard Object */ $.seoWizard = function (settings, skipFirstStep) { SeoWizard.settings = settings; // init tagsInput $.setInputSettings( { "keywords": { "defaultText": SeoWizard.settings.addKeyword }, "competitors": { "defaultText": SeoWizard.settings.addCompetitor } } ); // load search engines $.getJSON(SeoWizard.settings.senginesUrl, function (json) { if (typeof json === "object" && json !== null && typeof json['hosts'] === "object" && json['hosts'] !== null) { SeoWizard.sengines = json; } var seHostsOptions = ''; $.each(SeoWizard.sengines['hosts'], function (i, v) { if (SeoWizard.sengines['countries'][i] !== undefined) { seHostsOptions += '<option data-img-src="' + SeoWizard.settings.baseUrl + 'images/flags/' + SeoWizard.sengines['countries'][i] + '.png" value="' + i + '">' + v + '</option>'; } else { seHostsOptions += '<option value="' + i + '">' + v + '</option>'; } }); $('.wizard #host').chosen("destroy").html(seHostsOptions).val(SeoWizard.sengineHost).chosen(); }); // set button events $('.skipWizard a').click(function () { SeoWizard.currentStep = 5; SeoWizard.gotoStep(SeoWizard.currentStep); return false; }); $('.stepWizard button').click(function () { var direction = parseInt($(this).val()); SeoWizard.currentStep += direction; SeoWizard.currentStep = (SeoWizard.currentStep < 1 ? 1 : (SeoWizard.currentStep > 5 ? 5 : SeoWizard.currentStep)); if (direction < 0) { // step back SeoWizard.showStep(SeoWizard.currentStep); } else { // next step SeoWizard.gotoStep(SeoWizard.currentStep); } return false; }); $('#nextWizard button').click(function () { $(this).parents('p:first').hide(); $('.loader').show(); location.href = SeoWizard.settings.wizardUrl + '/id/' + $('#domainFinal').val(); return false; }); SeoWizard.showStep(1); if (skipFirstStep) { $(".step1 .stepWizard button").click(); } return SeoWizard; } })(jQuery);