Example #1
0
 /**
  * Push CSS to the document
  *
  * @param   string  $stylesheet  Stylesheet or styles 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 css($stylesheet = '', $extension = null, $element = null)
 {
     $extension = $extension ?: $this->detectExtensionName();
     $attr = array('type' => 'text/css', 'media' => null, 'attribs' => array());
     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 Stylesheet($extension, $stylesheet);
     if ($asset->exists()) {
         if ($asset->isDeclaration()) {
             \App::get('document')->addStyleDeclaration($asset->contents());
         } else {
             \App::get('document')->addStyleSheet($asset->link(), $attr['type'], $attr['media'], $attr['attribs']);
         }
     }
     return $this;
 }
Example #2
0
 /**
  * Push CSS to the document
  *
  * @param   string  $stylesheet  Stylesheet or styles 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($stylesheet = '', $extension = null, $element = null)
 {
     $extension = $extension ?: $this->_extension();
     if ($element) {
         $extension = 'plg_' . $extension . '_' . $element;
     }
     $asset = new Stylesheet($extension, $stylesheet);
     if ($asset->exists()) {
         if ($asset->isDeclaration()) {
             Document::addStyleDeclaration($asset->contents());
         } else {
             Document::addStyleSheet($asset->link());
         }
     }
     return $this->getView();
 }
Example #3
0
 /**
  * Adds a linked stylesheet from a plugin to the page
  *
  * @param   string  $folder      Plugin folder name
  * @param   string  $plugin      Plugin name
  * @param   string  $stylesheet  Stylesheet name (optional, uses module name if left blank)
  * @param   string  $dir         Asset directory to look in
  * @return  void
  */
 public static function addPluginStyleSheet($folder, $plugin, $stylesheet = '', $dir = 'css')
 {
     if ($dir != 'css') {
         $stylesheet = $dir . '/' . $stylesheet;
     }
     $asset = new Stylesheet('plg_' . $folder . '_' . $plugin, $stylesheet);
     if ($asset->exists()) {
         if ($document = self::app('document')) {
             $document->addStyleSheet($asset->link());
         }
     }
 }