1 define(function(require) {
6 var _ = require('libs/underscore');
9 var createSwitchAction = function(createParams) {
11 name: createParams.name,
13 fragment: {type: 'context', name: 'fragment'},
15 getState: function(params) {
17 label: this.config.label
23 !(f && f.isValid()) ||
24 !((f instanceof f.CaretFragment) || (f instanceof f.TextRangeFragment && f.getCommonParent()))
26 return _.extend(state, {
28 description: 'wrong or no selection'
32 var node = f instanceof f.CaretFragment ? f.node.parent() : f.getCommonParent(),
33 alreadyInTarget = node.isInside(createParams.to),
36 if(!toSwitch.is(createParams.from)) {
37 toSwitch = toSwitch.getParent(createParams.from);
40 return _.extend(state, {
42 toggled: alreadyInTarget,
43 description: 'Switch to ' + createParams.to.name,
44 execute: alreadyInTarget ? function() {} : function() {
45 f.document.transaction(function() {
46 if(createParams.to.tagName) {
47 toSwitch = toSwitch.setTag(createParams.to.tagName);
49 if(!_.isUndefined(createParams.to.klass)) {
50 toSwitch.setClass(createParams.to.klass);
62 createSwitchAction({name: 'switchToHeader', from: {tagName: 'div', klass: 'p'}, to: {tagName: 'header', klass: '', name: gettext('header')}}),
63 createSwitchAction({name: 'switchToParagraph', from: {tagName: 'header'}, to: {tagName: 'div', klass: 'p', name: gettext('paragraf')}})