Skip to content

Commit

Permalink
Make the Javascript a common file, rather than lightbox specific
Browse files Browse the repository at this point in the history
  • Loading branch information
Viper007Bond committed Apr 21, 2012
1 parent 622d7ba commit c8bb2e5
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 101 deletions.
99 changes: 99 additions & 0 deletions developer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
function a8c_developer_lightbox() {
(function($){
function make_colorbox( href, transition ) {
$.colorbox({
inline: true,
href: href,
title: a8c_developer_i18n.lightbox_title,
innerWidth: 500,
maxHeight: '100%',
transition: transition
});
}

make_colorbox( '#a8c-developer-setup-dialog-step-1', 'none' );

$('#a8c-developer-setup-dialog-step-1-form').submit( function(e) {
var form = this;

$('#a8c-developer-setup-dialog-step-1-submit').val( a8c_developer_i18n.saving );

if ( 'yes' != a8c_developer_i18n.go_to_step_2 )
return;

e.preventDefault();

$.post( ajaxurl, $(form).serialize() )
.success( function( result ) {
// If there was an error with the AJAX save, then do a normal POST
if ( '-1' == result ) {
location.href = 'options-general.php?page=' + a8c_developer_i18n.settings_slug + '&a8cdev_errorsaving=1';
return;
}

// AJAX says no step 2 needed, so head to the settings page
if ( 'redirect' == result ) {
location.href = 'options-general.php?page=' + a8c_developer_i18n.settings_slug + '&updated=1';
return;
}

// Display the AJAX reponse
$('#a8c-developer-setup-dialog-step-2').html( result );
make_colorbox( '#a8c-developer-setup-dialog-step-2' );
})
;
});
})(jQuery);
}

function a8c_developer_bind_events() {
(function($){
$('.a8c_developer_button_install').click( function() {
var button = this;

$(button).html( a8c_developer_i18n.installing );

$.post( ajaxurl, {
'action': 'a8c_developer_install_plugin',
'_ajax_nonce': $(button).attr('data-nonce'),
'plugin_slug': $(button).attr('data-pluginslug')
} )
.success( function( result ) {
if ( '1' == result ) {
$(button).html( a8c_developer_i18n.installed );
$(button).unbind('click').prop('disabled', true);
} else {
$(button).html( a8c_developer_i18n.error );
}
})
.error( function() {
$(button).html( a8c_developer_i18n.error );
})
;
});

$('.a8c_developer_button_activate').click( function() {
var button = this;

$(button).html( a8c_developer_i18n.activating );

$.post( ajaxurl, {
'action': 'a8c_developer_activate_plugin',
'_ajax_nonce': $(button).attr('data-nonce'),
'path': $(button).attr('data-path')
} )
.success( function( result ) {
if ( '1' == result ) {
$(button).html( a8c_developer_i18n.activated );
$(button).unbind('click').prop('disabled', true);
} else {
$(button).html( a8c_developer_i18n.error );
}
})
.error( function() {
$(button).html( a8c_developer_i18n.error );
})
;
});
})(jQuery);
}
9 changes: 5 additions & 4 deletions developer.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function admin_init() {
register_setting( $this->option_name, $this->option_name, array( &$this, 'settings_validate' ) );


wp_register_script( 'a8c-developer-lightbox', plugins_url( 'js/lightbox.js', __FILE__ ), array( 'jquery' ), $this->version );
wp_register_script( 'a8c-developer', plugins_url( 'developer.js', __FILE__ ), array( 'jquery' ), $this->version );
$strings = array(
'settings_slug' => $this->settings_page_slug,
'go_to_step_2' => ( current_user_can( 'install_plugins' ) && current_user_can( 'activate_plugins' ) && 'direct' == get_filesystem_method() ) ? 'yes' : 'no',
Expand All @@ -136,9 +136,9 @@ public function admin_init() {
'activated' => __( 'Activated', 'a8c-developer' ),
'error' => __( 'Error!', 'a8c-developer' ),
);
wp_localize_script( 'a8c-developer-lightbox', 'a8c_developer_i18n', $strings );
wp_localize_script( 'a8c-developer', 'a8c_developer_i18n', $strings );

wp_register_style( 'a8c-developer', plugins_url( 'css/developer.css', __FILE__ ), array(), $this->version );
wp_register_style( 'a8c-developer', plugins_url( 'developer.css', __FILE__ ), array(), $this->version );


// Handle the submission of the lightbox form if step 2 won't be shown
Expand Down Expand Up @@ -180,7 +180,7 @@ public function load_lightbox_script_and_styles() {
wp_enqueue_script( 'colorbox', plugins_url( 'colorbox/jquery.colorbox-min.js', __FILE__ ), array( 'jquery' ), '1.3.19' );
wp_enqueue_style( 'a8c-developer-colorbox', plugins_url( 'colorbox/colorbox.css', __FILE__ ), array(), '1.3.19' );

wp_enqueue_script( 'a8c-developer-lightbox' );
wp_enqueue_script( 'a8c-developer' );
wp_enqueue_style( 'a8c-developer' );
}

Expand Down Expand Up @@ -210,6 +210,7 @@ public function output_setup_box_html() {
</div>
</div>

<script type="text/javascript">a8c_developer_lightbox();</script>
<?php
}

Expand Down
97 changes: 0 additions & 97 deletions lightbox.js

This file was deleted.

0 comments on commit c8bb2e5

Please sign in to comment.