Changeset 1017027
- Timestamp:
- 10/30/2014 09:24:34 PM (11 years ago)
- Location:
- scriblio-authority/trunk
- Files:
-
- 7 added
- 4 edited
-
.travis.yml (added)
-
bin (added)
-
bin/install-wp-tests.sh (added)
-
components/class-authority-posttype.php (modified) (1 diff)
-
components/css/scrib-authority.structure.css (modified) (1 diff)
-
components/js/jquery.scrib-authority.js (modified) (21 diffs)
-
phpunit.xml (added)
-
readme.txt (modified) (2 diffs)
-
tests (added)
-
tests/bootstrap.php (added)
-
tests/test-sample.php (added)
Legend:
- Unmodified
- Added
- Removed
-
scriblio-authority/trunk/components/class-authority-posttype.php
r980884 r1017027 453 453 }//end if 454 454 455 $taxonomy = get_taxonomy( $taxonomy ); 455 if ( ! $taxonomy = get_taxonomy( $taxonomy ) ) 456 { 457 continue; 458 } 456 459 457 460 $taxonomies[ $key ] = $this->simplify_taxonomy_for_json( $taxonomy ); -
scriblio-authority/trunk/components/css/scrib-authority.structure.css
r980884 r1017027 195 195 } 196 196 197 .scrib-authority-box .scrib-authority-box-results .scrib-authority-box-result-category h 4{197 .scrib-authority-box .scrib-authority-box-results .scrib-authority-box-result-category header { 198 198 margin: 0; 199 199 padding: 3px 0; -
scriblio-authority/trunk/components/js/jquery.scrib-authority.js
r980884 r1017027 35 35 */ 36 36 (function( $ ) { 37 'use strict'; 38 37 39 var defaults = { 38 40 id: null, … … 54 56 init: function( params ) { 55 57 56 if ( 'undefined' != typeof params && 'undefined' != typeof params.url ) {58 if ( 'undefined' !== typeof params && 'undefined' !== typeof params.url ) { 57 59 scrib_authority_suggest.url = params.url; 58 60 } … … 67 69 options = $.extend( defaults, params ); 68 70 69 var type = 'undefined' != typeof this.attr( 'type' ) ? this.attr( 'type' ) : 'text';71 var type = 'undefined' !== typeof this.attr( 'type' ) ? this.attr( 'type' ) : 'text'; 70 72 71 73 // set up the html injection variables 72 74 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 } ) 77 82 }; 78 83 … … 90 95 selectors.close = selectors.item + ' .close'; 91 96 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 ); 94 116 95 117 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 ); 97 129 }//end if 98 130 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 ); 104 141 105 142 if ( ! options.replace_field ) { … … 116 153 // wrap and hide the original bound element 117 154 $orig = $( this ); 118 $orig.wrap( html. wrapper );155 $orig.wrap( html.$wrapper ); 119 156 120 157 if ( options.replace_field ) { … … 150 187 151 188 // add the items container 152 $root.append( html. items );189 $root.append( html.$items ); 153 190 154 191 // add the entry/results container … … 157 194 //set top to the inverse of search-box margin to ensure it snugs up to the search box 158 195 $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', '' ); 160 197 161 198 return parseInt( margin, 10 ) * -1; 162 199 }); 163 200 164 $root.append('<div class="' + selector + '-clearfix"/>'); 201 $root.append( $( '<div/>', { 202 class: selector + '-clearfix' 203 } ) ); 165 204 166 205 if ( options.replace_field ) { … … 178 217 179 218 // click event: result item 180 $root.on( 'click.scrib-authority-box touchstart.scrib-authority-boxMSPointerDown.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 ) { 181 220 e.preventDefault(); 182 221 … … 185 224 }); 186 225 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 187 278 // 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 189 283 // 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 ); 191 301 }); 192 302 … … 327 437 * @param string which The data element to retrieve 328 438 */ 329 data_string: function( which) {439 data_string: function() { 330 440 var $el = methods.root( $(this) ); 331 441 var serialized = $el.ScribAuthority('serialize'); … … 353 463 */ 354 464 generate_item: function( data ) { 355 var $item = $( html.item);465 var $item = html.$item.clone(); 356 466 357 467 // let's store the object that is used to generate this item. … … 364 474 }//end if 365 475 476 console.log( key, data_value ); 477 366 478 // the only exception are the data elements. Add them to the item's data storage 367 if( 'data' == key ) {479 if( 'data' === key ) { 368 480 $.each( data_value, function( data_key, key_value ) { 369 481 $item.data( data_key, key_value ); 370 482 }); 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 373 489 $taxonomy.data( 'taxonomy', data_value ); 374 490 375 491 $item.append( $taxonomy ); 376 492 } 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 379 500 }); 380 501 … … 455 576 var temp_combo = value.taxonomy.name + ':' + value.term; 456 577 var temp_origin_combo = origin.taxonomy.name + ':' + origin.term; 457 if ( temp_combo != temp_origin_combo ) {578 if ( temp_combo !== temp_origin_combo ) { 458 579 new_items.push( value ); 459 580 }//end if … … 480 601 return this.each( function() { 481 602 var $el = $(this); 482 var $root = methods.root( $el );483 603 var items = $el.data('items'); 484 604 … … 493 613 // if the results item DOES NOT exist in the set of elements already selected, 494 614 // 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 ) { 496 616 $el.ScribAuthority('result', value); 497 617 }//end if … … 534 654 535 655 xhr.done( function( data ) { 536 if ( typeof data != 'undefined' ) {656 if ( typeof data !== 'undefined' ) { 537 657 $root.ScribAuthority('results', data); 538 658 methods.show_results( $root ); … … 547 667 */ 548 668 select_item: function( $item, $root ) { 669 var $newitem; 549 670 // get the cached items object from the root element 550 671 var items = $root.data('items') || []; … … 554 675 555 676 if( $item.is( selectors.newitem ) ) { 556 var$newitem = $item.clone();677 $newitem = $item.clone(); 557 678 $newitem.data('origin-data', { 558 679 taxonomy: $item.find('.taxonomy').data('taxonomy'), … … 565 686 items.push( $newitem.data( 'origin-data' ) ); 566 687 } else { 567 $root.find( selectors.items ).append( $item ); 688 $newitem = $item.clone(); 689 690 $root.find( selectors.items ).append( $newitem ); 568 691 items.push( $item.data( 'origin-data' ) ); 569 692 }//end else … … 577 700 // advertise that an item has been selected 578 701 $item.trigger( 'scriblio-authority-item-selected', { item: $item }); 702 703 methods.hide_results( $root ); 579 704 }, 580 705 /** … … 625 750 if ( options.taxonomies ) { 626 751 $.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 629 761 $taxonomy.data('taxonomy', value); 630 762 $item.append( $taxonomy ); -
scriblio-authority/trunk/readme.txt
r980884 r1017027 1 1 === Scriblio Authority === 2 2 3 Contributors: misterbisson, borkweb 4 3 5 Donate link: http://MaisonBisson.com/ 6 4 7 Tags: tags, custom taxonomies, term authority, tag management, 8 5 9 Requires at least: 3.7 10 6 11 Tested up to: 4.0 12 7 13 Stable tag: trunk 8 14 … … 13 19 Bring order to chaos: manage tags and other custom taxonomy terms. Make them do party tricks. 14 20 21 = In the WordPress.org plugin repo = 22 23 Here: https://wordpress.org/plugins/scriblio-authority/ 24 15 25 = Fork me! = 16 26 17 27 This 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): [](https://travis-ci.org/misterbisson/scriblio-authority)
Note: See TracChangeset
for help on using the changeset viewer.