Exemple #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();
 }
 /**
  * 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;
 }