Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
incorporating some tweaks from Jens Korff and a fix to the issue of a…
Browse files Browse the repository at this point in the history
…nchoring & going back
  • Loading branch information
aarongustafson committed Jan 29, 2015
1 parent 0112445 commit ec793cc
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions system/expressionengine/third_party/easy_jail/pi.easy_jail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
http://easy-designs.net/
=====================================================
This extension was created by Aaron Gustafson
- [email protected]
([email protected]) with contributions from
Jens Korff
This work is licensed under the MIT License.
=====================================================
File: pi.easy_jail.php
Expand Down Expand Up @@ -96,19 +97,24 @@ function prep( $str='', $xhtml='', $class_name='', $blank_img='' )
$instance[2] = substr( $instance[2], 0, -1 );
}

foreach ( explode( ' ', trim( $instance[2] ) ) as $attr )
# Get all attributes
# Reference: http://stackoverflow.com/questions/138313/how-to-extract-img-src-title-and-alt-from-html-using-php#answer-2937682
$doc = new DOMDocument();
@$doc->loadHTML($o_img);
$tags = $doc->getElementsByTagName('img');

foreach ( $tags as $tag )
{
preg_match_all( '/([^=]*)=([\'"])(.*)\\2$/', $attr, $matches, PREG_SET_ORDER );

if ( isset( $matches[0] ) )
foreach ( $tag->attributes as $attribute )
{
if ( $matches[0][1] == 'src' )
{
$src = $matches[0][3];
}
else
$name = $attribute->name;
$value = $attribute->value;

if ( $name == 'src' )
{
$attributes[$matches[0][1]] = $matches[0][1] . '="' . $matches[0][3] . '"';
$src = $value;
} else {
$attributes[$name] = $name . '="' . $value . '"';
}
}
}
Expand Down Expand Up @@ -168,7 +174,7 @@ function js( $class_name='', $config='' )
$js .= file_get_contents( PATH_THIRD . '/easy_jail/vendors/jail/dist/jail.min.js' ) . "\n\n";

# build the trigger
$template = '(function($){$("img.{class_name}").jail({jail_config});}(jQuery));';
$template = '(function(window,$){$("img.{class_name}").jail({jail_config});$(window).on("load",function(){$(this).resize();});}(this,jQuery));';
$swap = array(
'class_name' => $class_name,
'jail_config' => $config
Expand Down

0 comments on commit ec793cc

Please sign in to comment.