Browse Source

Add toggle images command

pull/36/head
Artur Arseniev 9 years ago
parent
commit
64de3a77eb
  1. 42
      src/demo.js

42
src/demo.js

@ -44,6 +44,41 @@ require(['config/require-config'], function() {
sender.set('active',false);
window.open('https://github.com/artf/grapesjs','_blank');
}
},{
id: 'sw-images',
run: function(editor, sender){
var srcPlh = '##';
var components = editor.getComponents();
var searchImage = function(components) {
components.each(function(comp){
if(comp.get('type') == 'image'){
if(comp.get('src') != srcPlh){
comp.set('src_bkp', comp.get('src'));
comp.set('src', srcPlh);
console.log('Stored', comp.get('src_bkp'));
}
}
searchImage(comp.get('components'));
});
};
searchImage(components);
},
stop: function() {
var srcPlh = '##';
var components = editor.getComponents();
var searchImage = function(components) {
components.each(function(comp){
if(comp.get('type') == 'image'){
if(comp.get('src') == srcPlh){
comp.set('src', comp.get('src_bkp'));
console.log('Restored', comp.get('src'));
}
}
searchImage(comp.get('components'));
});
};
searchImage(components);
}
},{
id: 'undo',
run: function(editor, sender){
@ -326,6 +361,13 @@ require(['config/require-config'], function() {
);
editor.Panels.addButton('options', [{
id: 'sw-images',
className: 'fa fa-image',
command: 'sw-images',
attributes: { title: 'View on Github' }
}]);
window.editor = editor;
});

Loading…
Cancel
Save