https://www.mediawiki.org/wiki/Special:Code/MediaWiki/105451
Revision: 105451 Author: tparscal Date: 2011-12-07 19:16:40 +0000 (Wed, 07 Dec 2011) Log Message: ----------- * Simplified context menu * Added typeOnly option to getIndexOfAnnotation * Fixed overly-strict checking for annotations in toolbar Modified Paths: -------------- trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js trunk/extensions/VisualEditor/modules/es/styles/es.ContextView.css trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js trunk/extensions/VisualEditor/modules/es/views/es.ContextView.js Modified: trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js =================================================================== --- trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js 2011-12-07 19:05:08 UTC (rev 105450) +++ trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js 2011-12-07 19:16:40 UTC (rev 105451) @@ -160,9 +160,10 @@ * @method * @param {Array} annotations Annotations to search through * @param {Object} annotation Annotation to search for + * @param {Boolean} typeOnly Whether to only consider the type * @returns {Integer} Index of annotation in annotations, or -1 if annotation was not found */ -es.DocumentModel.getIndexOfAnnotation = function( annotations, annotation ) { +es.DocumentModel.getIndexOfAnnotation = function( annotations, annotation, typeOnly ) { if ( annotation === undefined || annotation.type === undefined ) { throw 'Invalid annotation error. Can not find non-annotation data in character.'; } @@ -173,7 +174,18 @@ if ( typeof annotations[i] === 'string' ) { continue; } - if ( annotations[i].hash === ( annotation.hash || es.DocumentModel.getHash( annotation ) ) ) { + if ( + ( + typeOnly && + annotations[i].type === annotation.type + ) || + ( + !typeOnly && + annotations[i].hash === ( + annotation.hash || es.DocumentModel.getHash( annotation ) + ) + ) + ) { return i; } } Modified: trunk/extensions/VisualEditor/modules/es/styles/es.ContextView.css =================================================================== --- trunk/extensions/VisualEditor/modules/es/styles/es.ContextView.css 2011-12-07 19:05:08 UTC (rev 105450) +++ trunk/extensions/VisualEditor/modules/es/styles/es.ContextView.css 2011-12-07 19:16:40 UTC (rev 105451) @@ -54,14 +54,6 @@ top: 3px; } -.es-contextView-position-left .es-menuView { - left: -1px; -} - -.es-contextView-position-right .es-menuView { - right: -1px; -} - .es-contextView-panels { position: absolute; border: solid 1px #cccccc; @@ -85,3 +77,7 @@ padding: 0.33em 0.66em; white-space: nowrap; } + +.es-contextView .es-toolbarGroup { + border: none; +} \ No newline at end of file Modified: trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js =================================================================== --- trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js 2011-12-07 19:05:08 UTC (rev 105450) +++ trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js 2011-12-07 19:16:40 UTC (rev 105451) @@ -24,7 +24,7 @@ }; es.AnnotationButtonTool.prototype.updateState = function( annotations, nodes ) { - if ( es.DocumentModel.getIndexOfAnnotation( annotations.full, this.annotation ) !== -1 ) { + if ( es.DocumentModel.getIndexOfAnnotation( annotations.full, this.annotation, true ) !== -1 ) { this.$.addClass( 'es-toolbarButtonTool-down' ); this.active = true; return; Modified: trunk/extensions/VisualEditor/modules/es/views/es.ContextView.js =================================================================== --- trunk/extensions/VisualEditor/modules/es/views/es.ContextView.js 2011-12-07 19:05:08 UTC (rev 105450) +++ trunk/extensions/VisualEditor/modules/es/views/es.ContextView.js 2011-12-07 19:16:40 UTC (rev 105451) @@ -16,26 +16,11 @@ this.toolbarView = new es.ToolbarView( this.$toolbar, this.surfaceView, - [{ 'name': 'textStyle', 'items' : [ 'bold', 'italic', 'formatting', 'clear' ] }] + [{ 'name': 'textStyle', 'items' : [ 'bold', 'italic', 'link', 'clear' ] }] ); this.menuView = new es.MenuView( [ // Example menu items - { 'name': 'tools', '$': this.$toolbar }, - '-', - { 'name': 'link', 'label': 'Link to...', 'callback': function( item ) { - _this.menuView.hide(); - _this.$panels - .show() - .find( '[rel="link"]' ) - .show() - .end() - .find( '[rel="link"] input:first' ) - .focus(); - } }, - '-', - { 'name': 'copy', 'label': 'Copy' }, - { 'name': 'cut', 'label': 'Cut' }, - { 'name': 'paste', 'label': 'Paste' } + { 'name': 'tools', '$': this.$toolbar } ], null, this.$ @@ -100,13 +85,27 @@ } } if ( position ) { - if ( position.left + this.menuView.$.width() < $( 'body' ).width() ) { - this.$.addClass( 'es-contextView-position-left' ); - } else { - this.$.addClass( 'es-contextView-position-right' ); + var $menu = this.menuView.$, + menuMargin = 5, + menuWidth = $menu.width(), + menuHeight = $menu.height(), + $window = $( window ), + windowWidth = $window.width(), + windowHeight = $window.height(), + windowScrollTop = $window.scrollTop(); + // Center align menu + var menuLeft = -Math.round( menuWidth / 2 ); + // Adjust menu left or right depending on viewport + if ( ( position.left - menuMargin ) + menuLeft < 0 ) { + // Move right a bit past center + menuLeft -= position.left + menuLeft - menuMargin; + } else if ( ( menuMargin + position.left ) - menuLeft > windowWidth ) { + // Move left a bit past center + menuLeft += windowWidth - menuMargin - ( position.left - menuLeft ); } - var $window = $( window ); - if ( position.top + this.menuView.$.height() < $window.height() + $window.scrollTop() ) { + $menu.css( 'left', menuLeft ); + // Position menu on top or bottom depending on viewport + if ( position.top + menuHeight < windowHeight + windowScrollTop ) { this.$.addClass( 'es-contextView-position-below' ); } else { this.$.addClass( 'es-contextView-position-above' ); _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs