Browse Source

General updates by removing dependencies from jquery

no-jquery
Artur Arseniev 9 years ago
parent
commit
d73fee6277
  1. 2
      src/canvas/view/CanvasView.js
  2. 188
      src/commands/view/CommandAbstract.js
  3. 4
      src/dom_components/view/ComponentView.js
  4. 15
      src/domain_abstract/ui/Input.js
  5. 13
      src/domain_abstract/ui/InputNumber.js
  6. 9
      src/editor/model/Editor.js
  7. 2
      src/editor/view/EditorView.js
  8. 18
      src/style_manager/view/PropertiesView.js
  9. 1
      src/style_manager/view/PropertyCompositeView.js
  10. 2
      src/style_manager/view/PropertySelectView.js
  11. 1
      src/style_manager/view/PropertyStackView.js
  12. 2
      src/style_manager/view/PropertyView.js
  13. 3
      test/helper.js
  14. 6
      webpack.config.js

2
src/canvas/view/CanvasView.js

@ -1,5 +1,5 @@
const Backbone = require('backbone');
const FrameView = require('./FrameView'); const FrameView = require('./FrameView');
const $ = Backbone.$;
module.exports = Backbone.View.extend({ module.exports = Backbone.View.extend({

188
src/commands/view/CommandAbstract.js

@ -1,78 +1,78 @@
var Backbone = require('backbone'); const $ = Backbone.$
module.exports = Backbone.View.extend({ module.exports = Backbone.View.extend({
/** /**
* Initialize method that can't be removed * Initialize method that can't be removed
* @param {Object} o Options * @param {Object} o Options
* @private * @private
* */ * */
initialize(o) { initialize(o) {
this.config = o || {}; this.config = o || {};
this.editorModel = this.em = this.config.em || {}; this.editorModel = this.em = this.config.em || {};
this.pfx = this.config.stylePrefix; this.pfx = this.config.stylePrefix;
this.ppfx = this.config.pStylePrefix; this.ppfx = this.config.pStylePrefix;
this.hoverClass = this.pfx + 'hover'; this.hoverClass = this.pfx + 'hover';
this.badgeClass = this.pfx + 'badge'; this.badgeClass = this.pfx + 'badge';
this.plhClass = this.pfx + 'placeholder'; this.plhClass = this.pfx + 'placeholder';
this.freezClass = this.ppfx + 'freezed'; this.freezClass = this.ppfx + 'freezed';
this.canvas = this.em.get && this.em.get('Canvas'); this.canvas = this.em.get && this.em.get('Canvas');
if(this.em.get) if(this.em.get)
this.setElement(this.getCanvas()); this.setElement(this.getCanvas());
if(this.canvas){ if(this.canvas){
this.$canvas = this.$el; this.$canvas = this.$el;
this.$wrapper = $(this.getCanvasWrapper()); this.$wrapper = $(this.getCanvasWrapper());
this.frameEl = this.canvas.getFrameEl(); this.frameEl = this.canvas.getFrameEl();
this.canvasTool = this.getCanvasTools(); this.canvasTool = this.getCanvasTools();
this.bodyEl = this.getCanvasBody(); this.bodyEl = this.getCanvasBody();
} }
this.init(this.config); this.init(this.config);
}, },
/** /**
* On frame scroll callback * On frame scroll callback
* @param {[type]} e [description] * @param {[type]} e [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
onFrameScroll(e) {}, onFrameScroll(e) {},
/** /**
* Returns canval element * Returns canval element
* @return {HTMLElement} * @return {HTMLElement}
*/ */
getCanvas() { getCanvas() {
return this.canvas.getElement(); return this.canvas.getElement();
}, },
/** /**
* Get canvas body element * Get canvas body element
* @return {HTMLElement} * @return {HTMLElement}
*/ */
getCanvasBody() { getCanvasBody() {
return this.canvas.getBody(); return this.canvas.getBody();
}, },
/** /**
* Get canvas wrapper element * Get canvas wrapper element
* @return {HTMLElement} * @return {HTMLElement}
*/ */
getCanvasWrapper() { getCanvasWrapper() {
return this.canvas.getWrapperEl(); return this.canvas.getWrapperEl();
}, },
/** /**
* Get canvas wrapper element * Get canvas wrapper element
* @return {HTMLElement} * @return {HTMLElement}
*/ */
getCanvasTools() { getCanvasTools() {
return this.canvas.getToolsEl(); return this.canvas.getToolsEl();
}, },
/** /**
* Get the offset of the element * Get the offset of the element
* @param {HTMLElement} el * @param {HTMLElement} el
* @return {Object} * @return {Object}
@ -85,27 +85,27 @@ module.exports = Backbone.View.extend({
}; };
}, },
/** /**
* Callback triggered after initialize * Callback triggered after initialize
* @param {Object} o Options * @param {Object} o Options
* @private * @private
* */ * */
init(o) {}, init(o) {},
/** /**
* Method that run command * Method that run command
* @param {Object} em Editor model * @param {Object} em Editor model
* @param {Object} sender Button sender * @param {Object} sender Button sender
* @private * @private
* */ * */
run(em, sender) {}, run(em, sender) {},
/** /**
* Method that stop command * Method that stop command
* @param {Object} em Editor model * @param {Object} em Editor model
* @param {Object} sender Button sender * @param {Object} sender Button sender
* @private * @private
* */ * */
stop(em, sender) {}, stop(em, sender) {},
}); });

4
src/dom_components/view/ComponentView.js

@ -1,5 +1,5 @@
var Backbone = require('backbone'); const ComponentsView = require('./ComponentsView');
var ComponentsView = require('./ComponentsView'); const $ = Backbone.$;
module.exports = Backbone.View.extend({ module.exports = Backbone.View.extend({

15
src/domain_abstract/ui/Input.js

@ -1,4 +1,4 @@
var Backbone = require('backbone'); const $ = Backbone.$;
module.exports = Backbone.View.extend({ module.exports = Backbone.View.extend({
@ -6,8 +6,6 @@ module.exports = Backbone.View.extend({
'change': 'handleChange', 'change': 'handleChange',
}, },
template: _.template(`<span class='<%= holderClass %>'></span>`),
initialize(opts) { initialize(opts) {
var opt = opts || {}; var opt = opts || {};
var ppfx = opt.ppfx || ''; var ppfx = opt.ppfx || '';
@ -66,13 +64,12 @@ module.exports = Backbone.View.extend({
}, },
render() { render() {
var el = this.$el; const el = this.$el;
const ppfx = this.ppfx;
const holderClass = `${ppfx}input-holder`;
el.addClass(this.inputClass); el.addClass(this.inputClass);
el.html(this.template({ el.html(`<span class="${holderClass}"></span>`);
holderClass: this.inputHolderClass, el.find(`.${holderClass}`).append(this.getInputEl());
ppfx: this.ppfx
}));
el.find('.'+ this.inputHolderClass).html(this.getInputEl());
return this; return this;
} }

13
src/domain_abstract/ui/InputNumber.js

@ -102,7 +102,7 @@ module.exports = Backbone.View.extend({
* @return {HTMLElement} * @return {HTMLElement}
*/ */
getInputEl() { getInputEl() {
if(!this.inputEl) { if (!this.inputEl) {
const cls = this.inputCls; const cls = this.inputCls;
const plh = this.model.get('defaults'); const plh = this.model.get('defaults');
this.inputEl = $(`<input type="text" class="${cls}" placeholder="${plh}">`); this.inputEl = $(`<input type="text" class="${cls}" placeholder="${plh}">`);
@ -277,11 +277,12 @@ module.exports = Backbone.View.extend({
}, },
render() { render() {
var ppfx = this.ppfx; const ppfx = this.ppfx;
this.$el.html(this.template({ppfx})); const el = this.$el;
this.$el.find('.'+ ppfx +'input-holder').html(this.getInputEl()); el.html(this.template({ppfx}));
this.$el.find('.' + ppfx + 'field-units').html(this.getUnitEl()); el.find(`.${ppfx}input-holder`).append(this.getInputEl());
this.$el.addClass(this.contClass); el.find(`.${ppfx}field-units`).html(this.getUnitEl());
el.addClass(this.contClass);
return this; return this;
} }

9
src/editor/model/Editor.js

@ -25,18 +25,17 @@ const UndoManager = require('backbone-undo');
const key = require('keymaster'); const key = require('keymaster');
let timedInterval; let timedInterval;
const cash = require('cash-dom'); require('utils/cashAdds')(Backbone.$);
require('utils/cashAdds')(cash);
let $ = $ || '';
/*
if (!$) { if (!$) {
$ = cash; $ = cash;
window.$ = $; window.$ = $;
} }
console.log(Backbone.$);
if (!Backbone.$) { if (!Backbone.$) {
Backbone.$ = $; Backbone.$ = $;
} }*/
module.exports = Backbone.Model.extend({ module.exports = Backbone.Model.extend({

2
src/editor/view/EditorView.js

@ -1,3 +1,5 @@
const $ = Backbone.$;
module.exports = Backbone.View.extend({ module.exports = Backbone.View.extend({
initialize() { initialize() {

18
src/style_manager/view/PropertiesView.js

@ -1,12 +1,11 @@
var Backbone = require('backbone'); const PropertyView = require('./PropertyView');
var PropertyView = require('./PropertyView'); const PropertyIntegerView = require('./PropertyIntegerView');
var PropertyIntegerView = require('./PropertyIntegerView'); const PropertyRadioView = require('./PropertyRadioView');
var PropertyRadioView = require('./PropertyRadioView'); const PropertySelectView = require('./PropertySelectView');
var PropertySelectView = require('./PropertySelectView'); const PropertyColorView = require('./PropertyColorView');
var PropertyColorView = require('./PropertyColorView'); const PropertyFileView = require('./PropertyFileView');
var PropertyFileView = require('./PropertyFileView'); const PropertyCompositeView = require('./PropertyCompositeView');
var PropertyCompositeView = require('./PropertyCompositeView'); const PropertyStackView = require('./PropertyStackView');
var PropertyStackView = require('./PropertyStackView');
module.exports = Backbone.View.extend({ module.exports = Backbone.View.extend({
@ -44,7 +43,6 @@ module.exports = Backbone.View.extend({
}); });
this.$el.append(fragment); this.$el.append(fragment);
this.$el.append($('<div>', {class: "clear"}));
this.$el.attr('class', this.pfx + 'properties'); this.$el.attr('class', this.pfx + 'properties');
return this; return this;
} }

1
src/style_manager/view/PropertyCompositeView.js

@ -1,4 +1,5 @@
const PropertyView = require('./PropertyView'); const PropertyView = require('./PropertyView');
const $ = Backbone.$;
module.exports = PropertyView.extend({ module.exports = PropertyView.extend({

2
src/style_manager/view/PropertySelectView.js

@ -1,3 +1,5 @@
const $ = Backbone.$;
module.exports = require('./PropertyView').extend({ module.exports = require('./PropertyView').extend({
templateInput() { templateInput() {

1
src/style_manager/view/PropertyStackView.js

@ -1,4 +1,3 @@
var Backbone = require('backbone');
var PropertyCompositeView = require('./PropertyCompositeView'); var PropertyCompositeView = require('./PropertyCompositeView');
var Layers = require('./../model/Layers'); var Layers = require('./../model/Layers');
var LayersView = require('./LayersView'); var LayersView = require('./LayersView');

2
src/style_manager/view/PropertyView.js

@ -84,7 +84,7 @@ module.exports = Backbone.View.extend({
const config = this.config; const config = this.config;
const updatedCls = `${ppfx}color-hl`; const updatedCls = `${ppfx}color-hl`;
const computedCls = `${ppfx}color-warn`; const computedCls = `${ppfx}color-warn`;
const labelEl = this.$el.find(`> .${pfx}label`); const labelEl = this.$el.children(`.${pfx}label`);
const clearStyle = this.getClearEl().style; const clearStyle = this.getClearEl().style;
labelEl.removeClass(`${updatedCls} ${computedCls}`); labelEl.removeClass(`${updatedCls} ${computedCls}`);
clearStyle.display = 'none'; clearStyle.display = 'none';

3
test/helper.js

@ -7,7 +7,6 @@ import { JSDOM } from 'jsdom';
const dom = new JSDOM('<!doctype html><html><body></body></html>'); const dom = new JSDOM('<!doctype html><html><body></body></html>');
const window = dom.window; const window = dom.window;
//const $ = jquery(window);
// Fix for the spectrum lib // Fix for the spectrum lib
var Module = require('module'); var Module = require('module');
@ -15,6 +14,7 @@ var originalRequire = Module.prototype.require;
Module.prototype.require = function(name) { Module.prototype.require = function(name) {
if (name == 'jquery') { if (name == 'jquery') {
console.log('REQUIRE jquery', Backbone.$);
return Backbone.$; return Backbone.$;
} }
return originalRequire.apply(this, arguments); return originalRequire.apply(this, arguments);
@ -50,6 +50,7 @@ grapesjs.init({container: 'body',autorender: 0, storageManager: {
autoload: 0, autoload: 0,
type:'none' type:'none'
},}); },});
window.$ = Backbone.$; window.$ = Backbone.$;
Object.keys(window).forEach((key) => { Object.keys(window).forEach((key) => {

6
webpack.config.js

@ -30,9 +30,6 @@ module.exports = {
plugins: plugins, plugins: plugins,
module: { module: {
loaders: [{ loaders: [{
test: /backbone\.js$/,
use: ['imports-loader?define=>false']
},{
test: /grapesjs\/index\.js$/, test: /grapesjs\/index\.js$/,
loader: 'string-replace-loader', loader: 'string-replace-loader',
query: { query: {
@ -48,5 +45,8 @@ module.exports = {
}, },
resolve: { resolve: {
modules: ['src', 'node_modules'], modules: ['src', 'node_modules'],
alias: {
jquery: 'cash-dom'
}
}, },
} }

Loading…
Cancel
Save