Skip to content

Commit

Permalink
cite plugin: option for auto-open sidebar; table plugin: col/row form…
Browse files Browse the repository at this point in the history
…atting; format plugin: enable table cell formating
  • Loading branch information
evo42 committed Feb 9, 2012
1 parent 4e9b8a8 commit e444253
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 43 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -14,7 +14,9 @@ All changes are categorized into one of the following keywords:

## 0.20.5 - SNAPSHOT

- **BUG**: paste plugin: removed trim of pasted contents -- test[ text] + 2x c&p results now in test text text instead of testtexttext
- **BUG** paste plugin: removed trim of pasted contents -- test[ text] + 2x c&p results now in test text text instead of testtexttext
- **BUG** format/table plugin: added a workaround in the format plugin to enable formating of selected cells
- **ENHANCEMENT** cite plugin: config option if sidebar should auto open or not (Aloha.settings.plugins.cite.sidebar.open: true|false)


## 0.20.4 - 2012/01/27
Expand Down
56 changes: 55 additions & 1 deletion src/plugins/common/format/lib/format-plugin.js
Expand Up @@ -121,7 +121,34 @@ function(Aloha, Plugin, jQuery, FloatingMenu, i18n, i18nCore) {
var
markup = jQuery('<'+button+'></'+button+'>'),
rangeObject = Aloha.Selection.rangeObject,
foundMarkup;
foundMarkup,
selectedCells = jQuery('.aloha-cell-selected');

// formating workaround for table plugin
if ( selectedCells.length > 0 ) {
var cellMarkupCounter = 0;
selectedCells.each( function () {
var cellContent = jQuery(this).find('div'),
cellMarkup = cellContent.find(button);

if ( cellMarkup.length > 0 ) {
// unwrap all found markup text
// <td><b>text</b> foo <b>bar</b></td>
// and wrap the whole contents of the <td> into <b> tags
// <td><b>text foo bar</b></td>
cellMarkup.contents().unwrap();
cellMarkupCounter++;
}
cellContent.contents().wrap('<'+button+'></'+button+'>');
});

// remove all markup if all cells have markup
if ( cellMarkupCounter == selectedCells.length ) {
selectedCells.find(button).contents().unwrap();
}
return false;
}
// formating workaround for table plugin

// check whether the markup is found in the range (at the start of the range)
foundMarkup = rangeObject.findMarkup(function() {
Expand Down Expand Up @@ -176,6 +203,33 @@ function(Aloha, Plugin, jQuery, FloatingMenu, i18n, i18nCore) {
'iconClass' : 'aloha-button ' + i18n.t('aloha-button-' + button),
'markup' : jQuery('<'+button+'></'+button+'>'),
'click' : function() {
var selectedCells = jQuery('.aloha-cell-selected');
// formating workaround for table plugin
if ( selectedCells.length > 0 ) {
var cellMarkupCounter = 0;
selectedCells.each( function () {
var cellContent = jQuery(this).find('div'),
cellMarkup = cellContent.find(button);

if ( cellMarkup.length > 0 ) {
// unwrap all found markup text
// <td><b>text</b> foo <b>bar</b></td>
// and wrap the whole contents of the <td> into <b> tags
// <td><b>text foo bar</b></td>
cellMarkup.contents().unwrap();
cellMarkupCounter++;
}
cellContent.contents().wrap('<'+button+'></'+button+'>');
});

// remove all markup if all cells have markup
if ( cellMarkupCounter == selectedCells.length ) {
selectedCells.find(button).contents().unwrap();
}
return false;
}
// formating workaround for table plugin

Aloha.Selection.changeMarkupOnSelection(jQuery('<' + button + '></' + button + '>'));

This comment has been minimized.

Copy link
@deliminator

deliminator Mar 21, 2012

Contributor

Hallo Rene, bitte code nicht copy & pasten. Bitte diesen block und den davor in eine function herausfactorizieren.

This comment has been minimized.

Copy link
@evo42

evo42 Mar 22, 2012

Author Member

I'll do so.

}
});
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/common/table/lib/table-cell.js
Expand Up @@ -115,7 +115,6 @@ function (jQuery, Utils) {
// Disabled the dragging of content, since it makes cell selection difficult
this.wrapper.get( 0 ).ondragstart = function () { return false };
}

return this;
};

Expand Down Expand Up @@ -228,20 +227,23 @@ function (jQuery, Utils) {
*/
TableCell.prototype._startCellSelection = function(){
if(!this.tableObj.selection.cellSelectionMode){

//unselect currently selected cells
this.tableObj.selection.unselectCells();

// activate cell selection mode
this.tableObj.selection.cellSelectionMode = true;

//bind a global mouseup event handler to stop cell selection
var that = this;
jQuery('body').bind('mouseup.cellselection', function(){
that._endCellSelection();

});

this.tableObj.selection.baseCellPosition = [this._virtualY(), this._virtualX()];


}
};

Expand Down
68 changes: 34 additions & 34 deletions src/plugins/common/table/lib/table-plugin.js
Expand Up @@ -626,16 +626,19 @@ define( [
var sc = that.activeTable.selection.selectedCells;
// if a selection was made, transform the selected cells
for (var i = 0; i < sc.length; i++) {
for (var j = 0; j < sc[i].length; j++) {
// remove all row formattings
for (var f = 0; f < that.rowConfig.length; f++) {
jQuery(sc[i][j]).removeClass(that.rowConfig[f].cssClass);
}
// set new style
jQuery(sc[i][j]).addClass(itemConf.cssClass);
}
if ( jQuery(sc[i]).attr('class').indexOf(itemConf.cssClass) > -1 ) {
jQuery(sc[i]).removeClass(itemConf.cssClass);
} else {
jQuery(sc[i]).addClass(itemConf.cssClass);
// remove all row formattings
for (var f = 0; f < that.rowConfig.length; f++) {
if (that.rowConfig[f].cssClass != itemConf.cssClass) {
jQuery(sc[i]).removeClass(that.rowConfig[f].cssClass);
}
}

}
}

// selection could have changed.
that.activeTable.selectRows();
}
Expand All @@ -651,21 +654,18 @@ define( [
iconClass: 'aloha-button aloha-button-removeFormat',
wide: true,
click: function () {
if (that.activeTable) {
var sc = that.activeTable.selection.selectedCells;
// if a selection was made, transform the selected cells
for (var i = 0; i < sc.length; i++) {
for (var j = 0; j < sc[i].length; j++) {
for (var f = 0; f < that.rowConfig.length; f++) {
jQuery(sc[i][j]).removeClass(that.rowConfig[f].cssClass);
}
}
}

// selection could have changed.
that.activeTable.selectRows();
}
}
if (that.activeTable) {
var sc = that.activeTable.selection.selectedCells;
// if a selection was made, transform the selected cells
for (var i = 0; i < sc.length; i++) {
for (var f = 0; f < that.rowConfig.length; f++) {
jQuery(sc[i]).removeClass(that.rowConfig[f].cssClass);
}
}
// selection could have changed.
that.activeTable.selectRows();
}
}
});
}

Expand Down Expand Up @@ -852,13 +852,16 @@ define( [
var sc = that.activeTable.selection.selectedCells;
// if a selection was made, transform the selected cells
for (var i = 0; i < sc.length; i++) {
for (var j = 0; j < sc[i].length; j++) {
// remove all columnformattings
if ( jQuery(sc[i]).attr('class').indexOf(itemConf.cssClass) > -1 ) {
jQuery(sc[i]).removeClass(itemConf.cssClass);
} else {
jQuery(sc[i]).addClass(itemConf.cssClass);
// remove all column formattings
for (var f = 0; f < that.columnConfig.length; f++) {
jQuery(sc[i][j]).removeClass(that.columnConfig[f].cssClass);
if (that.columnConfig[f].cssClass != itemConf.cssClass) {
jQuery(sc[i]).removeClass(that.columnConfig[f].cssClass);
}
}
// set new style
jQuery(sc[i][j]).addClass(itemConf.cssClass);
}
}
// selection could have changed.
Expand All @@ -882,13 +885,10 @@ define( [
var sc = that.activeTable.selection.selectedCells;
// if a selection was made, transform the selected cells
for (var i = 0; i < sc.length; i++) {
for (var j = 0; j < sc[i].length; j++) {
for (var f = 0; f < that.columnConfig.length; f++) {
jQuery(sc[i][j]).removeClass(that.columnConfig[f].cssClass);
}
for (var f = 0; f < that.columnConfig.length; f++) {
jQuery(sc[i]).removeClass(that.columnConfig[f].cssClass);
}
}

// selection could have changed.
that.activeTable.selectColumns();
}
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/common/table/lib/table-selection.js
Expand Up @@ -128,6 +128,9 @@ function (Aloha, $, Utils, TableCell, i18n) {
TableSelection.prototype.notifyCellsSelected = function () {
Aloha.trigger( 'aloha-table-selection-changed' );

// @workaround to enable formating of all selected cells with eg. bold style from format plugin
//$('.aloha-table').contentEditable( true );

// the UI feels more consisten when we remove the non-table
// selection when cells are selected
// TODO this code doesn't work right in IE as it causes the table
Expand All @@ -143,6 +146,9 @@ function (Aloha, $, Utils, TableCell, i18n) {
*/
TableSelection.prototype._notifyCellsUnselected = function () {
Aloha.trigger( 'aloha-table-selection-changed' );

// @workaround to disable formating of all selected cells with eg. bold style from format plugin
//$('.aloha-table').contentEditable( false );
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/plugins/common/table/lib/table.js
Expand Up @@ -359,6 +359,7 @@ define( [
// Disable resize and selection of the controls (only IE)
// Events only can be set to elements which are loaded from the DOM (if they
// were created dynamically before) ;)

htmlTableWrapper = this.obj.parents( '.' + this.get( 'classTableWrapper' ) );
htmlTableWrapper.get( 0 ).onresizestart = function ( e ) { return false; };
htmlTableWrapper.get( 0 ).oncontrolselect = function ( e ) { return false; };
Expand Down
22 changes: 18 additions & 4 deletions src/plugins/extra/cite/lib/cite-plugin.js
Expand Up @@ -136,6 +136,7 @@ define([

citations: [],
referenceContainer: null,
settings: null,

init: function () {
var that = this;
Expand All @@ -144,13 +145,24 @@ define([
// the plugin
if (Aloha.settings &&
Aloha.settings.plugins &&
Aloha.settings.plugins.cite &&
Aloha.settings.plugins.cite) {
var referenceContainer = $(Aloha.settings.plugins.cite.referenceContainer);

if (referenceContainer.length > 0) {
this.referenceContainer = referenceContainer;
}

if ( typeof Aloha.settings.plugins.cite != 'undefinded' ) {
that.settings = Aloha.settings.plugins.cite;
}

if ( typeof that.settings.sidebar === 'undefinded' ) {
that.settings.sidebar = {};
}

if ( typeof that.settings.sidebar.open === 'undefinded' ) {
that.settings.sidebar.open = true;
}
}

// Add the inline quote button in the floating menu, in the
Expand Down Expand Up @@ -332,6 +344,7 @@ define([
},

addBlockQuote: function () {
var that = this;
var classes = [nsClass('wrapper'), nsClass(++uid)].join(' ');
var markup = $(supplant(
'<blockquote class="{classes}" data-cite-id="{uid}"></blockquote>',
Expand All @@ -347,7 +360,7 @@ define([

this.referenceContainer && this.addCiteToReferences(uid);

if (this.sidebar) {
if (this.sidebar && that.settings.sidebar.open === true) {
this.sidebar.open();
}
// .activatePanel(nsClass('sidebar-panel'), markup);
Expand All @@ -361,6 +374,7 @@ define([
));
var rangeObject = Aloha.Selection.rangeObject;
var foundMarkup;
var that = this;

// now re enable the editable
if (Aloha.activeEditable) {
Expand Down Expand Up @@ -401,8 +415,8 @@ define([
rangeObject.select();

this.referenceContainer && this.addCiteToReferences(uid);
if (this.sidebar) {

if (this.sidebar && that.settings.sidebar.open === true) {
this.sidebar.open();
}
// .activatePanel(nsClass('sidebar-panel'), markup);
Expand Down

0 comments on commit e444253

Please sign in to comment.