Skip to content
This repository has been archived by the owner on Jun 14, 2022. It is now read-only.

Commit

Permalink
no longer using __CLASS__
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Houghton committed Jan 29, 2014
1 parent 936d779 commit 12bdf45
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
51 changes: 23 additions & 28 deletions Splitdown.php
Expand Up @@ -24,43 +24,38 @@ static function get_instance(){


public function __construct(){
add_action( 'init', array( __CLASS__, 'remove_editor' ), 0, 10 );
add_action( 'edit_form_after_editor', array( __CLASS__, 'load_editor' ), 0, 11 );
add_action( 'init', array( $this, 'remove_editor' ), 0, 10 );
add_action( 'edit_form_after_editor', array( $this, 'load_editor' ), 0, 11 );
add_action( 'admin_menu', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_menu', array( __CLASS__, 'load_style' ) );
add_action( 'save_post', array( __CLASS__, 'save' ) );
add_action( 'edit_post', array( __CLASS__, 'save' ) );
add_action( 'admin_init', array( __CLASS__, 'add_options' ) );
add_action( 'admin_menu', array( $this, 'load_style' ) );
add_action( 'save_post', array( $this, 'save' ) );
add_action( 'edit_post', array( $this, 'save' ) );
add_action( 'admin_init', array( $this, 'add_options' ) );
}


public function enqueue_scripts(){

// Only enqueue scripts on editor pages
global $post;
if ($post) {

$extensions = get_option( 'splitdown_extensions', array() );

wp_enqueue_script( 'showdown', plugins_url( '/js/showdown/compressed/showdown.js', __FILE__ ), array(), '0.1', true );
wp_enqueue_script( 'markdown-parser', plugins_url( '/js/html2markdown/markdown_dom_parser.js', __FILE__ ) );
wp_enqueue_script( 'markdown-renderer', plugins_url( '/js/html2markdown/html2markdown.js', __FILE__ ) );
$extensions = get_option( 'splitdown_extensions', array() );

if( is_array( $extensions ) ){
wp_enqueue_script( 'showdown', plugins_url( '/js/showdown/compressed/showdown.js', __FILE__ ), array(), '0.1', true );
wp_enqueue_script( 'markdown-parser', plugins_url( '/js/html2markdown/markdown_dom_parser.js', __FILE__ ) );
wp_enqueue_script( 'markdown-renderer', plugins_url( '/js/html2markdown/html2markdown.js', __FILE__ ) );

foreach( $extensions as $extension ){
wp_enqueue_script( "showdown-{$extension}", plugins_url( "/js/showdown/compressed/extensions/{$extension}", __FILE__ ) );
}

}
if( is_array( $extensions ) ){

wp_enqueue_script( 'splitdown', plugins_url( '/js/splitdown.js', __FILE__ ), array( 'jquery' ) );
foreach( $extensions as $extension ){
wp_enqueue_script( "showdown-{$extension}", plugins_url( "/js/showdown/compressed/extensions/{$extension}", __FILE__ ) );
}

}

// Need for distraction free mode
wp_enqueue_script('screenfull', '//cdnjs.cloudflare.com/ajax/libs/screenfull.js/1.0.4/screenfull.min.js', array(), '3', true);
wp_enqueue_script( 'splitdown', plugins_url( '/js/splitdown.js', __FILE__ ), array( 'jquery' ) );

// Need for distraction free mode
wp_enqueue_script('screenfull', '//cdnjs.cloudflare.com/ajax/libs/screenfull.js/1.0.4/screenfull.min.js', array(), '3', true);

}

}

Expand Down Expand Up @@ -198,12 +193,12 @@ private static function _get_showdown_extensions(){

public static function options_field_showdown_extensions(){
$current = get_option( 'splitdown_extensions', array() );
$extensions = static::_get_showdown_extensions();
$extensions = static::_get_showdown_extensions();

if( empty( $current ) )
$current = array();
if( empty( $current ) )
$current = array();

$out = "";
$out = "";

foreach( $extensions as $extension ){
$vals = array(
Expand Down
1 change: 0 additions & 1 deletion css/style.css
Expand Up @@ -26,7 +26,6 @@ body { min-height: 100%; }
}

.splitdown-wrapper {
background: transparent;
margin-top: 30px;
width: 100%;
height: 100%;
Expand Down
21 changes: 13 additions & 8 deletions js/splitdown.js
Expand Up @@ -2,32 +2,37 @@ var Splitdown;

Splitdown = {
source: '',
desination: '',
destination: '',
converter: '',

init: function () {
Splitdown.source = jQuery( '#content' );
Splitdown.desination = jQuery( '#splitdown-preview' );
Splitdown.destination = jQuery( '#splitdown-preview' );

Splitdown.converter = new Showdown.converter();
// Check to see if the source and destination exist
if (!Splitdown.source.length || !Splitdown.destination.length) {
return;
}

Splitdown.converter = new Showdown.converter();

this.source.on( 'keyup', this.update );

jQuery( '#splitdown-dmode').on( 'click', this.dmode );

jQuery(document).on(screenfull.raw.fullscreenchange, this.dmodeChange );

//only convert html to markdown when there is a preview but no markdown
if( this.source.text().length == 0 && this.desination.html() != 0 ){
this.source.val( html2markdown( this.desination.html() ) );
if( this.source.text().length == 0 && this.destination.html() != 0 ){
this.source.val( html2markdown( this.destination.html() ) );
}

jQuery(document).ajaxSuccess( this.ajaxIntercept );

// Update at the start to generate the HTML (otherwise when we save after
// no changes, the_content() will be blank!)
this.update();

},

ajaxIntercept: function( event, xhr, settings){
Expand Down Expand Up @@ -56,13 +61,13 @@ Splitdown = {
},

update: function () {
Splitdown.desination.html(
Splitdown.destination.html(
Splitdown.converter.makeHtml(
Splitdown.source.val()
)
);

jQuery( '#splitdown-markdown').val( Splitdown.desination.html() );
jQuery( '#splitdown-markdown').val( Splitdown.destination.html() );
},

dmode: function() {
Expand Down

0 comments on commit 12bdf45

Please sign in to comment.