Skip to content

Commit

Permalink
Fixes bug with floatingmenu's reading of configuration settings, and …
Browse files Browse the repository at this point in the history
…fixes positioning of floatingmenu when the view port is scrolled.
  • Loading branch information
Petro Salema committed Feb 9, 2012
1 parent 2c13731 commit b7c8920
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,10 @@ All changes are categorized into one of the following keywords:
usage, or intent of an existing one.

## 0.20.6 - SNAPSHOT
- **BUG** floatingmenu: Fixed floating menu's reading of configuration values
so that they are parsed into numbers.
- **BUG** floatingmenu: Fixed floating menu positioning when view port is
scrolled so that it takes into account the aligntopOffset setting.


## 0.20.5 - 2012/02/09
Expand Down
3 changes: 2 additions & 1 deletion src/demo/boilerplate/index.html
Expand Up @@ -35,7 +35,8 @@
common/abbr,
extra/wai-lang,
extra/browser,
extra/linkbrowser"></script>
extra/linkbrowser,
extra/cite"></script>
<script src="js/aloha-boilerplate.js"></script>
</head>
<body>
Expand Down
6 changes: 4 additions & 2 deletions src/demo/boilerplate/js/aloha-config.js
Expand Up @@ -7,8 +7,10 @@
ribbon: false,
locale: 'en',
floatingmenu: {
width: 630,
behaviour: 'topalign'
"horizontalOffset" : "5",
"behaviour" : "topalign",
"width" : "510",
"topalignOffset" : "110"
},
repositories: {
linklist: {
Expand Down
82 changes: 46 additions & 36 deletions src/lib/aloha/floatingmenu.js
Expand Up @@ -290,39 +290,39 @@ function(Aloha, jQuery, Ext, Class, console) {
var element = floatingmenu.obj;
var editablePos = Aloha.activeEditable.obj.offset();
var isTopAligned = floatingmenu.behaviour === 'topalign';
var isManuallyPinned = floatingmenu.pinned
&& ( parseInt( element.css( 'left' ), 10 )
!= ( editablePos.left
+ floatingmenu.horizontalOffset
) );
var isManuallyPinned = floatingmenu.pinned &&
( parseInt( element.css( 'left' ), 10 ) !=
( editablePos.left +
floatingmenu.horizontalOffset ) );

if ( isTopAligned && isManuallyPinned ) {
return;
}

var floatingmenuHeight = element.height();
var scrollTop = jQuery(document).scrollTop();
var scrollTop = jQuery( document ).scrollTop();

// This value is what the top position of the floating menu
// *would* be if we tried to position it above the active
// editable.
// This value is what the top position of the floating menu *would* be
// if we tried to position it above the active editable.
var floatingmenuTop = editablePos.top - floatingmenuHeight
+ floatingmenu.marginTop;
+ floatingmenu.marginTop
- floatingmenu.topalignOffset;

// The floating menu does not fit in the space between the top
// of the viewport and the editable, so position it at the top
// of the viewport, and over the editable.
// The floating menu does not fit in the space between the top of the
// viewport and the editable, so position it at the top of the viewport
// and over the editable.
if ( scrollTop > floatingmenuTop ) {
editablePos.top = isTopAligned
? scrollTop + floatingmenu.marginTop
: floatingmenu.marginTop;

// There is enough space on top of the editable to fit the
// entire floating menu, so we do so.
// There is enough space on top of the editable to fit the entire
// floating menu, so we do so.
} else if ( scrollTop <= floatingmenuTop ) {
editablePos.top -= floatingmenuHeight
+ ( isTopAligned
? floatingmenu.marginTop
? floatingmenu.marginTop +
floatingmenu.topalignOffset
: 0 );
}

Expand Down Expand Up @@ -455,38 +455,48 @@ function(Aloha, jQuery, Ext, Class, console) {
init: function() {

// check for behaviour setting of the floating menu
if (Aloha.settings.floatingmenu) {

if (typeof Aloha.settings.floatingmenu.draggable === 'boolean') {
if ( Aloha.settings.floatingmenu ) {
if ( typeof Aloha.settings.floatingmenu.draggable ===
'boolean' ) {
this.draggable = Aloha.settings.floatingmenu.draggable;
}
if (typeof Aloha.settings.floatingmenu.behaviour === 'string') {

if ( typeof Aloha.settings.floatingmenu.behaviour ===
'string' ) {
this.behaviour = Aloha.settings.floatingmenu.behaviour;
}
if (typeof Aloha.settings.floatingmenu.topalignOffset !== 'undefined') {
this.topalignOffset = Aloha.settings.floatingmenu.topalignOffset;

if ( typeof Aloha.settings.floatingmenu.topalignOffset !==
'undefined' ) {
this.topalignOffset = parseInt(
Aloha.settings.floatingmenu.topalignOffset, 10 );
}
if (typeof Aloha.settings.floatingmenu.horizontalOffset !== 'undefined') {
this.horizontalOffset = Aloha.settings.floatingmenu.horizontalOffset;

if ( typeof Aloha.settings.floatingmenu.horizontalOffset !==
'undefined' ) {
this.horizontalOffset = parseInt(
Aloha.settings.floatingmenu.horizontalOffset , 10 );
}
if (typeof Aloha.settings.floatingmenu.marginTop === 'number') {
this.marginTop = Aloha.settings.floatingmenu.marginTop;

if ( typeof Aloha.settings.floatingmenu.marginTop ===
'number' ) {
this.marginTop = parseInt(
Aloha.settings.floatingmenu.marginTop , 10 );
}
//We just check for undefined
if (typeof Aloha.settings.floatingmenu.width !== 'undefined') {
//Try to pars it
try {
var parsed = parseInt(Aloha.settings.floatingmenu.width);
this.width = Aloha.settings.floatingmenu.width;
} catch(e) {
//do nothing.
}

if ( typeof Aloha.settings.floatingmenu.width !==
'undefined' ) {
this.width = parseInt( Aloha.settings.floatingmenu.width,
10 );
}
}

jQuery.storage = new jQuery.store();

this.currentScope = 'Aloha.global';

var that = this;

this.window.unload(function () {
// store fm position if the panel is pinned to be able to restore it next time
if (that.pinned) {
Expand Down Expand Up @@ -846,7 +856,7 @@ function(Aloha, jQuery, Ext, Class, console) {
var HORIZONTAL_PADDING = 10;
// Calculate by how much the floating menu is pocking
// outside the width of the viewport. A positive number
// means that is is outside the viewport, negative means
// means that it is outside the viewport, negative means
// it is within the viewport.
var overhang = ( ( editablePos.left + that.width
+ HORIZONTAL_PADDING ) - jQuery(window).width() );
Expand Down

0 comments on commit b7c8920

Please sign in to comment.