Как сделать: включить / отключить опцию для функции JavaScript с php?

Я все еще новичок в php, javascript, поэтому я надеюсь, что вы можете мне помочь.:)

У меня есть LightBox, который хорошо работает. Но теперь я хочу включить / отключить опцию Lightbox в моей теме Wordpress.

У меня есть этот код для страницы настроек параметров:

array (
                        'id' => 'enable_lightbox',
                        'type' => 'switch',
                        'title' => __('Enable Lightbox', 'framework'),
                        'desc' => __('Enable or disable lightbox', 'framework'),
                        'default' => 1,
                    ),

и это код для лайтбокса:

/LightBox    
function buildShareThis(url){
 var switchTo5x=true;
 stLight.options({publisher: "496075ad-6369-474b-ba12-283ff1fe76ac", doNotHash: false, doNotCopy: false, hashAddressBar: false});
 var customShareThis  = "<div class='share'>";
 customShareThis += "<span class='st_sharethis_large' displayText='ShareThis' st_url='"+url+"'></span> ";
 customShareThis += "<span class='st_facebook_large' displayText='Facebook' st_url='"+url+"'></span>";
 customShareThis += "<span class='st_googleplus_large' displayText='Google +' st_url='"+url+"'></span>";
 customShareThis += "<span class='st_twitter_large' displayText='Tweet' st_url='"+url+"'></span> ";
 customShareThis += "<span class='st_pinterest_large' st_url='"+url+"'></span>";
 customShareThis += "<span class='st_linkedin_large' displayText='LinkedIn' st_url='"+url+"'></span>";
 customShareThis += "<span class='st_baidu_large' displayText='Baidu' st_url='"+url+"'></span>";
 customShareThis += "<span class='st_reddit_large' displayText='Reddit' st_url='"+url+"'></span>";
 customShareThis += "<span class='st_tumblr_large' displayText='Tumblr' st_url='"+url+"'></span>";
 customShareThis += "<span class='st_email_large' displayText='Email' st_url='"+url+"'></span>";
 customShareThis += "<span class='st_print_large' displayText='Print' st_url='"+url+"'></span>";
 customShareThis += "</div>";
 return customShareThis;
}


 jQuery(".fancybox, a[href$='.jpg'], a[href$='.png'], a[href$='.jpeg'], a[href$='.gif'], .video")
 .attr('rel', 'gallery')
 .fancybox({
   closeClick  : false,
   nextEffect: 'fade',
   prevEffect: 'fade',
   beforeShow: function() {
     var caption =  jQuery(this.element).data("caption") ? jQuery(this.element).data("caption") : "";
     this.title = this.title ? this.title + buildShareThis(this.href) + caption : buildShareThis(this.href) + caption;
  },
  afterShow: function(){
     stButtons.locateElements();
  },
  helpers : {
    title : {
        type: 'inside'
  }
  } 
 });

Какой код мне нужно использовать, чтобы это работало?

Чтобы я мог из настроек страницы настроек включить или выключить лайтбокс?

Спасибо

1 ответ

Решение

PHP-код

if($setting -> default == 1) // Is enable
{
       echo '<script>var enable_Light = false; </script>';
}

в коде LightBox добавить раздел if.

 if(enable_Light == true){
 jQuery(".fancybox, a[href$='.jpg'], a[href$='.png'], a[href$='.jpeg'], a[href$='.gif'], .video")
 .attr('rel', 'gallery')
 .fancybox({
   closeClick  : false,
   nextEffect: 'fade',
   prevEffect: 'fade',
   beforeShow: function() {
     var caption =  jQuery(this.element).data("caption") ? jQuery(this.element).data("caption") : "";
     this.title = this.title ? this.title + buildShareThis(this.href) + caption : buildShareThis(this.href) + caption;
  },
  afterShow: function(){
     stButtons.locateElements();
  },
  helpers : {
    title : {
        type: 'inside'
  }
  } 
 });
}
Другие вопросы по тегам