| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- jQuery(document).ready(function($){
- jQuery('.ta-import-content').on('click', function(e){
- jQuery('#importer-response').children('.res-text').html('');
- jQuery('#importer-response').children('.res-text').html('Processing content...');
- jQuery('#importer-response').find('.loadinerSearch').show();
- jQuery.ajax({
- type : "post",
- url : envato_setup_params.ajaxurl,
- data : {
- action:'setup_content',
- data:'1',
- },
- success: function(response) {
- if(response){
- jQuery('#importer-response').children('.res-text').html(response);
- jQuery('#importer-response').find('.loadinerSearch').hide();
- jQuery('#importer-response').find('.checkImg').show();
- jQuery('#importer-response-menu').children('.res-text').html('');
- jQuery('#importer-response-menu').children('.res-text').html('Creating menu...');
- jQuery('#importer-response-menu').find('.loadinerSearch').show();
- /* adding menus */
- jQuery.ajax({
- type : "post",
- url : envato_setup_params.ajaxurl,
- data : {
- action:'taskereasy_menu',
- data:'1',
- },
- success: function(responseMen) {
- if(responseMen){
- jQuery('#importer-response-menu').children('.res-text').html(responseMen);
- jQuery('#importer-response-menu').find('.loadinerSearch').hide();
- jQuery('#importer-response-menu').find('.checkImg').show();
- jQuery('#importer-response-homepage').children('.res-text').html('');
- jQuery('#importer-response-homepage').children('.res-text').html('Adding Homepage...');
- jQuery('#importer-response-homepage').find('.loadinerSearch').show();
- /* adding homepage */
- jQuery.ajax({
- type : "post",
- url : envato_setup_params.ajaxurl,
- data : {
- action:'taskereasy_homepage',
- data:'1',
- },
- success: function(responseMen) {
- if(responseMen){
- jQuery('#importer-response-homepage').children('.res-text').html(responseMen);
- jQuery('#importer-response-homepage').find('.loadinerSearch').hide();
- jQuery('#importer-response-homepage').find('.checkImg').show();
- jQuery('#importer-response-themeoptions').children('.res-text').html('');
- jQuery('#importer-response-themeoptions').children('.res-text').html('Theme Options...');
- jQuery('#importer-response-themeoptions').find('.loadinerSearch').show();
- jQuery.ajax({
- type : "post",
- url : envato_setup_params.ajaxurl,
- data : {
- action:'taskereasy_theme_options',
- data:'1',
- },
- success: function(responseMen) {
- if(responseMen){
- jQuery('#importer-response-themeoptions').html(responseMen);
- jQuery('#importer-response-themeoptions').find('.loadinerSearch').hide();
- jQuery('#importer-response-themeoptions').find('.checkImg').show();
- jQuery( ".button-next-skip" )[0].click();
- }
- }
- });
- }
- }
- });
- }
- }
- });
- }
- }
- });
- return false;
- });
- });
- var EnvatoWizard = (function($){
- var t;
- // callbacks from form button clicks.
- var callbacks = {
- install_plugins: function(btn){
- var plugins = new PluginManager();
- plugins.init(btn);
- },
- install_content: function(btn){
- var content = new ContentManager();
- content.init(btn);
- }
- };
- function window_loaded(){
- // init button clicks:
- $('.button-next').on( 'click', function(e) {
- var loading_button = dtbaker_loading_button(this);
- if(!loading_button){
- return false;
- }
- if($(this).data('callback') && typeof callbacks[$(this).data('callback')] != 'undefined'){
- // we have to process a callback before continue with form submission
- callbacks[$(this).data('callback')](this);
- return false;
- }else{
- loading_content();
- return true;
- }
- });
- $('.button-upload').on( 'click', function(e) {
- e.preventDefault();
- renderMediaUploader();
- });
- $('.ta-imp-demo .ta-select-demo-image').on( 'click', function() {
- $('.ta-imp-demo').removeClass('current');
- $(this).parents().addClass('current');
- var newcolor = $(this).find('a').data('style');
- $('#new_style').val(newcolor);
- return false;
- });
- }
- function loading_content(){
- $('.envato-setup-content').block({
- message: null,
- overlayCSS: {
- background: '#fff',
- opacity: 0.6
- }
- });
- }
- function PluginManager(){
- var complete;
- var items_completed = 0;
- var current_item = '';
- var $current_node;
- var current_item_hash = '';
- function ajax_callback(response){
- if(typeof response == 'object' && typeof response.message != 'undefined'){
- $current_node.find('span').text(response.message);
- if(typeof response.url != 'undefined'){
- // we have an ajax url action to perform.
- if(response.hash == current_item_hash){
- $current_node.find('span').text("failed");
- find_next();
- }else {
- current_item_hash = response.hash;
- jQuery.post(response.url, response, function(response2) {
- process_current();
- $current_node.find('span').text(response.message + envato_setup_params.verify_text);
- }).fail(ajax_callback);
- }
- }else if(typeof response.done != 'undefined'){
- // finished processing this plugin, move onto next
- find_next();
- }else{
- // error processing this plugin
- find_next();
- }
- }else{
- // error - try again with next plugin
- $current_node.find('span').text("Success");
- find_next();
- }
- }
- function process_current(){
- if(current_item){
- // query our ajax handler to get the ajax to send to TGM
- // if we don't get a reply we can assume everything worked and continue onto the next one.
- jQuery.post(envato_setup_params.ajaxurl, {
- action: 'envato_setup_plugins',
- wpnonce: envato_setup_params.wpnonce,
- slug: current_item
- }, ajax_callback).fail(ajax_callback);
- }
- }
- function find_next(){
- var do_next = false;
- if($current_node){
- if(!$current_node.data('done_item')){
- items_completed++;
- $current_node.data('done_item',1);
- }
- $current_node.find('.spinner').css('visibility','hidden');
- }
- var $li = $('.envato-wizard-plugins li');
- $li.each(function(){
- if(current_item == '' || do_next){
- current_item = $(this).data('slug');
- $current_node = $(this);
- process_current();
- do_next = false;
- }else if($(this).data('slug') == current_item){
- do_next = true;
- }
- });
- if(items_completed >= $li.length){
- // finished all plugins!
- complete();
- }
- }
- return {
- init: function(btn){
- $('.envato-wizard-plugins').addClass('installing');
- complete = function(){
- loading_content();
- window.location.href=btn.href;
- };
- find_next();
- }
- }
- }
- function ContentManager(){
- var complete;
- var items_completed = 0;
- var current_item = '';
- var $current_node;
- var current_item_hash = '';
- function ajax_callback(response) {
- if(typeof response == 'object' && typeof response.message != 'undefined'){
- $current_node.find('span').text(response.message);
- if(typeof response.url != 'undefined'){
- // we have an ajax url action to perform.
- if(response.hash == current_item_hash){
- $current_node.find('span').text("failed");
- find_next();
- }else {
- current_item_hash = response.hash;
- jQuery.post(response.url, response, ajax_callback).fail(ajax_callback); // recuurrssionnnnn
- }
- }else if(typeof response.done != 'undefined'){
- // finished processing this plugin, move onto next
- find_next();
- }else{
- // error processing this plugin
- find_next();
- }
- }else{
- // error - try again with next plugin
- $current_node.find('span').text("Success");
- find_next();
- }
- }
- function process_current(){
- if(current_item){
- var $check = $current_node.find('input:checkbox');
- if($check.is(':checked')) {
- console.log("Doing 2 "+current_item);
- // process htis one!
- jQuery.post(envato_setup_params.ajaxurl, {
- action: 'envato_setup_content',
- wpnonce: envato_setup_params.wpnonce,
- content: current_item
- }, ajax_callback).fail(ajax_callback);
- }else{
- $current_node.find('span').text("Skipping");
- setTimeout(find_next,300);
- }
- }
- }
- function find_next(){
- var do_next = false;
- if($current_node){
- if(!$current_node.data('done_item')){
- items_completed++;
- $current_node.data('done_item',1);
- }
- $current_node.find('.spinner').css('visibility','hidden');
- }
- var $items = $('tr.envato_default_content');
- var $enabled_items = $('tr.envato_default_content input:checked');
- $items.each(function(){
- if (current_item == '' || do_next) {
- current_item = $(this).data('content');
- $current_node = $(this);
- process_current();
- do_next = false;
- } else if ($(this).data('content') == current_item) {
- do_next = true;
- }
- });
- if(items_completed >= $items.length){
- // finished all items!
- complete();
- }
- }
- return {
- init: function(btn){
- $('.envato-setup-pages').addClass('installing');
- $('.envato-setup-pages').find('input').prop("disabled", true);
- complete = function(){
- loading_content();
- window.location.href=btn.href;
- };
- find_next();
- }
- }
- }
- /**
- * Callback function for the 'click' event of the 'Set Footer Image'
- * anchor in its meta box.
- *
- * Displays the media uploader for selecting an image.
- *
- * @since 0.1.0
- */
- function renderMediaUploader() {
- 'use strict';
- var file_frame, attachment;
- if ( undefined !== file_frame ) {
- file_frame.open();
- return;
- }
- file_frame = wp.media.frames.file_frame = wp.media({
- title: 'Upload Logo',//jQuery( this ).data( 'uploader_title' ),
- button: {
- text: 'Select Logo' //jQuery( this ).data( 'uploader_button_text' )
- },
- multiple: false // Set to true to allow multiple files to be selected
- });
- // When an image is selected, run a callback.
- file_frame.on( 'select', function() {
- // We set multiple to false so only get one image from the uploader
- attachment = file_frame.state().get('selection').first().toJSON();
- jQuery('.site-logo').attr('src',attachment.url);
- jQuery('#new_logo_id').val(attachment.id);
- // Do something with attachment.id and/or attachment.url here
- });
- // Now display the actual file_frame
- file_frame.open();
- }
- function dtbaker_loading_button(btn){
- var $button = jQuery(btn);
- if($button.data('done-loading') == 'yes')return false;
- var existing_text = $button.text();
- var existing_width = $button.outerWidth();
- var loading_text = '⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⠄⠂⠁⠁⠂⠄';
- var completed = false;
- $button.css('width',existing_width);
- $button.addClass('dtbaker_loading_button_current');
- var _modifier = $button.is('input') || $button.is('button') ? 'val' : 'text';
- $button[_modifier](loading_text);
- //$button.attr('disabled',true);
- $button.data('done-loading','yes');
- var anim_index = [0,1,2];
- // animate the text indent
- function moo() {
- if (completed)return;
- var current_text = '';
- // increase each index up to the loading length
- for(var i = 0; i < anim_index.length; i++){
- anim_index[i] = anim_index[i]+1;
- if(anim_index[i] >= loading_text.length)anim_index[i] = 0;
- current_text += loading_text.charAt(anim_index[i]);
- }
- $button[_modifier](current_text);
- setTimeout(function(){ moo();},60);
- }
- moo();
- return {
- done: function(){
- completed = true;
- $button[_modifier](existing_text);
- $button.removeClass('dtbaker_loading_button_current');
- $button.attr('disabled',false);
- }
- }
- }
- return {
- init: function(){
- t = this;
- $(window_loaded);
- },
- callback: function(func){
- console.log(func);
- console.log(this);
- }
- }
- })(jQuery);
- EnvatoWizard.init();
|