Skip to content

Commit

Permalink
WPFAS: Update to latest revisions.
Browse files Browse the repository at this point in the history
- Fix taxonomy JS for WordPress 4.7.
- Remove postbox JS from enqueuing. Drag-n-drop metaboxes are not necessary when frontend editing.
- Change the body class attribute to tell that JS is being used.
  • Loading branch information
r-a-y committed Dec 22, 2016
1 parent 7f20978 commit 75b3411
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions includes/wp-frontend-admin-screen/wp-frontend-admin-screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ public function screen() {

// redirect
if ( empty( $this->args['redirect_root'] ) ) {
$url = add_query_arg(
array( 'p' => $post_id ),
get_home_url()
);
$url = get_permalink ( $post_id );
} else {
// refetch post to grab slug
$post = get_post( $post_id );
Expand Down Expand Up @@ -274,6 +271,10 @@ public function display() {
$this->before_display();
?>

<script type="text/javascript">
document.body.className = document.body.className.replace( 'no-js', 'js' );
</script>

<h2 class="admin-page-title"><?php esc_html_e( $title ); ?></h2>

<div id="post-body">
Expand Down Expand Up @@ -438,14 +439,21 @@ public function enqueue_editor_scripts() {
// @see wp_default_scripts()
$suffix = SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script( 'word-count', admin_url( "js/word-count$suffix.js" ), array( 'jquery' ), false, 1 );
wp_enqueue_script( 'postbox', admin_url( "js/postbox$suffix.js" ), array('jquery-ui-sortable'), false, 1 );
wp_enqueue_script( 'post', admin_url( "js/post$suffix.js" ), array( 'suggest', 'wp-lists', 'postbox' ), false, 1 );
wp_enqueue_script( 'link', admin_url( "js/link$suffix.js" ), array( 'wp-lists', 'postbox' ), false, 1 );
wp_enqueue_script( 'post', admin_url( "js/post$suffix.js" ), array( 'suggest', 'wp-lists' ), false, 1 );
wp_enqueue_script( 'link', admin_url( "js/link$suffix.js" ), array( 'wp-lists' ), false, 1 );
//wp_enqueue_script( 'autosave' );

// yay, different WP versions!
if ( version_compare( $wp_version, '4.1.999') >= 0 ) {
wp_enqueue_script( 'tags-box', admin_url( "js/tags-box$suffix.js" ), array( 'jquery', 'suggest' ), false, 1 );
$suggest = 'suggest';
if ( version_compare( $wp_version, '4.6.999' >= 0 ) ) {
$suggest = 'tags-suggest';
}
wp_enqueue_script( 'tags-box', admin_url( "js/tags-box$suffix.js" ), array( 'jquery', $suggest ), false, 1 );
}
if ( version_compare( $wp_version, '4.6.999' >= 0 ) ) {
wp_enqueue_script( 'wp-a11y', includes_url( "js/wp-a11y$suffix.js" ), array( 'jquery' ), false, 1 );
wp_enqueue_script( 'tags-suggest', admin_url( "js/tags-suggest$suffix.js" ), array( 'jquery-ui-autocomplete', 'wp-a11y' ), false, 1 );
}

if ( wp_is_mobile() ) {
Expand All @@ -464,6 +472,14 @@ public function enqueue_editor_scripts() {
wp_localize_script( 'tags-box', 'tagsBoxL10n', array(
'tagDelimiter' => $this->strings['tag_delimiter'],
) );
wp_localize_script( 'tags-suggest', 'tagsSuggestL10n', array(
'tagDelimiter' => $this->strings['tag_delimiter'],
'removeTerm' => __( 'Remove term:' ),
'termSelected' => __( 'Term selected.' ),
'termAdded' => __( 'Term added.' ),
'termRemoved' => __( 'Term removed.' ),
) );

wp_localize_script( 'word-count', 'wordCountL10n', array(
'type' => 'characters' == $this->strings( 'words' ) ? 'c' : 'w',
) );
Expand Down Expand Up @@ -507,12 +523,16 @@ public function enqueue_editor_scripts() {
}

// set the 'pagenow' JS variable to emulate wp-admin area
// postboxes variable abstraction is necessary due to post.js calling for it.
// @see /wp-admin/admin-header.php
?>

<script type="text/javascript">
var pagenow = '<?php echo self::$post_type; ?>',
typenow = '<?php echo self::$post_type; ?>';
typenow = '<?php echo self::$post_type; ?>',
postboxes = new Object();

postboxes.add_postbox_toggles = function() {}
</script>

<?php
Expand Down

0 comments on commit 75b3411

Please sign in to comment.