/** * Marketplace JS file * * This file contains all functions relating to the Layers Marketplace * * @package Layers * @since Layers 1.0.0 * * Contents * * 1 - Modal Closing Functions * 2 - Modal Keyboard Navigation * 3 - Modal population script * 4 - Marketplace Filter and Search functions * 5 - Item height matcher * * Author: Obox Themes * Author URI: http://www.oboxthemes.com/ * License: GNU General Public License v2 or later * License URI: http://www.gnu.org/licenses/gpl-2.0.html */ jQuery(function($) { /** * 1 - Modal Closing Functions */ $(document).on( 'click', '#layers-marketplace .theme-backdrop', function(e){ if( $(this).not( '.theme-overlay' ) ){ $( '#layers-marketplace .theme-overlay button.close' ).trigger( 'click' ); } }); $(document).on( 'click', '#layers-marketplace .theme-overlay button.close', function(e){ e.preventDefault(); $( '.theme-overlay' ).fadeOut(250).addClass( 'l_admin-hide' ); }); /** * 2 - Modal Keyboard Navigation */ $( '.toplevel_page_layers-marketplace' ).on( "keyup", function( e ) { e.preventDefault(); $modal = $( '.theme-overlay' ); // Esc if( 27 == event.which ){ $modal.find( '.close' ).click(); } // <- if( 37 == event.which ){ $modal.find( '.left' ).click(); } // -> if( 39 == event.which ){ $modal.find( '.right' ).click(); } }); /** * 3 - Modal population script */ function layers_marketplace_hide_preview(){ $( '.theme-preview iframe' ).remove(); $( '.theme-preview' ).hide(); $( '.theme-about' ).removeClass( 'l_admin-hide' ).show(); $( '.theme-demo-link' ).text( $( '.theme-demo-link' ).data( 'show-preview-label' ) ); } $(document).on( 'click', '#layers-marketplace [data-view-item^="product-details-"]', function(e){ e.preventDefault(); var $layers_a = $(this); $id = '#' + $layers_a.attr('data-view-item'); var $my_data = $( $id ).find( 'input' ).val(); var $json = ''; $json = jQuery.parseJSON( $my_data ); $modal = $( '.theme-overlay' ); /** * Product Screenshot */ $screenshot = $( $id ).find( '.l_admin-product-screenshot' ).html(); $modal.find( '.theme-screenshots' ).html( $( $screenshot ).removeAttr( 'width') ); /** * Product Details */ $modal.find( '.theme-name' ).text( $json.name ); /** * Product Meta */ $price = $json.price; $modal.find( '.theme-author-img' ).attr( 'src' , $json.author_image ); $modal.find( '.theme-author' ).attr( 'href' , $json.author_url ) $modal.find( '.theme-author' ).text( 'By ' + $json.author ); $sales_word = ( $json.sales == 1 ? ' sale' : ' sales' ); $modal.find( '.theme-sales' ).html( $json.sales + $sales_word).show(); if( 0 == $json.sales ) $modal.find( '.theme-sales' ).hide(); /** * Product Preview */ layers_marketplace_hide_preview(); $( '.theme-demo-link' ).attr( 'data-allow-demo', $json.allow_demo ); $( '.theme-demo-link' ).attr( 'data-demo-url', $json.demo_url ); /** * Product Links */ var $url = $( $id ).data( 'url' ); $modal.find( '.theme-details-link' ).attr( 'href' , $url ); if( '' == $json.demo_url ){ $modal.find( '.theme-demo-link' ).hide(); } else { $modal.find( '.theme-demo-link' ).show().attr( 'href' , $json.demo_url + '&type=demo&slug=' + $( $id ).data( 'slug' ) ); } $modal.find( '.theme-buy-link' ).attr( 'href' , $url + "&type=purchase" ); $modal.find( '.theme-details-link, .theme-demo-link, .theme-buy-link' ).attr( 'data-item', $json.name ).attr( 'data-price', '$ ' + $price ); /** * Product Description & Summary */ var decoded_description = $("
").html( $json.description ).text(); $modal.find( '.theme-description' ).html( decoded_description + ' Read More' ); $modal.find( '.theme-price' ).text( '$' + $price ); $modal.find( '.theme-tags' ).text( $json.summary ); /** * Next / Previous buttons */ if( 1 > $( $id ).prev( 'div.l_admin-product' ).length ){ $prev = $('.l_admin-products .l_admin-product').eq( $('.l_admin-products .l_admin-product').length - 1 ).attr( 'id' ); } else { $prev = $( $id ).prev().attr( 'id' ); } $modal.find( '.left' ).attr( 'data-view-item' , $prev ); if( 1 > $( $id ).next( 'div.l_admin-product' ).length ){ $next = $('.l_admin-products .l_admin-product').eq(0).attr( 'id' ); } else { $next = $( $id ).next().attr( 'id' ); } $modal.find( '.right' ).attr( 'data-view-item' , $next ); /** * Rating */ $modal.find( '.theme-rating' ).html(''); if( 3 > $json.rating_count ){ $modal.find( '.theme-rating' ).hide(); } else { $modal.find( '.theme-rating' ).show(); for( i = 1; i < 6; i++ ){ if( i <= Math.round( $json.rating ) ){ $star_class = 'star star-full'; } else { $star_class = 'star star-empty'; } $modal.find( '.theme-rating' ).append( $('') ); } } if( $( '.theme-overlay' ).hasClass( 'l_admin-hide' ) ){ $( '.theme-overlay' ).hide().removeClass( 'l_admin-hide' ).fadeIn(250); } }); $(document).on( 'click', '.theme-demo-link', function(e){ var $demo_url = $(this).attr( 'data-demo-url' ); var $allow_demo = $(this).attr( 'data-allow-demo' ); if( 'true' == $allow_demo ) e.preventDefault(); if( 'true' == $allow_demo && '' !== $demo_url && 0 == $( '.theme-preview iframe' ).length ){ $iframe = $( '