From 31942729d79a07942f42745d26c2038908c640e6 Mon Sep 17 00:00:00 2001 From: aarongustafson Date: Mon, 22 Jul 2013 11:38:47 -0400 Subject: [PATCH] Initial commit --- .gitmodules | 3 + README.md | 47 +++- .../third_party/easy_jail/pi.easy_jail.php | 233 ++++++++++++++++++ .../third_party/easy_jail/vendors/jail | 1 + 4 files changed, 282 insertions(+), 2 deletions(-) create mode 100644 .gitmodules create mode 100644 system/expressionengine/third_party/easy_jail/pi.easy_jail.php create mode 160000 system/expressionengine/third_party/easy_jail/vendors/jail diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9941e56 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "system/expressionengine/third_party/easy_jail/vendors/jail"] + path = system/expressionengine/third_party/easy_jail/vendors/jail + url = https://github.com/sebarmeli/JAIL.git diff --git a/README.md b/README.md index 577e67e..acede53 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,47 @@ -easy_jail.ee_addon -================== +Easy JAIL for ExpressionEngine +============================== ExpressionEngine Plugin to automate use of the jQuery Asynchronous Image Loader + +The API +------- + +First off, this plugin requires jQuery. Using it requires 2 steps: + +**Step 1:** Wrap the markup you want to JAIL in `{exp:easy_jail:prep}` + + {exp:easy_jail:prep} + {body} + {/exp:easy_jail:prep} + +This will cause the plugin to convert + + + +into + + + + +Providing it with additional params allows you to customize certain bits: + +* `xhtml="n"` - HTML output +* `blank_img="my_blank.gif"` - Your custom blank image +* `class_name="custom_class"` - Your custom class choice + +**Step 2:** Include `{exp:easy_jail:js}` at the end of your `body` element, after you included jQuery. + + + + {exp:easy_jail:js} + +By default, this will include the JAIL script and a baseline configuration. To configure the output of the script, you can use the following parameters: + +* `class_name="custom_class"` - Your custom class choice +* `config="{offset:300}"` - Your custom configuration (see the [JAIL documentation](http://sebarmeli.github.io/JAIL/) for a run-down of options) + + +License +------- + +Easy JAIL for ExpressionEngine and jQuery JAIL are both distributed under the liberal MIT License. \ No newline at end of file diff --git a/system/expressionengine/third_party/easy_jail/pi.easy_jail.php b/system/expressionengine/third_party/easy_jail/pi.easy_jail.php new file mode 100644 index 0000000..3636c32 --- /dev/null +++ b/system/expressionengine/third_party/easy_jail/pi.easy_jail.php @@ -0,0 +1,233 @@ + 'Easy JAIL', + 'pi_version' => '1.0', + 'pi_author' => 'Aaron Gustafson', + 'pi_author_url' => 'http://easy-designs.net/', + 'pi_description' => 'Automates the implementation of Sebastiano Armeli-Battana’s jQuery Asynchronous Image Loader Plugin', + 'pi_usage' => Easy_jail::usage() +); + +class Easy_jail { + + var $return_data; + var $template = ''; + var $xhtml = TRUE; + var $class_name = 'jail'; + var $blank_img = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='; + var $alt = ''; + var $config = ''; + + /** + * Easy_jail constructor + * sets any overrides and triggers the processing + * + * @param str $str - the content to be parsed + */ + function __construct() + { + $this->return_data = ee()->TMPL->tagdata; + } # end Easy_jail constructor + + /** + * Easy_jail::prep() + * processes the supplied content based on the configuration + * + * @param str $str - the content to be parsed + */ + function prep( $str='', $xhtml='', $class_name='', $blank_img='' ) + { + # get any tag overrides + if ( empty( $xhtml ) ) + { + $xhtml = ee()->TMPL->fetch_param( 'xhtml', $this->xhtml ); + } + if ( empty( $class_name ) ) + { + $class_name = ee()->TMPL->fetch_param( 'class_name', $this->class_name ); + } + if ( empty( $blank_img ) ) + { + $blank_img = ee()->TMPL->fetch_param( 'blank_img', ( empty( $blank_img ) ? $this->blank_img : $blank_img ) ); + } + + # Fetch string + if ( empty( $str ) ) + { + $str = ee()->TMPL->tagdata; + } + + # trim + $str = trim( $str ); + + $lookup = '/(]*)\/?>)/'; + if ( preg_match_all( $lookup, $str, $found, PREG_SET_ORDER ) ) + { + # loop the matches + foreach ( $found as $instance ) + { + $o_img = $instance[1]; + $src = ''; + + # get the attributes + $attributes = array(); + + # remove the / + if ( substr( $instance[2], -1, 1 ) == '/' ) + { + $instance[2] = substr( $instance[2], 0, -1 ); + } + + foreach ( explode( ' ', trim( $instance[2] ) ) as $attr ) + { + preg_match_all( '/([^=]*)=([\'"])(.*)\\2$/', $attr, $matches, PREG_SET_ORDER ); + + if ( isset( $matches[0] ) ) + { + if ( $matches[0][1] == 'src' ) + { + $src = $matches[0][3]; + } + else + { + $attributes[$matches[0][1]] = $matches[0][1] . '="' . $matches[0][3] . '"'; + } + } + } + + # enforce an alt attribute + if ( ! isset( $attributes['alt'] ) ) + { + $attributes['alt'] = $this->alt; + } + + # build the new image + $swap = array( + 'attributes' => implode( ' ', $attributes ), + 'class_name' => $class_name, + 'blank_img' => $blank_img, + 'real_img' => $src + ); + $n_img = ee()->functions->var_swap( $this->template, $swap ); + + # XHTML? + if ( ! $xhtml ) + { + $n_img = str_replace( '/>', '>', $n_img ); + } + + $str = str_replace( $o_img, $n_img, $str ); + + } # end foreach instance + + } # end if match + + $this->return_data = $str; + + return $this->return_data; + + } # end Easy_jail::prep() + + /** + * Easy_jail::js() + * Describes how the plugin is used + */ + function js( $class_name='', $config='' ) + { + $js = ''; + + # get tag params + if ( empty( $class_name ) ) + { + $class_name = ee()->TMPL->fetch_param( 'class_name', $this->class_name ); + } + if ( empty( $config ) ) + { + $config = ee()->TMPL->fetch_param( 'config', $this->config ); + } + + # get JAIL + $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));'; + $swap = array( + 'class_name' => $class_name, + 'jail_config' => $config + ); + $js .= ee()->functions->var_swap( $template, $swap ); + + $this->return_data = ''; + + return $this->return_data; + + } # end Easy_jail::js() + + /** + * Easy_jail::usage() + * Describes how the plugin is used + */ + function usage() + { + ob_start(); ?> +First off, this plugin requires jQuery. Using it requires 2 steps: + +1) Wrap the markup you want to JAIL in {exp:easy_jail:prep} + +{exp:easy_jail:prep} + {body} +{/exp:easy_jail:prep} + +This will cause the plugin to convert + + + +into + + + + +Providing it with additional params allows you to customize certain bits: + +* xhtml="n" - HTML output +* blank_img="my_blank.gif" - Your custom blank image +* class_name="custom_class" - Your custom class choice + +2) Include {exp:easy_jail:js} at the end of your body element, after you included jQuery. + + + +{exp:easy_jail:js} + +By default, this will include the JAIL script and a baseline configuration. To configure the output of the script, you can use the following parameters: + +* class_name="custom_class" - Your custom class choice +* config="{offset:300}" - Your custom configuration (see http://sebarmeli.github.io/JAIL/ for a run-down of options) +