register_scripts_and_styles(); add_shortcode("animation-set", array( $this, 'animationSet')); add_shortcode("animation-element", array( $this, 'animationElement')); //http://sww.co.nz/solution-to-wordpress-adding-br-and-p-tags-around-shortcodes/ remove_filter( 'the_content', 'wpautop' ); add_filter( 'the_content', 'wpautop' , 12); } /** * Registers and enqueues stylesheets for the administration panel and the * public facing site. */ private function register_scripts_and_styles() { wp_register_script( "gsapTweenMax", 'http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js'); wp_enqueue_script( "gsapTweenMax" ); wp_register_script( "fidesit_ayc", plugins_url("js/ayc.js", __FILE__), array( 'jquery' ) ); //depends on jquery wp_enqueue_script( "fidesit_ayc" ); } // end register_scripts_and_styles public function animationSet($args, $content = null) { $id = "fidesit_ayc_".sanitize_key($args["id"]); $defaults = array( 'time' => 2.0, 'type' => "animation-element", 'delay_increment' => 0 ); $this->parent_attrs = wp_parse_args( $args, $defaults ); $this->child_count=0; wp_add_inline_style( $id, "#".$id."{ display:none; }" ); $result= '
'.do_shortcode($content).'
'; $this->parent_attrs=array(); return $result; } public function animationElement($args, $content = null) { $this->nrOfElements+=1; $defaults = $this->parent_attrs; $r = wp_parse_args( $args, $defaults ); if (!array_key_exists('delay', $r)){ $r['delay']=((float)$r['delay_increment'])*(float)$this->child_count; } unset($r['delay_increment']); $this->child_count+=1; return '
shortcode_args_to_html_attrs($r).'>'.do_shortcode($content).'
'; } public function shortcode_args_to_html_attrs($args){ $final_arr = array(); foreach ($args as $key=>$value){ if (in_array($key, array("class", "style"))){ $final_arr[$key]=$value; } else if (in_array($key, array("type", "effect","time", "id"))){ $final_arr["ayc_".$key]=$value; } else { $final_arr["gsap_".$key]=$value; } } $result=""; foreach ($final_arr as $key => $value){ $result.=' '.$key.'="'.$value.'"'; } return $result; } } // end class new AnimateYourContentPlugin(); ?>