Skip to content

Commit

Permalink
fix incorrect parameter for generateHtml in listener
Browse files Browse the repository at this point in the history
  • Loading branch information
noogen committed Mar 5, 2019
1 parent 8dcaf71 commit b47a4c1
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 52 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/index.js": "/index.js?id=010182b05b82e2854a04",
"/index.js.map": "/index.js.map?id=5ac4bf61cc671c007486"
"/index.js": "/index.js?id=6fc1bec3c19ea926ecbd",
"/index.js.map": "/index.js.map?id=3f3ccc9e250c1f7d93f4"
}
50 changes: 27 additions & 23 deletions example/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grapesjs-components-farmer",
"description": "grapesjs plugin to build components for different css framework",
"version": "0.2.1",
"version": "0.2.2",
"author": "friends@niiknow.org",
"license": "MIT",
"main": "dist/index.js",
Expand Down
50 changes: 27 additions & 23 deletions src/traits.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default (editor, opts = {}) => {
// force regenerate of HTML
toHTML() {
let html = ''
if (!this.view.el) {
if (this.view && !this.view.el) {
const el = document.createElement(this.attributes.tagName)

html = this.generateHtml(el)[0].outerHTML
Expand Down Expand Up @@ -173,6 +173,10 @@ export default (editor, opts = {}) => {

return false
},
// function to use with listener
genHtml() {
this.generateHtml()
},
generateHtml(el = this.view.el, k = this.attributes.tagName) {
const model = this
const $el = $(el || model.view.el)
Expand All @@ -197,8 +201,8 @@ export default (editor, opts = {}) => {
// override default view to generate html
const myDefaultView = defaultView.extend({
onRender() {
if (this.model.generateHtml) {
this.model.generateHtml()
if (this.model.genHtml) {
this.model.genHtml()
}

return this
Expand All @@ -222,9 +226,9 @@ export default (editor, opts = {}) => {
const that = this
that.myInitDefaults()

that.listenTo(that, 'change:label_attr', that.generateHtml)
that.listenTo(that, 'change:name_attr', that.generateHtml)
that.listenTo(that, 'change:placeholder_attr', that.generateHtml)
that.listenTo(that, 'change:label_attr', that.genHtml)
that.listenTo(that, 'change:name_attr', that.genHtml)
that.listenTo(that, 'change:placeholder_attr', that.genHtml)
}
}),
view: myDefaultView
Expand Down Expand Up @@ -262,10 +266,10 @@ export default (editor, opts = {}) => {
const that = this
that.myInitDefaults()

that.listenTo(that, 'change:label_attr', that.generateHtml)
that.listenTo(that, 'change:name_attr', that.generateHtml)
that.listenTo(that, 'change:multiple_attr', that.generateHtml)
that.listenTo(that, 'change:option_attr', that.generateHtml)
that.listenTo(that, 'change:label_attr', that.genHtml)
that.listenTo(that, 'change:name_attr', that.genHtml)
that.listenTo(that, 'change:multiple_attr', that.genHtml)
that.listenTo(that, 'change:option_attr', that.genHtml)
}
}),
view: myDefaultView
Expand Down Expand Up @@ -312,11 +316,11 @@ export default (editor, opts = {}) => {
const that = this
that.myInitDefaults()

that.listenTo(that, 'change:label_attr', that.generateHtml)
that.listenTo(that, 'change:name_attr', that.generateHtml)
that.listenTo(that, 'change:placeholder_attr', that.generateHtml)
that.listenTo(that, 'change:cols_attr', that.generateHtml)
that.listenTo(that, 'change:rows_attr', that.generateHtml)
that.listenTo(that, 'change:label_attr', that.genHtml)
that.listenTo(that, 'change:name_attr', that.genHtml)
that.listenTo(that, 'change:placeholder_attr', that.genHtml)
that.listenTo(that, 'change:cols_attr', that.genHtml)
that.listenTo(that, 'change:rows_attr', that.genHtml)
}
}),
view: myDefaultView
Expand Down Expand Up @@ -357,10 +361,10 @@ export default (editor, opts = {}) => {
const that = this
that.myInitDefaults()

that.listenTo(that, 'change:label_attr', that.generateHtml)
that.listenTo(that, 'change:name_attr', that.generateHtml)
that.listenTo(that, 'change:placeholder_attr', that.generateHtml)
that.listenTo(that, 'change:accept_attr', that.generateHtml)
that.listenTo(that, 'change:label_attr', that.genHtml)
that.listenTo(that, 'change:name_attr', that.genHtml)
that.listenTo(that, 'change:placeholder_attr', that.genHtml)
that.listenTo(that, 'change:accept_attr', that.genHtml)
}
}),
view: myDefaultView
Expand Down Expand Up @@ -389,8 +393,8 @@ export default (editor, opts = {}) => {
const that = this
that.myInitDefaults()

that.listenTo(that, 'change:label_attr', that.generateHtml)
that.listenTo(that, 'change:name_attr', that.generateHtml)
that.listenTo(that, 'change:label_attr', that.genHtml)
that.listenTo(that, 'change:name_attr', that.genHtml)
}
}),
view: myDefaultView
Expand All @@ -417,7 +421,7 @@ export default (editor, opts = {}) => {
const that = this
that.myInitDefaults()

that.listenTo(that, 'change:name_attr', that.generateHtml)
that.listenTo(that, 'change:name_attr', that.genHtml)
}
}),
view: myDefaultView
Expand Down Expand Up @@ -446,7 +450,7 @@ export default (editor, opts = {}) => {
const that = this
that.myInitDefaults()

that.listenTo(that, 'change:label_attr', that.generateHtml)
that.listenTo(that, 'change:label_attr', that.genHtml)
}
}),
view: myDefaultView
Expand Down

0 comments on commit b47a4c1

Please sign in to comment.