示例#1
0
 /**
  * Display method
  *
  * @param string $tpl
  *
  * @return string
  */
 public function display($tpl = null)
 {
     // Add CSS
     JHTML::stylesheet('media/com_magebridge/css/backend-elements.css');
     // Load jQuery
     YireoHelper::jquery();
     $this->current = JFactory::getApplication()->input->get('current');
     $this->object = JFactory::getApplication()->input->get('object');
     parent::display($tpl);
 }
示例#2
0
 /**
  * Helper-method to return the right AJAX-script
  *
  * @param string $block
  * @param string $element
  * @param string $url
  * @return bool
  */
 public static function getScript($block, $element, $url = null)
 {
     // Set the default AJAX-URL
     if (empty($url)) {
         $url = self::getUrl($block);
     }
     // Load ProtoType
     if (MageBridgeTemplateHelper::hasPrototypeJs() == true) {
         $script = "Event.observe(window,'load',function(){new Ajax.Updater('{$element}','{$url}',{method:'get'});});";
         // Load jQuery
     } else {
         if (JFactory::getApplication()->get('jquery') == true) {
             $script = "jQuery(document).ready(function(){\n" . "\tjQuery('#" . $element . "').load('" . $url . "');" . "});\n";
             // Load jQuery ourselves
         } else {
             YireoHelper::jquery();
             $script = "jQuery(document).ready(function(){\n" . "\tjQuery('#" . $element . "').load('" . $url . "');" . "});\n";
         }
     }
     return $script;
 }
示例#3
0
 /**
  * Function to load a specific stylesheet or script
  *
  * @param string $type
  * @param string $file
  * @return bool
  */
 public static function load($type, $file = null)
 {
     // Fetch system-variables
     $template = JFactory::getApplication()->getTemplate();
     $document = JFactory::getDocument();
     $application = JFactory::getApplication();
     // Handle shortcuts to specific scripts or stylesheets
     switch ($type) {
         case 'jquery':
             // Load jQuery through the Google API
             if (MagebridgeModelConfig::load('use_google_api') == 1) {
                 $prefix = JURI::getInstance()->isSSL() ? 'https' : 'http';
                 $document->addScript($prefix . '://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js');
             } else {
                 YireoHelper::jquery();
             }
             // Set the flag that jQuery has been loaded
             if (method_exists($application, 'set')) {
                 $application->set('jquery', true);
             }
             return;
         case 'jquery-easing':
             self::load('js', 'jquery/jquery.easing.1.3.js');
             return;
         case 'jquery-fancybox':
             self::load('js', 'jquery/jquery.fancybox-1.3.1.pack.js');
             return;
         case 'jquery-mousewheel':
             self::load('js', 'jquery/jquery.mousewheel-3.0.2.pack.js');
             return;
         case 'jquery-carousel':
             self::load('js', 'jquery/jquery.jcarousel.pack.js');
             return;
         case 'jquery-lazyload':
             self::load('jquery');
             self::load('js', 'jquery/jquery.lazyload.mini.js');
             $ll_options = '{effect:"fadeIn", treshhold:20}';
             $ll_elements = 'a.product-image img';
             $ll_script = 'jQuery(document).ready(function($) {jQuery("' . $ll_elements . '").lazyload(' . $ll_options . ');});';
             $document->addCustomTag('<script type="text/javascript">' . $ll_script . '</script>');
             return;
     }
     // Check whether a file of a certain type exists - either as a template override, or as original file
     $path = self::getPath($type, $file);
     if (empty($path)) {
         return;
     }
     // Handle JavaScript
     if ($type == 'js') {
         // Load ProtoType-scripts as a custom tag so it loads after the main library (hopefully)
         if (stristr($path, 'prototype')) {
             $html = '<script type="text/javascript" src="' . $path . '"></script>';
             $document->addCustomTag($html);
         } else {
             $file = basename($path);
             $path = dirname($path);
             $document->addScript($path . '/' . $file);
         }
     } else {
         // Handle CSS
         $document->addStylesheet($path);
     }
 }
示例#4
0
 public static function ajax($url = null, $div = null)
 {
     $document = JFactory::getDocument();
     if (stristr(get_class($document), 'html') == false) {
         return false;
     }
     YireoHelper::jquery();
     $script = "<script type=\"text/javascript\">\n" . "jQuery(document).ready(function() {\n" . "    var MBajax = jQuery.ajax({\n" . "        url: '" . $url . "', \n" . "        method: 'get', \n" . "        success: function(result){\n" . "            if (result == '') {\n" . "                alert('Empty result');\n" . "            } else {\n" . "                jQuery('#" . $div . "').html(result);\n" . "            }\n" . "        }\n" . "    });\n" . "});\n" . "</script>";
     $document->addCustomTag($script);
 }