Refactoring PHP and JavaScript codes

This commit is contained in:
attosoft committed 2012-05-25 14:56:25 +00:00
1 parent 8b0d7200ee
commit 9e12eef401
3 files changed
+25 -33

No files matched your search

+7 -2
View File
@@ -817,7 +817,7 @@ class auto_thickbox_options {
}
/**
* XXX: disabled() function is from WordPress 3.0
* XXX: disabled() function is defined from WordPress 3.0
* @see /wp-includes/general-template.php
*/
function disabled( $disabled, $current = true, $echo = true ) {
@@ -830,6 +830,11 @@ class auto_thickbox_options {
if ( $echo ) echo $result;
return $result;
}
/**
* XXX: $current with default value and $echo is defined from WordPress 2.8
* @see /wp-admin/includes/template.php
* @see /wp-includes/general-template.php (since 3.0)
*/
function checked( $checked, $current = true, $echo = true ) {
if ( version_compare('2.8', get_bloginfo('version')) > 0 )
checked( $checked, $current );
@@ -841,7 +846,7 @@ class auto_thickbox_options {
function esc_attr( $text ) {
echo function_exists( 'esc_attr' ) ? esc_attr( $text ) : attribute_escape( $text );
}
function esc_attr_e( $text, $domain ) {
function esc_attr_e( $text, $domain = 'default' ) {
if (function_exists( 'esc_attr_e' ))
esc_attr_e( $text, $domain );
else
+4 -8
View File
@@ -12,19 +12,15 @@ jQuery(function($) {
var text = $(this).prevAll(".colortext");
var checkbox = $(this).prevAll("label").children("input:checkbox");
var preview = $(this).prevAll(".colorpreview");
var first = true;
var fb = $.farbtastic(this, function(color) {
if (first) {
first = false;
return;
}
var fb = $.farbtastic(this);
if (text.val()[0] == '#') fb.setColor(text.val()); // color in hex
preview.css("backgroundColor", text.val());
fb.linkTo(function(color) {
text.val(color);
preview.css("backgroundColor", color);
text.parent().find(":disabled").removeAttr("disabled");
checkbox.filter(":checked").removeAttr("checked");
});
if (text.val()[0] == '#') fb.setColor(text.val()); // color in hex
preview.css("backgroundColor", text.val());
});
$(".pickcolor").click(function() { $(this).nextAll(".colorpicker").show(); return false; });
$(document).mousedown(function() { $(".colorpicker:visible").hide(); });
+14 -23
View File
@@ -89,21 +89,7 @@ class auto_thickbox {
|| ($this->options['thickbox_target'] == 'off' && !empty($anchor['attr']['target'])) )
return $anchor;
if ( !$anchor['attr']['class'] ) {
$anchor['attr']['class'][] = 'thickbox';
$anchor['attr']['class'][] = 'no_icon';
} else {
$no_thickbox_found;
foreach ( explode(' ', trim($this->options['no_thickbox'])) as $no_thickbox ) {
$no_thickbox_found = in_array($no_thickbox, $anchor['attr']['class']);
if ( $no_thickbox_found )
break;
}
if ( !in_array('thickbox', $anchor['attr']['class']) && !$no_thickbox_found )
$anchor['attr']['class'][] = 'thickbox';
if ( !in_array('no_icon', $anchor['attr']['class']) && !in_array('noicon', $anchor['attr']['class']) )
$anchor['attr']['class'][] = 'no_icon';
}
$anchor = $this->add_thickbox_class($anchor);
if ( $this->options['thickbox_style'] == 'gallery' && in_the_loop() && !$anchor['attr']['rel'] )
$anchor['attr']['rel'][] = 'gallery-' . get_the_ID();
@@ -608,52 +594,54 @@ SCRIPT;
delete_option('thickbox_res');
}
$updateOption = false;
// XXX: transition code for v0.6 or earlier
if (isset($this->options['thickbox_res'])) {
$this->options['builtin_res'] = $this->options['thickbox_res'] == 'unload' ? 'on' : 'off';
unset($this->options['thickbox_res']);
update_option('auto-thickbox-plus', $this->options);
$updateOption = true;
}
// XXX: transition code for between v1.1 and v1.2
if (isset($this->options['cap_position'])) {
$this->options['position_cap'] = $this->options['cap_position'];
unset($this->options['cap_position']);
update_option('auto-thickbox-plus', $this->options);
$updateOption = true;
}
// XXX: transition code for v1.1 or earlier
if (isset($this->options['bgcolor_win'])) {
$this->options['bgcolor_img'] = $this->options['bgcolor_win'];
unset($this->options['bgcolor_win']);
update_option('auto-thickbox-plus', $this->options);
$updateOption = true;
}
// XXX: transition code for v1.5 or earlier
if ($this->options['thickbox_text'] == 'auto' || $this->options['thickbox_text'] == 'manual') {
$this->options['thickbox_text'] = $this->options['thickbox_text'] == 'auto' ? 'on' : 'off';
update_option('auto-thickbox-plus', $this->options);
$updateOption = true;
}
if (!$this->is_default_options('border_win') && $this->options['border_win'] != 'none') {
$values = explode(' ', trim($this->options['border_win']));
$this->options['border_width_win'] = str_replace('px', '', $values[0]);
$this->options['border_style_win'] = $values[1];
$this->options['border_color_win'] = $values[2];
update_option('auto-thickbox-plus', $this->options);
$updateOption = true;
}
if (!$this->is_default_options('border_img_tl') && $this->options['border_img_tl'] != 'none') {
$values = explode(' ', trim($this->options['border_img_tl']));
$this->options['border_width_img_tl'] = str_replace('px', '', $values[0]);
$this->options['border_style_img_tl'] = $values[1];
$this->options['border_color_img_tl'] = $values[2];
update_option('auto-thickbox-plus', $this->options);
$updateOption = true;
}
if (!$this->is_default_options('border_img_br') && $this->options['border_img_br'] != 'none') {
$values = explode(' ', trim($this->options['border_img_br']));
$this->options['border_width_img_br'] = str_replace('px', '', $values[0]);
$this->options['border_style_img_br'] = $values[1];
$this->options['border_color_img_br'] = $values[2];
update_option('auto-thickbox-plus', $this->options);
$updateOption = true;
}
if ($this->is_default_options('post_id')) {
@@ -668,9 +656,12 @@ SCRIPT;
$args['post_title'] = AUTO_THICKBOX_PLUS;
$this->options['post_id'] = wp_insert_post($args);
}
update_option('auto-thickbox-plus', $this->options);
$updateOption = true;
}
if ($updateOption)
update_option('auto-thickbox-plus', $this->options);
$this->is_en_locale = strpos(get_locale(), 'en') !== false;
$this->texts['next'] = $this->gettext('Next >', array('Next »'));
$this->texts['next2'] = trim(str_replace(array('>', '»'), '', $this->texts['next']));