/** * VisualEditor user interface Context class. * * @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt */ /** * Creates an ve.ui.Context object. * * @class * @constructor * @param {jQuery} $overlay DOM selection to add nodes to */ ve.ui.Context = function ( surfaceView, $overlay ) { // Inheritance if ( !surfaceView ) { return; } // Properties this.surfaceView = surfaceView; this.inspectors = {}; this.inspector = null; this.position = null; this.clicking = false; // Default to body as parent. $overlay = $overlay || $( 'body' ); // Setup contextView this.$ = $( '
' ).prop( 'class', 've-ui-context' ); $overlay.append( this.$ ); // Icon this.$icon = $( '
' ) .prop( 'class' , 've-ui-context-icon' ) .appendTo( this.$ ); // Toolbar this.$toolbar = $( '
' ) .prop( 'class', 've-ui-context-toolbar'); // Toolbar view this.toolbarView = new ve.ui.Toolbar( this.$toolbar, this.surfaceView, [{ 'name': 'textStyle', 'items' : [ 'bold', 'italic', 'link', 'clear' ] }] ); // Context Menu this.menuView = new ve.ui.Menu( [ // Example menu items { 'name': 'tools', '$': this.$toolbar } ], null, this.$ ); // Events this.$icon.on( { 'mousedown': ve.bind( this.onMouseDown, this ), 'mouseup': ve.bind( this.onMouseUp, this ) } ); this.surfaceView.getDocument().getDocumentNode().$.on( { 'focus': ve.bind( this.onDocumentFocus, this ), 'blur': ve.bind( this.onDocumentBlur, this ) } ); // Setup Inspectors. this.setupInspectorSpace(); }; /* Methods */ ve.ui.Context.prototype.setupInspectorSpace = function () { var $styleLink; // Inspector container this.$inspectors = $( '
' ) .prop( 'class', 've-ui-context-inspectors' ) .appendTo( this.$ ); // Overlay in main document scope for positioning elements over iframe. this.$iframeOverlay = $( '
' ) .prop( 'class', 've-iframe-overlay' ) .appendTo( this.$inspectors ); // Create and append an iframe to contain inspectors. // NOTE: Inspectors are required to be inside the iframe to prevent loss of content selection. this.$inspectorFrame = $( '