Created
January 9, 2014 11:07
-
-
Save ringe/8332578 to your computer and use it in GitHub Desktop.
Combine Trumbowyg with RestInPlace. I had some difficulties extending RestInPlaceEditor.forms with the "trumbowyg" type.
Mainly because the callbacks are not documented in Trumbowyg, I believe. I was not able to use the RestInPlace method _this.update(); but had to copy the code from restinplace.js and implement a custom ajax handling.
This leav…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id=page_1 data-url=/pages/1><> | |
<h1 class="rest-in-place" data-attribute="title">Nord-Norges stØrste næringsmagasin</h1> | |
<div id=pagebody_1 class="pagebody" data-attribute="body" data-formtype="trumbowyg" tabindex=1> | |
<h1>mama</h1> | |
<p>written text</p> | |
</div> | |
<script> | |
$("#pagebody_1").restInPlace(); | |
</script> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define the Trumbowyg form type for RestInPlace | |
var trumbowyg = { | |
"trumbowyg" : { | |
activateForm: function() { | |
var _this = this; | |
var domid = this.$element[0].id; | |
this.$element.trumbowyg({ | |
autogrow: true | |
}); | |
this.$element[0].focus(); | |
this.$element.keyup(function(e){ | |
if (e.keyCode === 27) { | |
$("#"+domid).trumbowyg("destroy"); | |
return _this.abort(); | |
} | |
}); | |
return this.$element.focusout(function() { | |
var updateRequest, data; | |
data = _this.getEncodedTokenAuthenticationParams(); | |
data["_method"] = 'put'; | |
data["" + _this.objectName + "[" + _this.attributeName + "]"] = _this.$element[0].innerHTML; | |
_this.$element.trigger('update.rest-in-place', data); | |
updateRequest = _this.ajax({ | |
type: "post", | |
data: data | |
}); | |
updateRequest.done(function(data) { | |
if (data) { | |
return _this.loadSuccessCallback(data); | |
} else { | |
return _this.loadViaGET(); | |
} | |
}); | |
updateRequest.fail(function(jqXHR, textStatus) { | |
if (jqXHR.status === 200 && textStatus === "parsererror") { | |
return _this.loadViaGET(); | |
} else { | |
_this.$element.trigger('failure.rest-in-place'); | |
return _this.abort(); | |
} | |
}); | |
_this.$element.trumbowyg("destroy"); | |
$(domid).restInPlace(); | |
// return _this.update(); // does not work | |
}); | |
}, | |
getValue: function() { | |
return null; | |
return this.$element[0].innerHTML; // does not do anything | |
} | |
} | |
}; | |
// Extend RestInPlaceEditor with Trumbowyg form type | |
$.extend(RestInPlaceEditor.forms, trumbowyg); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hm. Focus out leaves the text with the tags, which then get parsed by trumbowyg on the next edit, which is then posted back. Then it looks like this:
If I click the HTML button in Trumbowyg, the tags get sanitized.
Is this a Trumbowyg error?