mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Res: Add resources from xowa_app_windows_64_v4.5.26.1810
This commit is contained in:
76
res/bin/any/xowa/xtns/Graph/modules/graph.sandbox.js
Normal file
76
res/bin/any/xowa/xtns/Graph/modules/graph.sandbox.js
Normal file
@@ -0,0 +1,76 @@
|
||||
( function ( $, mw ) {
|
||||
var oldContent, ccw,
|
||||
resizeCodeEditor = $.noop;
|
||||
|
||||
$( function () {
|
||||
var viewportHeight = $( window ).height(),
|
||||
sandboxHeight = viewportHeight - 150,
|
||||
initialPosition = sandboxHeight - 100;
|
||||
$( '#mw-graph-sandbox' ).width( '100%' ).height( sandboxHeight ).split( {
|
||||
orientation: 'vertical',
|
||||
limit: 100,
|
||||
position: '40%'
|
||||
} );
|
||||
$( '#mw-graph-left' ).split( {
|
||||
orientation: 'horizontal',
|
||||
limit: 100,
|
||||
position: initialPosition
|
||||
} );
|
||||
} );
|
||||
|
||||
mw.hook( 'codeEditor.configure' ).add( function ( session ) {
|
||||
var $json = $( '#mw-graph-json' )[ 0 ],
|
||||
$graph = $( '.mw-graph' ),
|
||||
$graphEl = $graph[ 0 ],
|
||||
$rightPanel = $( '#mw-graph-right' ),
|
||||
$editor = $( '.editor' );
|
||||
|
||||
if ( ccw ) {
|
||||
ccw.release();
|
||||
}
|
||||
ccw = mw.confirmCloseWindow( {
|
||||
test: function () {
|
||||
return session.getValue().length > 0;
|
||||
},
|
||||
message: mw.msg( 'editwarning-warning' )
|
||||
} );
|
||||
|
||||
resizeCodeEditor = function () {
|
||||
$editor.parent().height( $rightPanel.height() - 57 );
|
||||
$.wikiEditor.instances[ 0 ].data( 'wikiEditor-context' ).codeEditor.resize();
|
||||
};
|
||||
|
||||
// I tried to resize on $( window ).resize(), but that didn't work right
|
||||
resizeCodeEditor();
|
||||
|
||||
session.on( 'change', $.debounce( 300, function () {
|
||||
var content = session.getValue();
|
||||
|
||||
if ( oldContent === content ) {
|
||||
return;
|
||||
}
|
||||
oldContent = content;
|
||||
$graph.empty();
|
||||
|
||||
new mw.Api().post( {
|
||||
formatversion: 2,
|
||||
action: 'graph',
|
||||
text: content
|
||||
} ).done( function ( data ) {
|
||||
if ( session.getValue() !== content ) {
|
||||
// Just in case the content has changed since we made the api call
|
||||
return;
|
||||
}
|
||||
$json.textContent = JSON.stringify( data.graph, null, 2 );
|
||||
mw.drawVegaGraph( $graphEl, data.graph, function ( error ) {
|
||||
if ( error ) {
|
||||
$graphEl.textContent = ( error.exception || error ).toString();
|
||||
}
|
||||
} );
|
||||
} ).fail( function ( errCode, error ) {
|
||||
$graphEl.textContent = errCode.toString() + ':' + ( error.exception || error ).toString();
|
||||
} );
|
||||
} ) );
|
||||
} );
|
||||
|
||||
}( jQuery, mediaWiki ) );
|
||||
Reference in New Issue
Block a user