1(function ($) { 2 'use strict'; 3 $('img[longdesc]').each(function () { 4 var longdesc = $(this).attr('longdesc'); 5 var img = $(this); 6 var classes = img.attr('class'); 7 var class_array = img.attr('class').match(/\S+/g); 8 var image_id = ''; 9 $.each( class_array, function ( index, value ) { 10 if ( value.match( /wp-image-/gi ) ) { 11 image_id = value; 12 } 13 }); 14 // Secondary check for image ID, if not in classes. 15 if ( '' === image_id ) { 16 var imgId = img.attr( 'id' ); 17 image_id = imgId.replace( 'longdesc-return-', '' ); 18 } 19 img.attr('class', ''); 20 img.wrap('<div class="wpa-ld" />') 21 img.parent('.wpa-ld').addClass(classes); 22 img.parent('.wpa-ld').append('<button aria-expanded="false" class="wpa-toggle">' + wparest.text + '</button>'); 23 img.parent('.wpa-ld').append('<div class="longdesc"></div>'); 24 var container = img.parent('.wpa-ld').children('.longdesc'); 25 container.hide(); 26 container.load( longdesc + ' #desc_' + image_id ); 27 img.parent('.wpa-ld').children('button').on( 'click', function(e) { 28 e.preventDefault(); 29 var visible = container.is( ':visible' ); 30 if ( visible ) { 31 $( this ).attr( 'aria-expanded', 'false' ); 32 container.hide(); 33 } else { 34 $( this ).attr( 'aria-expanded', 'true' ); 35 container.show(150); 36 } 37 }); 38 }); 39 40 $( 'figure.is-style-longdesc' ).each(function() { 41 var img = $(this).find( 'img' ); 42 wpa_load_image( img ); 43 }); 44 45 function wpa_draw_longdesc( img, image_id, longdesc, rawdesc ) { 46 var classes = img.attr('class'); 47 img.attr('class', '').attr('longdesc', longdesc ); 48 img.attr('id','longdesc-return-' + image_id ); 49 img.wrap('<div class="wpa-ld" />')
50 img.parent('.wpa-ld').addClass(classes); 51 img.parent('.wpa-ld').append('<button aria-expanded="false" class="wpa-toggle">' + wparest.text + '</button>'); 52 img.parent('.wpa-ld').append('<div class="longdesc"></div>'); 53 var container = img.parent('.wpa-ld').children('.longdesc'); 54 container.hide(); 55 container.load( longdesc + ' #desc_' + image_id, {limit:25}, 56 function( responseText, textStatus, xhr ) { 57 if ( 'error' === textStatus ) { 58 container.html( rawdesc ); 59 } 60 } 61 ); 62 img.parent('.wpa-ld').children('button').on( 'click', function(e) { 63 e.preventDefault(); 64 var visible = container.is( ':visible' ); 65 if ( visible ) { 66 $( this ).attr( 'aria-expanded', 'false' ); 67 container.hide(); 68 } else { 69 $( this ).attr( 'aria-expanded', 'true' ); 70 container.show(150); 71 } 72 }); 73 } 74 75 function wpa_load_image( img ) { 76 var classes = img.attr( 'class' ); 77 if ( '' === classes ) { 78 classes = img.parent( '.wpa-alt' ).attr( 'class' ).replace( 'wpa-alt ', '' ); 79 } 80 var id = classes.replace( 'wp-image-', '' ); 81 var api = wparest.url + '/' + id; 82 83 $.get( api ) 84 .done( function( response ) { 85 var attachment = { 86 attachment: response 87 } 88 var rawdesc = response.description.rendered; 89 rawdesc = rawdesc.replace(/(<([^>]+)>)/gi, '').trim(); 90 if ( '' !== rawdesc ) { 91 var url = new URL( response.link ); 92 url.searchParams.set( 'longdesc', id ); 93 url.toString(); 94 wpa_draw_longdesc( img, id, url, rawdesc ); 95 } 96 }) 97 .fail( function() { 98 alert( 'cannot load media' ) 99 }); 100 } 101}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.