Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from imgix/8-v1-pass-through-attriubutes
Browse files Browse the repository at this point in the history
Statamic 1.x implementation of pass-attrs for #8
  • Loading branch information
paulstraw authored Oct 4, 2016
2 parents f5eced1 + 2cef49c commit 3188db6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions _add-ons/imgix/pi.imgix.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@

class Plugin_imgix extends Plugin
{
private static $html_attributes = array('accesskey', 'align', 'alt', 'border', 'class', 'contenteditable', 'contextmenu', 'dir', 'height', 'hidden', 'id', 'lang', 'longdesc', 'sizes', 'style', 'tabindex', 'title', 'usemap', 'width');
protected $builder;

protected function categorized_attributes() {
$attrs = $this->attributes;

$categorized_attrs = array(
'path' => $attrs['path'],
'img_attributes' => array(),
'html_attributes' => array(),
'imgix_attributes' => array()
);

unset($attrs['path']);

while (list($key, $val) = each($attrs)) {
$is_img_attr = in_array($key, array('alt', 'longdesc', 'title'));
$is_html_attr = in_array($key, self::$html_attributes);
$is_data_attr = strpos($key, 'data-') === 0;
$is_aria_attr = strpos($key, 'aria-') === 0;

if ($is_img_attr || $is_data_attr || $is_aria_attr) {
$categorized_attrs['img_attributes'][$key] = $val;
if ($is_html_attr || $is_data_attr || $is_aria_attr) {
$categorized_attrs['html_attributes'][$key] = $val;
} else {
$categorized_attrs['imgix_attributes'][$key] = $val;
}
Expand All @@ -40,12 +41,12 @@ protected function build_url($categorized_attrs) {
);
}

protected function build_img_attributes($categorized_attrs) {
$img_attributes = $categorized_attrs['img_attributes'];
protected function build_html_attributes($categorized_attrs) {
$html_attributes = $categorized_attrs['html_attributes'];

$html = '';

while (list($key, $val) = each($img_attributes)) {
while (list($key, $val) = each($html_attributes)) {
$html .= " $key=\"$val\"";
}

Expand Down Expand Up @@ -93,7 +94,7 @@ public function image_tag() {
'<img src="',
$this->build_url($categorized_attrs),
'" ',
$this->build_img_attributes($categorized_attrs),
$this->build_html_attributes($categorized_attrs),
'>'
));
}
Expand All @@ -107,7 +108,7 @@ public function responsive_image_tag() {
'" src="',
$this->build_url($categorized_attrs),
'" ',
$this->build_img_attributes($categorized_attrs),
$this->build_html_attributes($categorized_attrs),
'>'
));
}
Expand All @@ -123,7 +124,7 @@ public function picture_tag() {
'<img src="',
$this->build_url($categorized_attrs),
'" ',
$this->build_img_attributes($categorized_attrs),
$this->build_html_attributes($categorized_attrs),
'>',
'</picture>'
));
Expand Down

0 comments on commit 3188db6

Please sign in to comment.