r105451 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105450‎ | r105451 | r105452 >
Date:19:16, 7 December 2011
Author:tparscal
Status:deferred
Tags:
Comment:
* 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 (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/styles/es.ContextView.css (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/views/es.ContextView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js
@@ -24,7 +24,7 @@
2525 };
2626
2727 es.AnnotationButtonTool.prototype.updateState = function( annotations, nodes ) {
28 - if ( es.DocumentModel.getIndexOfAnnotation( annotations.full, this.annotation ) !== -1 ) {
 28+ if ( es.DocumentModel.getIndexOfAnnotation( annotations.full, this.annotation, true ) !== -1 ) {
2929 this.$.addClass( 'es-toolbarButtonTool-down' );
3030 this.active = true;
3131 return;
Index: trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js
@@ -160,9 +160,10 @@
161161 * @method
162162 * @param {Array} annotations Annotations to search through
163163 * @param {Object} annotation Annotation to search for
 164+ * @param {Boolean} typeOnly Whether to only consider the type
164165 * @returns {Integer} Index of annotation in annotations, or -1 if annotation was not found
165166 */
166 -es.DocumentModel.getIndexOfAnnotation = function( annotations, annotation ) {
 167+es.DocumentModel.getIndexOfAnnotation = function( annotations, annotation, typeOnly ) {
167168 if ( annotation === undefined || annotation.type === undefined ) {
168169 throw 'Invalid annotation error. Can not find non-annotation data in character.';
169170 }
@@ -173,7 +174,18 @@
174175 if ( typeof annotations[i] === 'string' ) {
175176 continue;
176177 }
177 - if ( annotations[i].hash === ( annotation.hash || es.DocumentModel.getHash( annotation ) ) ) {
 178+ if (
 179+ (
 180+ typeOnly &&
 181+ annotations[i].type === annotation.type
 182+ ) ||
 183+ (
 184+ !typeOnly &&
 185+ annotations[i].hash === (
 186+ annotation.hash || es.DocumentModel.getHash( annotation )
 187+ )
 188+ )
 189+ ) {
178190 return i;
179191 }
180192 }
Index: trunk/extensions/VisualEditor/modules/es/styles/es.ContextView.css
@@ -54,14 +54,6 @@
5555 top: 3px;
5656 }
5757
58 -.es-contextView-position-left .es-menuView {
59 - left: -1px;
60 -}
61 -
62 -.es-contextView-position-right .es-menuView {
63 - right: -1px;
64 -}
65 -
6658 .es-contextView-panels {
6759 position: absolute;
6860 border: solid 1px #cccccc;
@@ -85,3 +77,7 @@
8678 padding: 0.33em 0.66em;
8779 white-space: nowrap;
8880 }
 81+
 82+.es-contextView .es-toolbarGroup {
 83+ border: none;
 84+}
\ No newline at end of file
Index: trunk/extensions/VisualEditor/modules/es/views/es.ContextView.js
@@ -16,26 +16,11 @@
1717 this.toolbarView = new es.ToolbarView(
1818 this.$toolbar,
1919 this.surfaceView,
20 - [{ 'name': 'textStyle', 'items' : [ 'bold', 'italic', 'formatting', 'clear' ] }]
 20+ [{ 'name': 'textStyle', 'items' : [ 'bold', 'italic', 'link', 'clear' ] }]
2121 );
2222 this.menuView = new es.MenuView( [
2323 // Example menu items
24 - { 'name': 'tools', '$': this.$toolbar },
25 - '-',
26 - { 'name': 'link', 'label': 'Link to...', 'callback': function( item ) {
27 - _this.menuView.hide();
28 - _this.$panels
29 - .show()
30 - .find( '[rel="link"]' )
31 - .show()
32 - .end()
33 - .find( '[rel="link"] input:first' )
34 - .focus();
35 - } },
36 - '-',
37 - { 'name': 'copy', 'label': 'Copy' },
38 - { 'name': 'cut', 'label': 'Cut' },
39 - { 'name': 'paste', 'label': 'Paste' }
 24+ { 'name': 'tools', '$': this.$toolbar }
4025 ],
4126 null,
4227 this.$
@@ -100,13 +85,27 @@
10186 }
10287 }
10388 if ( position ) {
104 - if ( position.left + this.menuView.$.width() < $( 'body' ).width() ) {
105 - this.$.addClass( 'es-contextView-position-left' );
106 - } else {
107 - this.$.addClass( 'es-contextView-position-right' );
 89+ var $menu = this.menuView.$,
 90+ menuMargin = 5,
 91+ menuWidth = $menu.width(),
 92+ menuHeight = $menu.height(),
 93+ $window = $( window ),
 94+ windowWidth = $window.width(),
 95+ windowHeight = $window.height(),
 96+ windowScrollTop = $window.scrollTop();
 97+ // Center align menu
 98+ var menuLeft = -Math.round( menuWidth / 2 );
 99+ // Adjust menu left or right depending on viewport
 100+ if ( ( position.left - menuMargin ) + menuLeft < 0 ) {
 101+ // Move right a bit past center
 102+ menuLeft -= position.left + menuLeft - menuMargin;
 103+ } else if ( ( menuMargin + position.left ) - menuLeft > windowWidth ) {
 104+ // Move left a bit past center
 105+ menuLeft += windowWidth - menuMargin - ( position.left - menuLeft );
108106 }
109 - var $window = $( window );
110 - if ( position.top + this.menuView.$.height() < $window.height() + $window.scrollTop() ) {
 107+ $menu.css( 'left', menuLeft );
 108+ // Position menu on top or bottom depending on viewport
 109+ if ( position.top + menuHeight < windowHeight + windowScrollTop ) {
111110 this.$.addClass( 'es-contextView-position-below' );
112111 } else {
113112 this.$.addClass( 'es-contextView-position-above' );

Status & tagging log