2022-06-07 17:22:42 +00:00
$ ( document ) . ready ( function ( ) {
2024-05-16 21:39:06 +00:00
$ ( '.needs-localtime' ) . each ( function ( ) {
for ( var option of this . options ) {
var dateObject = new Date ( option . value * 1000 ) ;
option . label = dateObject . toLocaleString ( undefined , { dateStyle : "full" , timeStyle : "medium" } ) ;
}
} ) ;
2022-06-07 17:22:42 +00:00
// Load it when the #screenshot tab is in use, so we dont give a slow experience when waiting for the text diff to load
window . addEventListener ( 'hashchange' , function ( e ) {
toggle ( location . hash ) ;
} , false ) ;
toggle ( location . hash ) ;
function toggle ( hash _name ) {
if ( hash _name === '#screenshot' ) {
$ ( "img#screenshot-img" ) . attr ( 'src' , screenshot _url ) ;
2022-06-07 17:53:13 +00:00
$ ( "#settings" ) . hide ( ) ;
2022-08-15 16:56:53 +00:00
} else if ( hash _name === '#error-screenshot' ) {
$ ( "img#error-screenshot-img" ) . attr ( 'src' , error _screenshot _url ) ;
$ ( "#settings" ) . hide ( ) ;
2022-12-05 13:48:03 +00:00
} else if ( hash _name === '#extract' ) {
$ ( "#settings" ) . hide ( ) ;
2023-08-24 12:29:48 +00:00
} else {
$ ( "#settings" ) . show ( ) ;
2022-08-15 16:56:53 +00:00
}
2023-08-24 12:29:48 +00:00
}
2022-08-15 16:56:53 +00:00
2023-08-24 12:29:48 +00:00
const article = $ ( '.highlightable-filter' ) [ 0 ] ;
// We could also add the 'touchend' event for touch devices, but since
// most iOS/Android browsers already show a dialog when you select
// text (often with a Share option) we'll skip that
article . addEventListener ( 'mouseup' , dragTextHandler , false ) ;
article . addEventListener ( 'mousedown' , clean , false ) ;
function clean ( event ) {
$ ( "#highlightSnippet" ) . remove ( ) ;
}
2024-07-03 17:26:33 +00:00
// Listen for Escape key press
window . addEventListener ( 'keydown' , function ( e ) {
if ( e . key === 'Escape' ) {
clean ( ) ;
}
} , false ) ;
2023-08-24 12:29:48 +00:00
function dragTextHandler ( event ) {
console . log ( 'mouseupped' ) ;
// Check if any text was selected
if ( window . getSelection ( ) . toString ( ) . length > 0 ) {
// Find out how much (if any) user has scrolled
var scrollTop = ( window . pageYOffset !== undefined ) ? window . pageYOffset : ( document . documentElement || document . body . parentNode || document . body ) . scrollTop ;
// Get cursor position
const posX = event . clientX ;
const posY = event . clientY + 20 + scrollTop ;
// Append HTML to the body, create the "Tweet Selection" dialog
document . body . insertAdjacentHTML ( 'beforeend' , '<div id="highlightSnippet" style="position: absolute; top: ' + posY + 'px; left: ' + posX + 'px;"><div class="pure-form-message-inline" style="font-size: 70%">Ignore any change on any line which contains the selected text.</div><br><a data-mode="exact" href="javascript:void(0);" class="pure-button button-secondary button-xsmall">Ignore exact text</a> </div>' ) ;
if ( /\d/ . test ( window . getSelection ( ) . toString ( ) ) ) {
// Offer regex replacement
document . getElementById ( "highlightSnippet" ) . insertAdjacentHTML ( 'beforeend' , '<a data-mode="digit-regex" href="javascript:void(0);" class="pure-button button-secondary button-xsmall">Ignore text including number changes</a>' ) ;
}
$ ( '#highlightSnippet a' ) . bind ( 'click' , function ( e ) {
if ( ! window . getSelection ( ) . toString ( ) . trim ( ) . length ) {
alert ( 'Oops no text selected!' ) ;
return ;
}
$ . ajax ( {
type : "POST" ,
url : highlight _submit _ignore _url ,
data : { 'mode' : $ ( this ) . data ( 'mode' ) , 'selection' : window . getSelection ( ) . toString ( ) } ,
statusCode : {
400 : function ( ) {
// More than likely the CSRF token was lost when the server restarted
alert ( "There was a problem processing the request, please reload the page." ) ;
}
}
} ) . done ( function ( data ) {
2023-08-31 11:24:19 +00:00
$ ( "#highlightSnippet" ) . html ( data )
2023-08-24 12:29:48 +00:00
} ) . fail ( function ( data ) {
console . log ( data ) ;
alert ( 'There was an error communicating with the server.' ) ;
} ) ;
} ) ;
2022-08-15 16:56:53 +00:00
2022-06-07 17:22:42 +00:00
}
}
2023-08-24 12:29:48 +00:00
2024-02-01 09:36:43 +00:00
$ ( '#diff-form' ) . on ( 'submit' , function ( e ) {
if ( $ ( 'select[name=from_version]' ) . val ( ) === $ ( 'select[name=to_version]' ) . val ( ) ) {
e . preventDefault ( ) ;
alert ( 'Error - You are trying to compare the same version.' ) ;
}
} ) ;
2022-06-07 17:22:42 +00:00
} ) ;