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 img.attr('class', ''); 15 img.wrap('<div class="wpa-ld" />') 16 img.parent('.wpa-ld').addClass(classes); 17 img.parent('.wpa-ld').append('<div class="longdesc" aria-live="assertive"></div>'); 18 img.parent('.wpa-ld').append('<button>' + wpatext + '</button>'); 19 var container = img.parent('.wpa-ld').children('.longdesc'); 20 container.hide(); 21 container.load( longdesc + ' #desc_' + image_id ); 22 img.parent('.wpa-ld').children('button').on( 'click', function(e) { 23 e.preventDefault(); 24 var visible = container.is( ':visible' ); 25 if ( visible ) { 26 container.hide(); 27 } else { 28 container.show(150); 29 } 30 }); 31 }); 32 33 $( 'figure.is-style-longdesc' ).each(function() { 34 var img = $(this).find( 'img' ); 35 wpa_load_image( img ); 36 }); 37 38 function wpa_draw_longdesc( img, image_id, longdesc ) { 39 var classes = img.attr('class'); 40 img.attr('class', '').attr('longdesc', longdesc ); 41 img.attr('id','longdesc-return-' + image_id ); 42 img.wrap('<div class="wpa-ld" />')
43 img.parent('.wpa-ld').addClass(classes); 44 img.parent('.wpa-ld').append('<div class="longdesc" aria-live="assertive"></div>'); 45 img.parent('.wpa-ld').append('<button>' + wpatext + '</button>'); 46 var container = img.parent('.wpa-ld').children('.longdesc'); 47 container.hide(); 48 container.load( longdesc + ' #desc_' + image_id ); 49 console.log( longdesc + ' #desc_' + image_id ); 50 img.parent('.wpa-ld').children('button').on( 'click', function(e) { 51 e.preventDefault(); 52 var visible = container.is( ':visible' ); 53 if ( visible ) { 54 container.hide(); 55 } else { 56 container.show(150); 57 } 58 }); 59 } 60 61 function wpa_load_image( img ) { 62 var id = img.attr( 'class' ).replace( 'wp-image-', '' ); 63 var api = wparest + '/' + id; 64 65 $.get( api ) 66 .done( function( response ) { 67 var attachment = { 68 attachment: response 69 } 70 71 var url = new URL( response.link ); 72 url.searchParams.set( 'longdesc', id ); 73 url.toString(); 74 wpa_draw_longdesc( img, id, url ); 75 }) 76 .fail( function() { 77 alert( 'cannot load media' ) 78 }); 79 } 80}(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.