I use ember.js
v1.13.0
and have template helper
import Ember from 'ember';
export default Ember.Handlebars.makeBoundHelper(function(data, recordType, options) {
data = data || '';
if (recordType == 12) {
//not escaped
escaped = data + "<a href=\"#\">it's some extra button</a>";
} else {
var escaped = Handlebars.Utils.escapeExpression(data);
var matchURLs = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi;
var replaceURL = function (str) {
return "<a target=\"_blank\" href='" + (str.indexOf("://") === -1 ? "http://" : "") + str + "'>" + str + "</a>";
}
escaped = escaped.replace(matchURLs, replaceURL);
}
//nl2br
escaped = escaped.replace(/\n/g, "<br />");
return new Handlebars.SafeString(escaped);
});
My aim if helper gets record with specified type it will add button to end of record text. But when button is clicked it needs to call some action in my controller.
I have idea to call template's action
helper from my helper when it will add the button.
Aucun commentaire:
Enregistrer un commentaire