Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Commit

Permalink
Merge d9b2889 into d258be0
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkloud9 committed Oct 15, 2015
2 parents d258be0 + d9b2889 commit 83fab71
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
Binary file not shown.
19 changes: 19 additions & 0 deletions app/scripts/directives/sf-aloha-format-generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ angular.module('authoringEnvironmentApp').directive('sfAlohaFormatGeneric', [
element.attr('disabled', !supported || !enabled);

element.bind('click', function () {
// this block sets the Aloha.activeEditable
// to the editable of the current Aloha.Selection
// needed due to a bug with the formatBlock function
var selEditableId = $(Aloha.Selection
.rangeObject.limitObject)[0].id;
for (var i = 0; i < Aloha.editables.length; i++) {
var editable = Aloha.editables[i];
if (selEditableId === editable.obj[0].id) {
Aloha.activeEditable = Aloha.editables[i];
}
}

// for some reason execCommand does not trigger
// a change event (ff browser only). We need this
// to fire to enable the article save button
Aloha.trigger('aloha-smart-content-changed', {
'editable': Aloha.activeEditable
});

Aloha.execCommand(scope.alohaElement, false, '');
element.toggleClass(
'active',
Expand Down
Binary file not shown.
75 changes: 75 additions & 0 deletions test/spec/directives/sf-aloha-format-generic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict';

/**
* Module with tests for the droppedImage directive.
*
* @module droppedImage directive tests
*/

describe('Directive: sfAlohaFormatGeneric', function () {
var isoScope,
scope,
element,
oldAloha,
$rootScope;

beforeEach(module('authoringEnvironmentApp'));

beforeEach(inject(function (_$rootScope_, $compile) {
var html;

html = [
'<button sf-aloha-format-generic ',
' data-button-name="{{name}}" ',
' data-aloha-element="{{element}}">',
'</button> ',
].join('');

$rootScope = _$rootScope_;
scope = $rootScope.$new();
scope.name = 'Italics';
scope.element = 'Italics';
element = $compile(html)(scope);
scope.$digest();

isoScope = element.isolateScope();

oldAloha = Aloha;
Aloha.execCommand = function () { return true; };
Aloha.trigger = function () { return true; };
Aloha.Selection = {
rangeObject: {
limitObject: [
{
id: 'test-id'
}
]
}
};
}));

afterEach(function () {
Aloha = oldAloha;
});

it('called the correct Aloha.execCommand', function () {
var execCommandSpy = spyOn(Aloha, 'execCommand').andReturn(true);

isoScope.alohaElement = 'Bold';
element.click();

expect(execCommandSpy).toHaveBeenCalledWith(
'Bold', false, '');
});

it('triggers aloha-smart-content-changed Aloha.execCommand', function () {
var execCommandSpy = spyOn(Aloha, 'execCommand').andReturn(true);
var triggerSpy = spyOn(Aloha, 'trigger').andReturn(true);

isoScope.alohaElement = 'something-that-is-not-bold';
element.click();

expect(triggerSpy).toHaveBeenCalled();
});
});

0 comments on commit 83fab71

Please sign in to comment.