From 45b7aa5275b01120663385800ac27b28b4c3c4f8 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sun, 13 Jul 2014 03:43:38 +1000 Subject: [PATCH] Use ajax for shortcode generator menu in editor --- assets/js/admin/editor.js | 217 ++--- includes/admin/class-sp-admin-assets.php | 2 +- includes/admin/class-sp-admin-menus.php | 2 +- includes/admin/class-sp-admin-thickbox.php | 483 ----------- includes/admin/class-sp-admin.php | 3 +- .../post-types/class-sp-admin-meta-boxes.php | 2 +- includes/class-sp-ajax.php | 754 ++++++++++++++++++ includes/class-sp-event.php | 2 +- includes/class-sp-shortcodes.php | 2 +- sportspress.php | 11 + 10 files changed, 850 insertions(+), 628 deletions(-) delete mode 100644 includes/admin/class-sp-admin-thickbox.php create mode 100644 includes/class-sp-ajax.php diff --git a/assets/js/admin/editor.js b/assets/js/admin/editor.js index c18e6dfa..6ba9a908 100644 --- a/assets/js/admin/editor.js +++ b/assets/js/admin/editor.js @@ -8,23 +8,6 @@ icon: false, type: 'menubutton', menu: [ - { - text: ed.getLang( 'sportspress.countdown' ), - menu: [ - { - text: ed.getLang( 'sportspress.manual' ), - onclick: function() { - editor.insertContent( '[countdown id="" live="1"]' ); - } - }, - { - text: ed.getLang( 'sportspress.auto' ), - onclick: function() { - editor.insertContent( '[countdown]' ); - } - } - ] - }, { text: ed.getLang( 'sportspress.event' ), menu: [ @@ -34,112 +17,74 @@ { text: ed.getLang( 'sportspress.details' ), onclick: function() { - editor.insertContent( '[event_details id=""]' ); + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.event' ) + ' - ' + ed.getLang( 'sportspress.details' ), 'admin-ajax.php?action=sportspress_event_details_shortcode&width=' + W + '&height=' + H ); } }, { text: ed.getLang( 'sportspress.results' ), onclick: function() { - editor.insertContent( '[event_results id=""]' ); + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.event' ) + ' - ' + ed.getLang( 'sportspress.results' ), 'admin-ajax.php?action=sportspress_event_results_shortcode&width=' + W + '&height=' + H ); } }, { text: ed.getLang( 'sportspress.performance' ), onclick: function() { - editor.insertContent( '[event_performance id=""]' ); + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.event' ) + ' - ' + ed.getLang( 'sportspress.performance' ), 'admin-ajax.php?action=sportspress_event_performance_shortcode&width=' + W + '&height=' + H ); } } ] }, + { + text: ed.getLang( 'sportspress.countdown' ), + onclick: function() { + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.event' ) + ' - ' + ed.getLang( 'sportspress.countdown' ), 'admin-ajax.php?action=sportspress_countdown_shortcode&width=' + W + '&height=' + H ); + } + }, { text: ed.getLang( 'sportspress.calendar' ), - menu: [ - { - text: ed.getLang( 'sportspress.select' ), onclick : function() { - // triggers the thickbox - var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; - W = W - 80; - H = H - 84; - tb_show( 'My WIndow POPUP Title', '#TB_inline?width=' + W + '&height=' + H + '&inlineId=sp_choose_event_calendar' ); - } - }, - { - text: ed.getLang( 'sportspress.manual' ), - onclick: function() { - editor.insertContent( '[event_calendar id="" status="default" initial="1" show_all_events_link="0"]' ); - } - }, - { - text: ed.getLang( 'sportspress.auto' ), - onclick: function() { - editor.insertContent( '[event_calendar]' ); - } - } - ] + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.event' ) + ' - ' + ed.getLang( 'sportspress.calendar' ), 'admin-ajax.php?action=sportspress_event_calendar_shortcode&width=' + W + '&height=' + H ); + } }, { text: ed.getLang( 'sportspress.list' ), - menu: [ - { - text: ed.getLang( 'sportspress.select' ), - onclick : function() { - // triggers the thickbox - var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; - W = W - 80; - H = H - 84; - tb_show( 'My WIndow POPUP Title', '#TB_inline?width=' + W + '&height=' + H + '&inlineId=sp_choose_event_list' ); - } - }, - { - text: ed.getLang( 'sportspress.manual' ), - onclick: function() { - editor.insertContent( '[event_list id="" status="default" show_all_events_link="0"]' ); - } - } - ] + onclick : function() { + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.event' ) + ' - ' + ed.getLang( 'sportspress.list' ), 'admin-ajax.php?action=sportspress_event_list_shortcode&width=' + W + '&height=' + H ); + } }, { text: ed.getLang( 'sportspress.blocks' ), - menu: [ - { - text: ed.getLang( 'sportspress.select' ), - onclick : function() { - // triggers the thickbox - var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; - W = W - 80; - H = H - 84; - tb_show( 'My WIndow POPUP Title', '#TB_inline?width=' + W + '&height=' + H + '&inlineId=sp_choose_event_blocks' ); - } - }, - { - text: ed.getLang( 'sportspress.manual' ), - onclick: function() { - editor.insertContent( '[event_blocks id="" status="default" show_all_events_link="0"]' ); - } - } - ] - } - ] - }, - { - text: ed.getLang( 'sportspress.league_table' ), - menu: [ - { - text: ed.getLang( 'sportspress.select' ), - onclick : function() { - // triggers the thickbox - var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; - W = W - 80; - H = H - 84; - tb_show( 'My WIndow POPUP Title', '#TB_inline?width=' + W + '&height=' + H + '&inlineId=sp_choose_league_table' ); - } - }, - { - text: ed.getLang( 'sportspress.manual' ), - onclick: function() { - editor.insertContent( '[league_table id="" number="-1" show_team_logo="1" link_posts="0" show_full_table_link="0"]' ); - } + onclick : function() { + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.event' ) + ' - ' + ed.getLang( 'sportspress.blocks' ), 'admin-ajax.php?action=sportspress_event_blocks_shortcode&width=' + W + '&height=' + H ); + } } ] }, @@ -152,60 +97,56 @@ { text: ed.getLang( 'sportspress.details' ), onclick: function() { - editor.insertContent( '[player_details id=""]' ); + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.player' ) + ' - ' + ed.getLang( 'sportspress.details' ), 'admin-ajax.php?action=sportspress_player_details_shortcode&width=' + W + '&height=' + H ); } }, { text: ed.getLang( 'sportspress.statistics' ), onclick: function() { - editor.insertContent( '[player_statistics id=""]' ); + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.player' ) + ' - ' + ed.getLang( 'sportspress.statistics' ), 'admin-ajax.php?action=sportspress_player_statistics_shortcode&width=' + W + '&height=' + H ); } } ] }, { text: ed.getLang( 'sportspress.list' ), - menu: [ - { - text: ed.getLang( 'sportspress.select' ), - onclick : function() { - // triggers the thickbox - var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; - W = W - 80; - H = H - 84; - tb_show( 'My WIndow POPUP Title', '#TB_inline?width=' + W + '&height=' + H + '&inlineId=sp_choose_player_list' ); - } - }, - { - text: ed.getLang( 'sportspress.manual' ), - onclick: function() { - editor.insertContent( '[player_list id="" number="-1" orderby="default" order="ASC" show_all_players_link="0"]' ); - } - } - ] + onclick : function() { + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.player' ) + ' - ' + ed.getLang( 'sportspress.list' ), 'admin-ajax.php?action=sportspress_player_list_shortcode&width=' + W + '&height=' + H ); + } }, { text: ed.getLang( 'sportspress.gallery' ), - menu: [ - { - text: ed.getLang( 'sportspress.select' ), - onclick : function() { - // triggers the thickbox - var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; - W = W - 80; - H = H - 84; - tb_show( 'My WIndow POPUP Title', '#TB_inline?width=' + W + '&height=' + H + '&inlineId=sp_choose_player_gallery' ); - } - }, - { - text: ed.getLang( 'sportspress.manual' ), - onclick: function() { - editor.insertContent( '[player_gallery id="" number="-1" columns="3" orderby="default" order="ASC" size="thumbnail" show_all_players_link="0"]' ); - } - } - ] + onclick : function() { + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.player' ) + ' - ' + ed.getLang( 'sportspress.gallery' ), 'admin-ajax.php?action=sportspress_player_gallery_shortcode&width=' + W + '&height=' + H ); + } } ] + }, + { + text: ed.getLang( 'sportspress.league_table' ), + onclick : function() { + // triggers the thickbox + var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.league_table' ), 'admin-ajax.php?action=sportspress_league_table_shortcode&width=' + W + '&height=' + H ); + } } ] }); diff --git a/includes/admin/class-sp-admin-assets.php b/includes/admin/class-sp-admin-assets.php index 7ec6b7c0..5584fe83 100644 --- a/includes/admin/class-sp-admin-assets.php +++ b/includes/admin/class-sp-admin-assets.php @@ -5,7 +5,7 @@ * @author ThemeBoy * @category Admin * @package SportsPress/Admin - * @version 1.1.6 + * @version 1.2 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly diff --git a/includes/admin/class-sp-admin-menus.php b/includes/admin/class-sp-admin-menus.php index b5eb7ee9..1976eb07 100644 --- a/includes/admin/class-sp-admin-menus.php +++ b/includes/admin/class-sp-admin-menus.php @@ -5,7 +5,7 @@ * @author ThemeBoy * @category Admin * @package SportsPress/Admin - * @version 1.1 + * @version 1.2 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly diff --git a/includes/admin/class-sp-admin-thickbox.php b/includes/admin/class-sp-admin-thickbox.php deleted file mode 100644 index 1a015a50..00000000 --- a/includes/admin/class-sp-admin-thickbox.php +++ /dev/null @@ -1,483 +0,0 @@ - - - - 'sp_calendar', - 'name' => 'id', - 'values' => 'ID', - ); - sp_dropdown_pages( $args ); - $calendar_dropdown = ob_get_clean(); - - ob_start(); - $args = array( - 'post_type' => 'sp_table', - 'name' => 'id', - 'values' => 'ID', - ); - sp_dropdown_pages( $args ); - $league_table_dropdown = ob_get_clean(); - - ob_start(); - $args = array( - 'post_type' => 'sp_list', - 'name' => 'id', - 'values' => 'ID', - ); - sp_dropdown_pages( $args ); - $player_list_dropdown = ob_get_clean(); - - ob_start(); - $args = array( - 'prepend_options' => array( - 'default' => __( 'Default', 'sportspress' ), - 'number' => __( 'Number', 'sportspress' ), - 'name' => __( 'Name', 'sportspress' ), - 'eventsplayed' => __( 'Played', 'sportspress' ) - ), - 'post_type' => array( 'sp_metric', 'sp_performance', 'sp_statistic' ), - 'name' => 'orderby', - 'id' => 'orderby', - 'values' => 'slug' - ); - sp_dropdown_pages( $args ); - $player_list_orderby_dropdown = ob_get_clean(); - ?> - - - - - - - - - - - - - nopriv + $ajax_events = array( + 'countdown_shortcode' => false, + 'event_details_shortcode' => false, + 'event_results_shortcode' => false, + 'event_performance_shortcode' => false, + 'event_calendar_shortcode' => false, + 'event_list_shortcode' => false, + 'event_blocks_shortcode' => false, + 'league_table_shortcode' => false, + 'player_details_shortcode' => false, + 'player_statistics_shortcode' => false, + 'player_list_shortcode' => false, + 'player_gallery_shortcode' => false, + ); + + foreach ( $ajax_events as $ajax_event => $nopriv ) { + add_action( 'wp_ajax_sportspress_' . $ajax_event, array( $this, $ajax_event ) ); + + if ( $nopriv ) { + add_action( 'wp_ajax_nopriv_sportspress_' . $ajax_event, array( $this, $ajax_event ) ); + } + } + } + + /** + * AJAX countdown shortcode + */ + public function countdown_shortcode() { + ?> +
+

+ +

+

+ +

+

+ +

+

+ + +

+
+ +
+

+ +

+

+ + +

+
+ +
+

+ +

+

+ + +

+
+ +
+

+ +

+

+ + +

+
+ +
+

+ +

+

+ +

+

+ +

+

+ + +

+
+ +
+

+ +

+

+ +

+

+ +

+

+ +

+

+ +

+

+
+ __( 'Event', 'sportspress' ), + 'teams' => __( 'Teams', 'sportspress' ), + 'time' => __( 'Time', 'sportspress' ), + 'venue' => __( 'Venue', 'sportspress' ), + 'article' => __( 'Article', 'sportspress' ), + ); + $field_name = 'columns[]'; + $field_id = 'columns'; + ?> + $label ): ?> + + +

+

+ +

+

+ + +

+
+ +
+

+ +

+

+ +

+

+ +

+

+ +

+

+ +

+

+ +

+

+ + +

+
+ +
+

+ +

+

+ +

+

+
+ 'sp_column', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' + ); + $the_columns = get_posts( $args ); + + $field_name = 'columns[]'; + $field_id = 'columns'; + ?> + + + +

+

+ +

+

+ +

+

+ + +

+
+ +
+

+ +

+

+ + +

+
+ +
+

+ +

+

+ + +

+
+ +
+

+ +

+

+ +

+

+
+ array( 'sp_metric', 'sp_performance', 'sp_statistic' ), + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' + ); + $the_columns = get_posts( $args ); + + $field_name = 'columns[]'; + $field_id = 'columns'; + ?> + + + +

+

+ +

+

+ +

+

+ +

+

+ + +

+
+ + + + + ajax_includes(); + } + if ( ! is_admin() || defined( 'DOING_AJAX' ) ) { $this->frontend_includes(); } @@ -225,6 +229,13 @@ final class SportsPress { include_once( 'includes/class-sp-wpml.php' ); } + /** + * Include required ajax files. + */ + public function ajax_includes() { + include_once( 'includes/class-sp-ajax.php' ); // Ajax functions for admin and the front-end + } + /** * Include required frontend files. */