예제 #1
0
 /**
  * Push JS to the document
  *
  * @param   string  $asset      Script to add
  * @param   string  $extension  Extension name, e.g.: com_example, mod_example, plg_example_test
  * @param   string  $element    Plugin element. Only used for plugins and if first argument is folder name.
  * @return  object
  */
 public function __invoke($asset = '', $extension = null, $element = null)
 {
     $extension = $extension ?: $this->_extension();
     if ($element) {
         $extension = 'plg_' . $extension . '_' . $element;
     }
     $asset = new Javascript($extension, $asset);
     if ($asset->exists()) {
         if ($asset->isDeclaration()) {
             Document::addScriptDeclaration($asset->contents());
         } else {
             Document::addScript($asset->link());
         }
     }
     return $this->getView();
 }
예제 #2
0
 /**
  * Push JS to the document
  *
  * @param   string  $asset      Script to add
  * @param   string  $extension  Extension name, e.g.: com_example, mod_example, plg_example_test
  * @param   string  $element    Plugin element. Only used for plugins and if first argument is folder name.
  * @return  object
  */
 public function js($asset = '', $extension = null, $element = null)
 {
     $extension = $extension ?: $this->detectExtensionName();
     $attr = array('type' => 'text/javascript', 'defer' => false, 'async' => false);
     if ($element) {
         if (is_string($element)) {
             $extension = 'plg_' . $extension . '_' . $element;
         } else {
             if (is_array($element)) {
                 foreach ($element as $key => $val) {
                     if (array_key_exists($key, $attr)) {
                         $attr[$key] = $val;
                     }
                 }
             }
         }
     }
     $asset = new Javascript($extension, $asset);
     if ($asset->exists()) {
         if ($asset->isDeclaration()) {
             \App::get('document')->addScriptDeclaration($asset->contents());
         } else {
             \App::get('document')->addScript($asset->link(), $attr['type'], $attr['defer'], $attr['async']);
         }
     }
     return $this;
 }
예제 #3
0
 /**
  * Adds a linked script to the page
  *
  * @param   string  $folder  Plugin folder name
  * @param   string  $plugin  Plugin name
  * @param   string  $script  Script name (optional, uses module name if left blank)
  * @param   string  $dir     Asset directory to look in
  * @return  void
  */
 public static function addPluginScript($folder, $plugin, $script = '', $dir = 'js')
 {
     if ($dir != 'js') {
         $script = $dir . '/' . $script;
     }
     $asset = new Javascript('plg_' . $folder . '_' . $plugin, $script);
     if ($asset->exists()) {
         if ($document = self::app('document')) {
             $document->addScript($asset->link());
         }
     }
 }