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
24 !(f && f.isValid()) ||
25 !((f instanceof f.CaretFragment) || (f instanceof f.TextRangeFragment && f.getCommonParent()))
27 return _.extend(state, {
29 description: 'wrong or no selection'
33 var node = f instanceof f.CaretFragment ? f.node.parent() : f.getCommonParent(),
34 alreadyInTarget = node.isInside(createParams.to),
37 if(!toSwitch.is(createParams.from)) {
38 toSwitch = toSwitch.getParent(createParams.from);
41 description = 'Switch to ' + createParams.to.name;
42 return _.extend(state, {
44 toggled: alreadyInTarget,
45 description: description,
46 execute: alreadyInTarget ? function() {} : function(callback) {
47 f.document.transaction(function() {
48 if(createParams.to.tagName) {
49 toSwitch = toSwitch.setTag(createParams.to.tagName);
51 if(!_.isUndefined(createParams.to.klass)) {
52 toSwitch.setClass(createParams.to.klass);
56 description: description
69 createSwitchAction({name: 'switchToHeader', from: {tagName: 'div', klass: 'p'}, to: {tagName: 'header', klass: '', name: gettext('header')}}),
70 createSwitchAction({name: 'switchToParagraph', from: {tagName: 'header'}, to: {tagName: 'div', klass: 'p', name: gettext('paragraf')}})