コード例 #1
0
 /**
  * render
  *
  * @since 2.2.0
  *
  * @param mixed $src
  * @param array $options
  *
  * @return string
  */
 public static function render($src = null, $options = array())
 {
     $output = '';
     /* device related images */
     if (is_array($src)) {
         /* process source */
         foreach ($src as $key => $value) {
             if (in_array($key, self::$_config['device']) && Registry::get('my' . ucfirst($key))) {
                 $src = $value;
             }
         }
     }
     /* collect output */
     if (file_exists($src)) {
         $imageElement = new Element('img', array('src' => self::$_config['placeholder'], 'class' => self::$_config['className']['image'] . ' ' . $options['className'], 'alt' => $options['alt']));
         /* collect output */
         $output = $imageElement->copy()->attr('data-src', $src);
         /* placeholder */
         if (self::$_config['placeholder']) {
             /* calculate image ratio */
             $imageDimensions = getimagesize($src);
             $imageRatio = $imageDimensions[1] / $imageDimensions[0] * 100;
             /* placeholder */
             $placeholderElement = new Element('div', array('class' => self::$_config['className']['placeholder'], 'style' => 'padding-bottom:' . $imageRatio . '%'));
             /* collect output */
             $output = $placeholderElement->html($output);
         }
         /* noscript fallback */
         $output .= '<noscript>' . $imageElement . '</noscript>';
     }
     return $output;
 }
コード例 #2
0
 /**
  * testCopy
  *
  * @since 2.2.0
  */
 public function testCopy()
 {
     /* setup */
     $element = new Element('a');
     $elementCopy = $element->copy()->attr('href', 'test');
     /* expect and actual */
     $expect = $element;
     $actual = $elementCopy;
     /* compare */
     $this->assertNotEquals($expect, $actual);
 }