Plugin Directory

Changeset 1017027


Ignore:
Timestamp:
10/30/2014 09:24:34 PM (11 years ago)
Author:
misterbisson
Message:

small bug fixes, updated readme

Location:
scriblio-authority/trunk
Files:
7 added
4 edited

Legend:

Unmodified
Added
Removed
  • scriblio-authority/trunk/components/class-authority-posttype.php

    r980884 r1017027  
    453453                }//end if
    454454
    455                 $taxonomy = get_taxonomy( $taxonomy );
     455                if ( ! $taxonomy = get_taxonomy( $taxonomy ) )
     456                {
     457                    continue;
     458                }
    456459
    457460                $taxonomies[ $key ] = $this->simplify_taxonomy_for_json( $taxonomy );
  • scriblio-authority/trunk/components/css/scrib-authority.structure.css

    r980884 r1017027  
    195195}
    196196
    197 .scrib-authority-box .scrib-authority-box-results .scrib-authority-box-result-category h4 {
     197.scrib-authority-box .scrib-authority-box-results .scrib-authority-box-result-category header {
    198198    margin: 0;
    199199    padding: 3px 0;
  • scriblio-authority/trunk/components/js/jquery.scrib-authority.js

    r980884 r1017027  
    3535 */
    3636(function( $ ) {
     37    'use strict';
     38
    3739    var defaults = {
    3840        id: null,
     
    5456        init: function( params ) {
    5557
    56             if ( 'undefined' != typeof params && 'undefined' != typeof params.url ) {
     58            if ( 'undefined' !== typeof params && 'undefined' !== typeof params.url ) {
    5759                scrib_authority_suggest.url = params.url;
    5860            }
     
    6769            options = $.extend( defaults, params );
    6870
    69             var type = 'undefined' != typeof this.attr( 'type' ) ? this.attr( 'type' ) : 'text';
     71            var type = 'undefined' !== typeof this.attr( 'type' ) ? this.attr( 'type' ) : 'text';
    7072
    7173            // set up the html injection variables
    7274            html = {
    73                 wrapper : '<div class="' + selector + '" />',
    74                 item    : '<li class="' + selector + '-item" />',
    75                 items   : '<ul class="' + selector + '-items"></ul>',
    76                 entry   : '<input type="' + type + '" class="' + selector + '-entry ' + selector + '-input" />'
     75                $wrapper : $( '<div/>', { class: selector } ),
     76                $item    : $( '<li/>', { class: selector + '-item' } ),
     77                $items   : $( '<ul/>', { class: selector + '-items' } ),
     78                $entry   : $( '<input/>', {
     79                    type: type,
     80                    class: selector + '-entry ' + selector + '-input'
     81                } )
    7782            };
    7883
     
    9095            selectors.close     = selectors.item + ' .close';
    9196
    92             var $results = $('<ul class="' + selector +'-results"/>');
    93             $results.append( $('<li class="' + selector + '-result-category ' + selector + '-result-category-results"><h4>' + options.labels.results + '</h4><ul></ul></li>') );
     97            var $results = $( '<ul/>', {
     98                class: selector +'-results'
     99            } );
     100
     101            // create the <li> that'll hold the header and record <ul>
     102            var $results_li = $( '<li/>', {
     103                class: selector + '-result-category ' + selector + '-result-category-results'
     104            } );
     105
     106            // add a header for the result li
     107            $results_li.append( $( '<header/>', {
     108                text: options.labels.results
     109            } ) );
     110
     111            // add a container for result records
     112            $results_li.append( '<ul/>' );
     113
     114            // add the result li
     115            $results.append( $results_li );
    94116
    95117            if ( options.custom_enabled ) {
    96                 $results.append( $('<li class="' + selector + '-result-category ' + selector + '-result-category-custom"><h4>Custom</h4><ul></ul></li>') );
     118                var $custom_results_li = $( '<li/>', {
     119                    class: selector + '-result-category ' + selector + '-result-category-custom'
     120                } );
     121
     122                $custom_results_li.append( $( '<header/>', {
     123                    text: 'Custom'
     124                } ) );
     125
     126                $custom_results_li.append( '<ul/>' );
     127
     128                $results.append( $custom_results_li );
    97129            }//end if
    98130
    99             $results.find('.' + selector + '-result-category-results ul').append('<li class="' + selector + '-no-results">No terms were found matching your search.</li>');
    100 
    101             var $entry_container = $('<div class="' + selector + '-entry-container"/>');
    102 
    103             $entry_container.append( html.entry );
     131            $results.find('.' + selector + '-result-category-results ul').append( $( '<li/>', {
     132                class: selector + '-no-results',
     133                text: 'No terms were found matching your search.'
     134            } ) );
     135
     136            var $entry_container = $( '<div/>', {
     137                class: selector + '-entry-container'
     138            } );
     139
     140            $entry_container.append( html.$entry );
    104141
    105142            if ( ! options.replace_field ) {
     
    116153                // wrap and hide the original bound element
    117154                $orig = $( this );
    118                 $orig.wrap( html.wrapper );
     155                $orig.wrap( html.$wrapper );
    119156
    120157                if ( options.replace_field ) {
     
    150187
    151188                // add the items container
    152                 $root.append( html.items );
     189                $root.append( html.$items );
    153190
    154191                // add the entry/results container
     
    157194                //set top to the inverse of search-box margin to ensure it snugs up to the search box
    158195                $entry_container.css('top', function() {
    159                     var margin = $( selectors.entry ).css( 'margin-bottom' ).replace("px", "");
     196                    var margin = $( selectors.entry ).css( 'margin-bottom' ).replace( 'px', '' );
    160197
    161198                    return parseInt( margin, 10 ) * -1;
    162199                });
    163200
    164                 $root.append('<div class="' + selector + '-clearfix"/>');
     201                $root.append( $( '<div/>', {
     202                    class: selector + '-clearfix'
     203                } ) );
    165204
    166205                if ( options.replace_field ) {
     
    178217
    179218                // click event: result item
    180                 $root.on( 'click.scrib-authority-box touchstart.scrib-authority-box MSPointerDown.scrib-authority-box', selectors.results + ' ' + selectors.item, function( e ) {
     219                $root.on( 'click.scrib-authority-box MSPointerDown.scrib-authority-box', selectors.results + ' ' + selectors.item, function( e ) {
    181220                    e.preventDefault();
    182221
     
    185224                });
    186225
     226                $root.$current_touch_item = null;
     227                $root.current_touch_y_pos = null;
     228
     229                $root.on( 'touchstart.scrib-authority-box', selectors.results + ' ' + selectors.item, function( e ) {
     230                    $root.$current_touch_item = $( this );
     231                    $root.current_touch_y_pos = e.changedTouches[0].pageY;
     232                });
     233
     234                $root.on( 'touchend.scrib-authority-box', selectors.results + ' ' + selectors.item, function( e ) {
     235                    e.preventDefault();
     236
     237                    // if there isn't a touch start item, bail
     238                    if ( ! $root.$current_touch_item ) {
     239                        $root.$current_touch_item = null;
     240                        $root.current_touch_y_pos = null;
     241                        return;
     242                    }//end if
     243
     244                    var original_item = $root.$current_touch_item.find( '.taxonomy' ).html();
     245                    original_item = original_item + ':' + $root.$current_touch_item.find( '.term' ).html();
     246
     247                    var current_item = $( this ).find( '.taxonomy' ).html();
     248                    current_item = current_item + ':' + $( this ).find( '.term' ).html();
     249
     250                    // if the end item is not the start item, bail
     251                    if ( original_item !== current_item ) {
     252                        $root.$current_touch_item = null;
     253                        $root.current_touch_y_pos = null;
     254                        return;
     255                    }//end if
     256
     257                    // if there are no changedTouches, bail
     258                    if ( 'undefined' === typeof e.changedTouches || 0 === e.changedTouches.length ) {
     259                        $root.$current_touch_item = null;
     260                        $root.current_touch_y_pos = null;
     261                        return;
     262                    }
     263
     264                    // if the changed touches moved more than 10 pixels in any direction, bail (we're probably scrolling)
     265                    if ( ( $root.current_touch_y_pos + 10 ) < e.changedTouches[0].pageY || ( $root.current_touch_y_pos - 10 ) > e.changedTouches[0].pageY ) {
     266                        $root.$current_touch_item = null;
     267                        $root.current_touch_y_pos = null;
     268                        return;
     269                    }//end if
     270
     271                    $root.$current_touch_item = null;
     272                    $root.current_touch_y_pos = null;
     273
     274                    methods.select_item( $(this), $root );
     275                    methods.update_target( $root );
     276                });
     277
    187278                // click event: root element
    188                 $root.on( 'click.scrib-authority-box touchstart.scrib-authority-box MSPointerDown.scrib-authority-box', function( e ) {
     279                $root.on( 'click.scrib-authority-box touchstart.scrib-authority-box MSPointerDown.scrib-authority-box', function() {
     280                    var $entry = $( this ).find( selectors.entry );
     281                    var $results = $entry.closest( '.scrib-authority-box' ).find( '.scrib-authority-box-results.has-results' );
     282
    189283                    // if the root element is clicked, focus the entry
    190                     $(this).find( selectors.entry ).focus();
     284                    $entry.focus();
     285
     286                    // when focusing, if the input box already has content in it that returned results, show them
     287                    if ( $entry.val() && $results.length ) {
     288                        $results.addClass( 'show' );
     289                    }//end if
     290                });
     291
     292                // click event: handles dismissing the results box if clicking off of the box or search
     293                $( document ).on( 'click.scrib-authority-box-cancel touchstart.scrib-authority-box-cancel MSPointerDown.scrib-authority-box-cancel', function( e ) {
     294                    var $el = $( e.target );
     295
     296                    if ( $el.is( '.scrib-authority-box' ) || 0 !== $el.closest( '.scrib-authority-box').length ) {
     297                        return;
     298                    }//end if
     299
     300                    methods.hide_results( $root );
    191301                });
    192302
     
    327437         * @param string which The data element to retrieve
    328438         */
    329         data_string: function( which ) {
     439        data_string: function() {
    330440            var $el = methods.root( $(this) );
    331441            var serialized = $el.ScribAuthority('serialize');
     
    353463         */
    354464        generate_item: function( data ) {
    355             var $item = $( html.item );
     465            var $item = html.$item.clone();
    356466
    357467            // let's store the object that is used to generate this item.
     
    364474                }//end if
    365475
     476                console.log( key, data_value );
     477
    366478                // the only exception are the data elements.  Add them to the item's data storage
    367                 if( 'data' == key ) {
     479                if( 'data' === key ) {
    368480                    $.each( data_value, function( data_key, key_value ) {
    369481                        $item.data( data_key, key_value );
    370482                    });
    371                 } else if ( 'taxonomy' == key ) {
    372                     var $taxonomy = $('<span class="' + key + '">' + data_value.labels.singular_name + '</span>');
     483                } else if ( 'taxonomy' === key ) {
     484                    var $taxonomy = $( '<span/>', {
     485                        class: key,
     486                        text: data_value.labels.singular_name
     487                    } );
     488
    373489                    $taxonomy.data( 'taxonomy', data_value );
    374490
    375491                    $item.append( $taxonomy );
    376492                } else {
    377                     $item.prepend( $('<span class="' + key + '" />').html( data_value ) );
    378                 }//end if
     493                    var $inject = $( '<span/>', {
     494                        class: key
     495                    } );
     496
     497                    $inject.html( data_value );
     498                    $item.prepend( $inject );
     499                }//end else
    379500            });
    380501
     
    455576                var temp_combo = value.taxonomy.name + ':' + value.term;
    456577                var temp_origin_combo = origin.taxonomy.name + ':' + origin.term;
    457                 if ( temp_combo != temp_origin_combo ) {
     578                if ( temp_combo !== temp_origin_combo ) {
    458579                    new_items.push( value );
    459580                }//end if
     
    480601            return this.each( function() {
    481602                var $el = $(this);
    482                 var $root = methods.root( $el );
    483603                var items = $el.data('items');
    484604
     
    493613                        // if the results item DOES NOT exist in the set of elements already selected,
    494614                        //   add it to the result area
    495                         if ( 0 === $.grep( items, function( element, index ) { return element.data.term === value.data.term; }).length ) {
     615                        if ( 0 === $.grep( items, function( element ) { return element.data.term === value.data.term; }).length ) {
    496616                            $el.ScribAuthority('result', value);
    497617                        }//end if
     
    534654
    535655            xhr.done( function( data ) {
    536                 if ( typeof data != 'undefined' ) {
     656                if ( typeof data !== 'undefined' ) {
    537657                    $root.ScribAuthority('results', data);
    538658                    methods.show_results( $root );
     
    547667         */
    548668        select_item: function( $item, $root ) {
     669            var $newitem;
    549670            // get the cached items object from the root element
    550671            var items = $root.data('items') || [];
     
    554675
    555676            if( $item.is( selectors.newitem ) ) {
    556                 var $newitem = $item.clone();
     677                $newitem = $item.clone();
    557678                $newitem.data('origin-data', {
    558679                    taxonomy: $item.find('.taxonomy').data('taxonomy'),
     
    565686                items.push( $newitem.data( 'origin-data' ) );
    566687            } else {
    567                 $root.find( selectors.items ).append( $item );
     688                $newitem = $item.clone();
     689
     690                $root.find( selectors.items ).append( $newitem );
    568691                items.push( $item.data( 'origin-data' ) );
    569692            }//end else
     
    577700            // advertise that an item has been selected
    578701            $item.trigger( 'scriblio-authority-item-selected', { item: $item });
     702
     703            methods.hide_results( $root );
    579704        },
    580705        /**
     
    625750            if ( options.taxonomies ) {
    626751                $.each( options.taxonomies, function( i, value ) {
    627                     var $item = $('<li class="' + selector + '-item ' + selector + '-new"/>');
    628                     var $taxonomy = $('<span class="taxonomy">' + value.labels.singular_name + '</span>');
     752                    var $item = $( '<li/>', {
     753                        class: selector + '-item ' + selector + '-new'
     754                    } );
     755
     756                    var $taxonomy = $( '<span/>', {
     757                        class: 'taxonomy',
     758                        text: value.labels.singular_name
     759                    } );
     760
    629761                    $taxonomy.data('taxonomy', value);
    630762                    $item.append( $taxonomy );
  • scriblio-authority/trunk/readme.txt

    r980884 r1017027  
    11=== Scriblio Authority ===
     2
    23Contributors: misterbisson, borkweb
     4
    35Donate link: http://MaisonBisson.com/
     6
    47Tags: tags, custom taxonomies, term authority, tag management,
     8
    59Requires at least: 3.7
     10
    611Tested up to: 4.0
     12
    713Stable tag: trunk
    814
     
    1319Bring order to chaos: manage tags and other custom taxonomy terms. Make them do party tricks.
    1420
     21= In the WordPress.org plugin repo =
     22
     23Here: https://wordpress.org/plugins/scriblio-authority/
     24
    1525= Fork me! =
    1626
    1727This plugin is on Github: https://github.com/misterbisson/scriblio-authority
     28
     29= Build status =
     30
     31[Master build status at Travis-CI](https://travis-ci.org/misterbisson/scriblio-authority): [![Build Status](https://travis-ci.org/misterbisson/scriblio-authority.svg?branch=master)](https://travis-ci.org/misterbisson/scriblio-authority)
Note: See TracChangeset for help on using the changeset viewer.