Skip to content

Instantly share code, notes, and snippets.

@brandwaffle
Created December 27, 2011 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandwaffle/1525319 to your computer and use it in GitHub Desktop.
Save brandwaffle/1525319 to your computer and use it in GitHub Desktop.
P2 jQuery cleanup diff
Index: inc/js.php
===================================================================
--- inc/js.php (revision 18733)
+++ inc/js.php (working copy)
@@ -239,26 +239,26 @@
<script type="text/javascript">
/* <![CDATA[ */
- jQuery(document).ready( function() {
+ jQuery(document).ready( function($) {
function hideComments() {
- jQuery('.commentlist').hide();
- jQuery('.discussion').show();
+ $('.commentlist').hide();
+ $('.discussion').show();
}
function showComments() {
- jQuery('.commentlist').show();
- jQuery('.discussion').hide();
+ $('.commentlist').show();
+ $('.discussion').hide();
}
<?php if ( (int) $hide_threads ) : ?>
hideComments();
<?php endif; ?>
- jQuery("#togglecomments").click( function(){
- if (jQuery('.commentlist').css('display') == 'none') {
+ $("#togglecomments").click( function(e){
+ e.preventDefault();
+ if ($('.commentlist').css('display') == 'none') {
showComments();
} else {
hideComments();
}
- return false;
});
});
/* ]]> */
Index: inc/options-page.php
===================================================================
--- inc/options-page.php (revision 18733)
+++ inc/options-page.php (working copy)
@@ -197,63 +197,65 @@
/* <![CDATA[ */
var farbtastic;
- function pickColor(color) {
- jQuery('#p2_background_color_hex').val(color);
- farbtastic.setColor(color);
- }
+ jQuery(document).ready(function($) {
+ //closure methods
+ function pickColor(color) {
+ $('#p2_background_color_hex').val(color);
+ farbtastic.setColor(color);
+ }
- jQuery(document).ready(function() {
- jQuery('#pickcolor').click(function() {
- jQuery('#colorPickerDiv').show();
+ function colorDefault() {
+ pickColor( '#<?php echo HEADER_TEXTCOLOR; ?>' );
+ }
+
+ function hide_picker(what) {
+ var update = false;
+ $('#colorPickerDiv').each(function(){
+ var id = $(this).attr( 'id' );
+ if (id == what) {
+ return;
+ }
+ var display = $(this).css( 'display' );
+ if (display == 'block' ) {
+ $(this).fadeOut(2);
+ }
+ });
+ }
+
+ function toggle_text(force) {
+ if ($('#textcolor').val() == 'blank' ) {
+ //Show text
+ $(buttons.toString()).show();
+ $('#textcolor').val( '<?php echo HEADER_TEXTCOLOR; ?>' );
+ $('#hidetext').val( '<?php _e( 'Hide Text', 'p2' ); ?>' );
+ }
+ else {
+ //Hide text
+ $(buttons.toString()).hide();
+ $('#textcolor').val( 'blank' );
+ $('#hidetext').val( '<?php _e( 'Show Text', 'p2' ); ?>' );
+ }
+ }
+
+ //closure logic
+ $('#pickcolor').click(function() {
+ $('#colorPickerDiv').show();
});
- jQuery('#hidetext' ).click(function() {
+ $('#hidetext' ).click(function() {
toggle_text();
});
- farbtastic = jQuery.farbtastic( '#colorPickerDiv', function(color) { pickColor(color); });
+ farbtastic = $.farbtastic( '#colorPickerDiv', function(color) { pickColor(color); });
+
+ $(document).mousedown(function(){
+ // Make the picker disappear, since we're using it in an independant div
+ hide_picker();
+ });
});
-
- jQuery(document).mousedown(function(){
- // Make the picker disappear, since we're using it in an independant div
- hide_picker();
- });
-
- function colorDefault() {
- pickColor( '#<?php echo HEADER_TEXTCOLOR; ?>' );
- }
-
- function hide_picker(what) {
- var update = false;
- jQuery('#colorPickerDiv').each(function(){
- var id = jQuery(this).attr( 'id' );
- if (id == what) {
- return;
- }
- var display = jQuery(this).css( 'display' );
- if (display == 'block' ) {
- jQuery(this).fadeOut(2);
- }
- });
- }
-
- function toggle_text(force) {
- if (jQuery('#textcolor').val() == 'blank' ) {
- //Show text
- jQuery(buttons.toString()).show();
- jQuery('#textcolor').val( '<?php echo HEADER_TEXTCOLOR; ?>' );
- jQuery('#hidetext').val( '<?php _e( 'Hide Text', 'p2' ); ?>' );
- }
- else {
- //Hide text
- jQuery(buttons.toString()).hide();
- jQuery('#textcolor').val( 'blank' );
- jQuery('#hidetext').val( '<?php _e( 'Show Text', 'p2' ); ?>' );
- }
- }
/* ]]> */
</script>
<?php
}
-}
\ No newline at end of file
+}
Index: js/p2.js
===================================================================
--- js/p2.js (revision 18733)
+++ js/p2.js (working copy)
@@ -9,20 +9,20 @@
// Overload global send_to_editor media function.
send_to_editor = function( media ) {
- if ( jQuery('textarea#posttext').length ) {
- jQuery('textarea#posttext').val( jQuery('textarea#posttext').val() + media );
+ if ( $('textarea#posttext').length ) {
+ $('textarea#posttext').val( $('textarea#posttext').val() + media );
tb_remove();
}
};
// Live events can be bound before $(document).ready fires.
-jQuery('#comment-submit').live( 'click', function() {
+$('#comment-submit').live( 'click', function() {
if (loggedin == true)
window.onbeforeunload = null;
});
window.onbeforeunload = function (e) {
- if (jQuery('#posttext').val() || jQuery('#comment').val()) {
+ if ($('#posttext').val() || $('#comment').val()) {
var e = e || window.event;
if (e) { // For IE and Firefox
e.returnValue = p2txt.unsaved_changes;
@@ -280,7 +280,7 @@
var post_subscribe = ( $('#post_subscribe').prop('checked') ) ? 'post_subscribe' : 'false';
var posttext = $.trim($('#posttext').val());
- if(jQuery('.no-posts')) jQuery('.no-posts').hide();
+ if($('.no-posts')) $('.no-posts').hide();
if ("" == posttext) {
$("label#posttext_error").text('This field is required').show().focus();
@@ -605,17 +605,17 @@
this.value = text;
}
}
- jQuery(input).focus(onFocus).blur(onBlur);
+ $(input).focus(onFocus).blur(onBlur);
onBlur.call(input);
}
- jQuery.getJSON(ajaxUrl, {action: 'get_post', _inline_edit: nonce, post_ID: 'content-' + postId}, function(post) {
- var jqe = jQuery(element);
+ $.getJSON(ajaxUrl, {action: 'get_post', _inline_edit: nonce, post_ID: 'content-' + postId}, function(post) {
+ var jqe = $(element);
jqe.addClass('inlineediting');
jqe.find('.tags').css({display: 'none'});
jqe.find('.postcontent > *').hide();
if (post.type == 'page') {
- jQuery('#main h2').first().hide();
+ $('#main h2').first().hide();
}
var postContent = jqe.find('.postcontent');
@@ -686,14 +686,14 @@
jqe.find('.postcontent > *').show();
jqe.removeClass('inlineediting');
if (post.type == 'page') {
- jQuery('#main h2').first().show();
+ $('#main h2').first().show();
}
}
var buttonsDiv = document.createElement('div');
buttonsDiv.className = 'buttons';
var saveButton = document.createElement('button');
saveButton.innerHTML = p2txt.save;
- jQuery(saveButton).click(function() {
+ $(saveButton).click(function() {
var tags = ! tagsInput || tagsInput.value == p2txt.tagit ? '' : tagsInput.value;
var args = {
action:'save_post',
@@ -709,7 +709,7 @@
args.citation = citationInput.value == p2txt.citation ? '' : citationInput.value;
}
- jQuery.post(
+ $.post(
ajaxUrl,
args,
function(result) {
@@ -723,7 +723,7 @@
jqe.find('.postcontent').append(result.content);
}
if (post.type == 'page') {
- jQuery('#main h2').first().html(result.title);
+ $('#main h2').first().html(result.title);
} else {
jqe.find('span.tags').html(result.tags);
if (!isSingle) {
@@ -739,7 +739,7 @@
});
var cancelButton = document.createElement('button');
cancelButton.innerHTML = p2txt.cancel;
- jQuery(cancelButton).click(tearDownEditor);
+ $(cancelButton).click(tearDownEditor);
buttonsDiv.appendChild(saveButton);
buttonsDiv.appendChild(cancelButton);
bottomDiv.appendChild(buttonsDiv);
@@ -792,7 +792,7 @@
var thisPostEditArea;
if (inlineEditPosts != 0 && isUserLoggedIn) {
thisPostEditArea = $(element).children('div.postcontent').eq(0);
- jQuery(element).find('a.edit-post-link:first').click(
+ $(element).find('a.edit-post-link:first').click(
function(e) {
var postId = this.rel;
inlineEditPost(postId, element);
@@ -962,8 +962,8 @@
});
// Bind actions to comments and posts
- jQuery('body .post, body .page').each(function() { bindActions(this, 'post'); });
- jQuery('body .comment').each(function() { bindActions(this, 'comment'); });
+ $('body .post, body .page').each(function() { bindActions(this, 'post'); });
+ $('body .comment').each(function() { bindActions(this, 'comment'); });
$('#cancel-comment-reply-link').click(function() {
Index: post-form.php
===================================================================
--- post-form.php (revision 18733)
+++ post-form.php (working copy)
@@ -7,19 +7,19 @@
<script type="text/javascript">
/* <![CDATA[ */
jQuery(document).ready(function($) {
- jQuery('#post_cat').val($('#post-types a.selected').attr('id'));
+ $('#post_cat').val($('#post-types a.selected').attr('id'));
$('#post-types a').click(function(e) {
- jQuery('.post-input').hide();
+ e.preventDefault();
+ $('.post-input').hide();
$('#post-types a').removeClass('selected');
- jQuery(this).addClass('selected');
+ $(this).addClass('selected');
if ($(this).attr('id') == 'post') {
- jQuery('#posttitle').val("<?php echo esc_js( __('Post Title', 'p2') ); ?>");
+ $('#posttitle').val("<?php echo esc_js( __('Post Title', 'p2') ); ?>");
} else {
- jQuery('#posttitle').val('');
+ $('#posttitle').val('');
}
- jQuery('#postbox-type-' + $(this).attr('id')).show();
- jQuery('#post_cat').val($(this).attr('id'));
- return false;
+ $('#postbox-type-' + $(this).attr('id')).show();
+ $('#post_cat').val($(this).attr('id'));
});
});
/* ]]> */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment