Skip to content

Commit

Permalink
splitting out js and css for 3.4 and below and 3.5 and above.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiemoya committed Dec 13, 2012
1 parent e4a49c3 commit 9c79d79
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 10 deletions.
57 changes: 57 additions & 0 deletions media-categories-script-3.4.js
@@ -0,0 +1,57 @@
/**
* jQuery for Media Categories plugin
*
* @author Eddie Moya
* @since 1.1
*
*/

jQuery(document).ready(function($){
console.log('test');
$.each(taxonomy, function(index, tax){

$('.media-upload-form tr.'+ tax + '').hide();
$('.media-upload-form tr.' + tax + '_metabox input').live('click', function(){

var form_fields = $(this).closest("tbody");

var checked = form_fields.find("." + tax + "_metabox input:checked");
var slug_list = '';

checked.each(function(index){

if(slug_list.length > 0)
slug_list += ',' + $(this).val();
else
slug_list += $(this).val();
});

form_fields.find("tr."+ tax +" > td.field > input.text").val(slug_list);
})

$.extend($.expr[":"], {
"icontains": function(elem, i, match, array) {
return (elem.textContent || elem.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
/**
* The following javascript is borrowed (with few modifications) from Jason Corradino's
* 'Searchable Categories' plugin. It allows the category metabox to be filtered
* as the user types. To do this with your category meta boxes on pages and posts,
* download his plugin.
*
* http://wordpress.org/extend/plugins/searchable-categories/
*/

$('#' + tax + '-search').keyup(function() {
var val = $('#' + tax + '-search').val();
var lis = $("#"+ tax +"checklist li");
lis.hide();

// find li labels's containing term, then back to parent li
var containingLabels = $("#"+ tax +"checklist label:icontains('" + val + "')");
containingLabels.closest('li').find('li').andSelf().show();
containingLabels.parents('#'+ tax +'checklist li').show();
});
});
})
12 changes: 12 additions & 0 deletions media-categories-style-3.4.css
@@ -0,0 +1,12 @@
.media-upload-form .category-tabs,
.media-upload-form tr.category,
.media-upload-form #category-adder,
.media-upload-form .wp-hidden-children{
display:none;
}

.media-upload-form .category-filter {
font-size: 12px;
font-style: italic;
font-family: sans-serif;
}
32 changes: 22 additions & 10 deletions media-categories.php
Expand Up @@ -36,8 +36,13 @@ public function __construct($taxonomy) {
// Loading these in this fashion no longer applies in 3.5 because of new built-in support for taxonomy metaboxes on the editor page.
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_scripts'));
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_styles') );
} else {

add_action('wp_enqueue_media', array(__CLASS__, 'enqueue_media_categories_scripts'));
add_action('wp_enqueue_media', array(__CLASS__, 'enqueue_media_categories_styles') );
}




}
Expand All @@ -46,15 +51,18 @@ public function __construct($taxonomy) {
* Enqueue javascript
*/
function enqueue_media_categories_scripts() {
global $wp_version;

if (is_admin()) {

// Get each instance of this class, and pass each taxonomy in to javascript
foreach (self::$instances as $instance){
$tax[] = apply_filters('mc_taxonomy', $instance->taxonomy);
}


wp_register_script('media_categories_metabox_script', plugins_url('media-categories-script.js', __FILE__));
$filename = ($wp_version <= 3.4) ? 'media-categories-script-3.4.js' : 'media-categories-script.js';

wp_register_script('media_categories_metabox_script', plugins_url($filename, __FILE__));
wp_enqueue_script('media_categories_metabox_script');

wp_localize_script('media_categories_metabox_script', 'taxonomy', $tax);
Expand All @@ -65,9 +73,13 @@ function enqueue_media_categories_scripts() {
*
*/
function enqueue_media_categories_styles() {
global $wp_version;

if (is_admin()) {

wp_register_style('media_categories_metabox_style', plugins_url('media-categories-style.css', __FILE__));
$filename = ($wp_version <= 3.4) ? 'media-categories-style-3.4.css' : 'media-categories-style.css';

wp_register_style('media_categories_metabox_style', plugins_url($filename , __FILE__));
wp_enqueue_style( 'media_categories_metabox_style');
}
}
Expand All @@ -88,7 +100,7 @@ function register_media_categories() {
* a normal textfield, I capture the output of a custom metabox and insert it.
*/
function add_media_categories_metabox($form_fields, $post) {

global $wp_version;
require_once('./includes/meta-boxes.php');

$tax_name = apply_filters('mc_taxonomy', $this->taxonomy);
Expand All @@ -102,7 +114,7 @@ function add_media_categories_metabox($form_fields, $post) {

$form_slug = $this->taxonomy . '_metabox';

$form_fields[$form_slug]['label'] = $taxonomy->labels->name;
$form_fields[$form_slug]['label'] = $taxonomy->labels->name . "<div class='arrow-down'></div>";
$form_fields[$form_slug]['helps'] = sprintf(__('Select a %s, use the text fields above to filter'), strtolower($taxonomy->labels->singular_name));
$form_fields[$form_slug]['input'] = 'html';
$form_fields[$form_slug]['html'] = $metabox;
Expand Down Expand Up @@ -137,12 +149,12 @@ function media_categories_meta_box($post, $box) {
extract(wp_parse_args($args, $defaults), EXTR_SKIP);
$tax = get_taxonomy($taxonomy);
?>

<div>

<div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
<div class="taxonomy-metabox-field-container">
<label class='category-filter' for="category-filter">Search <?php echo $tax->labels->name; ?>:</label>
<input id='<?php echo $taxonomy?>-search' name="category-filter" type='text' /></div>
<div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">

<input id='<?php echo $taxonomy?>-search' name="category-filter" type='text' />
</div>
<ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs">
<li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li>
<li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-pop" tabindex="3"><?php _e('Most Used'); ?></a></li>
Expand Down

0 comments on commit 9c79d79

Please sign in to comment.