Skip to content

Commit

Permalink
Restructure JS and uglification
Browse files Browse the repository at this point in the history
  • Loading branch information
tlovett1 committed Mar 13, 2017
1 parent 81f5007 commit 91945d9
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 155 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2

[*.{php,js,css,scss}]
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4
19 changes: 15 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ module.exports = function(grunt) {
updatePoFiles: true
}
}
}
});
},

grunt.loadNpmTasks('grunt-wp-i18n');
uglify: {
js: {
files: {
'assets/js/restricted-site-access.min.js': ['assets/js/src/restricted-site-access.js'],
}
}
}

});

grunt.loadNpmTasks( 'grunt-wp-i18n' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );

grunt.registerTask('i18n', ['makepot']);
grunt.registerTask( 'i18n', ['makepot'] );
grunt.registerTask( 'default', ['uglify:js'] );
};
1 change: 1 addition & 0 deletions assets/js/restricted-site-access.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 146 additions & 0 deletions assets/js/src/restricted-site-access.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/**
* 10up
* http://10up.com
*
* Copyright (c) 2013 10up, jakemgold
* Licensed under the GPLv2+ license.
*/
(function (window, $) {

'use strict';
var document = window.document;

var Cache = {
add_btn : '',
new_ip : '',
ip_list_wrap : '',
empty_ip : '',
restrict_radio : '',
table : '',
redirect_choice : '',
message_choice : '',
page_choice : '',
redirect_fields : '',
message_field : '',
page_field : ''
};

function init() {

Cache.add_btn = $( document.getElementById( 'addip' ) );
Cache.new_ip = document.getElementById( 'newip' );
Cache.ip_list_wrap = document.getElementById( 'ip_list' );
Cache.empty_ip = $( document.getElementById( 'ip_list_empty' ) );
Cache.restrict_radio = document.getElementById( 'blog-restricted' );
Cache.table = $( document.getElementById( 'rsa-send-to-login' ) ).closest( 'table' );
Cache.redirect_choice = document.getElementById( 'rsa-redirect-visitor' );
Cache.message_choice = document.getElementById( 'rsa-display-message' );
Cache.page_choice = document.getElementById( 'rsa-unblocked-page' );
Cache.redirect_fields = $( document.querySelectorAll( '.rsa_redirect_field' ) ).closest( 'tr' );
Cache.message_field = $( document.getElementById( 'rsa_message' ) ).closest( 'tr' );
Cache.page_field = $( document.getElementById( 'rsa_page' ) ).closest( 'tr' );

if ( ! document.getElementById( 'blog-restricted' ).checked ) {
Cache.table.hide();
}

if ( ! document.getElementById( 'rsa-redirect-visitor' ).checked ) {
Cache.redirect_fields.hide();
}

if ( ! document.getElementById( 'rsa-display-message' ).checked ) {
Cache.message_field.hide();
}

if ( ! document.getElementById( 'rsa-unblocked-page' ).checked ) {
Cache.page_field.hide();
}

$( document.querySelectorAll( '#rsa_handle_fields input' ) ).on('change',function(){

if ( Cache.redirect_choice.checked ) {
Cache.redirect_fields.show();
} else {
Cache.redirect_fields.hide();
}

if ( Cache.message_choice.checked ) {
Cache.message_field.show();
} else {
Cache.message_field.hide();
}

if ( Cache.page_choice.checked ) {
Cache.page_field.show();
} else {
Cache.page_field.hide();
}

});

$( document.querySelectorAll( '.option-site-visibility input' ) ).on('change',function(){
if ( Cache.restrict_radio.checked ) {
Cache.table.show();
} else {
Cache.table.hide();
}
});

Cache.add_btn.on('click',function(){
add_ip( Cache.new_ip.value );
});

var myip_btn = document.getElementById( 'rsa_myip' );
if ( null !== myip_btn ) {
$( myip_btn ).on('click',function(){
add_ip( $( this ).data( 'myip' ) );
});
}

$( Cache.ip_list_wrap ).on('click', '.remove_btn', function(){
$( this.parentNode ).slideUp( 250, function(){ $( this ).remove(); } );
});

}

function add_ip( ip ) {
if ( $.trim( ip ) == '' ) {
return false;
}

var shake_speed = 600;

Cache.add_btn.attr( 'disabled', 'disabled' );
var ip_list = $( document.querySelectorAll( '#ip_list input' ) );

for ( var i = 0, l = ip_list.length; i < ip_list.length; i++ ) {
if ( ip_list[i].value == ip ) {
$( ip_list[i] ).parent().effect( 'shake', shake_speed );
Cache.add_btn.removeAttr( 'disabled' );
return false;
}
}

jQuery.post( ajaxurl, { action: 'rsa_ip_check', 'ip_address': ip }, function(response) {
if ( response ) {
$( Cache.new_ip.parentNode ).effect( 'shake', shake_speed );
Cache.add_btn.removeAttr( 'disabled' );
return false;
} else {
var new_ip = Cache.empty_ip.clone().appendTo( Cache.ip_list_wrap );
new_ip.children( 'input' ).val( ip );
new_ip.removeAttr( 'id' ).slideDown( 250 );

if ( ip == Cache.new_ip.value ) {
$( Cache.new_ip ).val( '' );
}
Cache.add_btn.removeAttr( 'disabled' );

return true;
}
} );
}

init();

})(window,jQuery);
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

{
"name": "restricted-site-access",
"description": "Limit access to visitors who are logged in or allowed by IP addresses. Includes many options for handling blocked visitors.",
"dependencies": {},
"dependencies": {
"grunt-contrib-uglify": "^2.2.0"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-wp-i18n": "^0.5.4"
Expand Down
146 changes: 0 additions & 146 deletions restricted-site-access.dev.js

This file was deleted.

1 change: 0 additions & 1 deletion restricted-site-access.js

This file was deleted.

11 changes: 9 additions & 2 deletions restricted_site_access.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* License: GPLv2 or later
*/

define( 'RSA_VERSION', '5.2' );

class Restricted_Site_Access {

private static $rsa_options, $basename;
Expand Down Expand Up @@ -266,8 +268,13 @@ public static function privacy_on_link_title( $text ) {
* Loads needed scripts and assets on the Reading page
*/
public static function load_options_page() {
$dev = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.dev' : '';
wp_enqueue_script( 'restricted-site-access', plugin_dir_url( __FILE__ ) . 'restricted-site-access' . $dev . '.js', array( 'jquery-effects-shake' ), '5.1', true );
$js_path = plugin_dir_url( __FILE__ ) . '/assets/js/restricted-site-access.min.js';

if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
$js_path = plugin_dir_url( __FILE__ ) . '/assets/js/src/restricted-site-access.js';
}

wp_enqueue_script( 'restricted-site-access', $js_path, array( 'jquery-effects-shake' ), RSA_VERSION, true );

add_action( 'admin_notices', array( __CLASS__, 'admin_notice' ) );
add_action( 'admin_head', array( __CLASS__, 'admin_head' ) );
Expand Down

0 comments on commit 91945d9

Please sign in to comment.