4 /* globals gettext, interpolate */
7 var getBoundriesForAList = function(fragment) {
10 if(fragment instanceof fragment.RangeFragment && fragment.hasSiblingBoundries()) {
11 return fragment.boundriesSiblingParents();
13 if(fragment instanceof fragment.NodeFragment) {
14 node = fragment.node.getNearestElementNode();
22 var countItems = function(boundries) {
23 var ptr = boundries.node1,
25 while(ptr && !ptr.sameNode(boundries.node2)) {
32 var toggleListAction = function(type) {
35 add: function(params) {
36 var boundries = getBoundriesForAList(params.fragment),
37 listParams = {klass: type === 'Bullet' ? 'list' : 'list.enum'};
38 if(boundries && boundries.node1) {
39 listParams.node1 = boundries.node1;
40 listParams.node2 = boundries.node2;
41 boundries.node1.document.createList(listParams);
43 throw new Error('Invalid boundries');
46 remove: function(params) {
48 var current = params.fragment.node;
50 var toSearch = current.nodeType === Node.ELEMENT_NODE ? [current] : [];
51 toSearch = toSearch.concat(current.parents());
52 toSearch.some(function(node) {
54 node.object.extractListItems();
59 changeType: function(params) {
60 params.fragment.node.getParent('list').setClass(type === 'Bullet' ? 'list' : 'list.enum');
64 var isToggled = function(params) {
65 if(params.fragment && params.fragment.node && params.fragment.node.isInside('list')) {
66 var list = params.fragment.node.getParent('list');
67 return list.getClass() === (type === 'Bullet' ? 'list' : 'list.enum');
74 name: 'toggle' + type + 'List',
75 context: ['fragment'],
77 fragment: {type: 'context', name: 'fragment'}
80 label: type === 'Bullet' ? gettext('bull. list') : gettext('num. list')
82 getState: function(params) {
83 if(!params.fragment || !params.fragment.isValid()) {
87 if(params.fragment instanceof params.fragment.CaretFragment && params.fragment.node.isInside('list')) {
88 var list = params.fragment.node.getParent('list');
89 if((list.getClass() === 'list' && type === 'Enum') || (list.getClass() === 'list.enum' && type === 'Bullet')) {
92 description: interpolate(gettext('Change list type to %s'), [type]),
93 execute: execute.changeType
98 toggled: isToggled(params),
99 description: gettext('Remove list'),
100 execute: execute.remove
104 var boundries = getBoundriesForAList(params.fragment);
108 description: interpolate(gettext('Make %s fragment(s) into list'), [countItems(getBoundriesForAList(params.fragment))]),
118 actions: [toggleListAction('Bullet'), toggleListAction('Enum')]