[html] </div> <script type="text/javascript" class="jsScript"> $(function () { $("#rteSample").ejRTE({ toolsList: ["customTools"], width: "100%", minWidth: "150px", tools: { customTools: [{ name: "InsertImage", tooltip: "InsertImage ", css: "InsertImage", text: "InsertImage" }] } |
[html] <script type="text/javascript" class="jsScript"> $("#InsertImagee").ejUploadbox({ saveUrl: "saveFiles.ashx", removeUrl: "removeFiles.ashx", complete: "success", dialogAction: { content: "body" } |
[html] <script type="text/javascript" class="jsScript"> //args contains the location of the image. function success(args) { var image = ej.buildTag("img#image"); image.attr("src", args.responseText); rteObj.executeCommand("inserthtml", image[0].outerHTML); uploadObj = $("#InsertImagee").ejUploadbox("instance"); uploadObj._dialogclose(); } |
$("#InsertImagee").ejUploadbox({
saveUrl: "saveFiles.ashx",
complete: "success", dialogAction: { content: "body" }
}); |
customTools: [Then add custom element in html:
{ name: "imageUpload", tooltip: "Image upload" }
]
create: function (args) {
//add image upload button
var btn = $("#imageUpload");
$("#imageUpload").find("div").remove();
var btntarget = $("#inputFileToLoadFake");
btn.append(btntarget);
}
<div id="inputFileToLoadFake" class="fileContainer e-rte-toolbar-icon image e-image">Add css styles to make icon look like syncfusion default image icon:
<input id="inputFileToLoad" type="file" />
</div>
.fileContainer {At the end, I add method in javascript bind to change event of file uploader. Method takes uploaded image,
overflow: hidden;
position: relative;
}
.fileContainer [type=file] {
cursor: inherit;
display: block;
font-size: 999px;
filter: alpha(opacity=0);
min-height: 100%;
min-width: 100%;
opacity: 0;
position: absolute;
right: 0;
text-align: right;
top: 0;
}
encodeImageFileAsURL = function() {fileUploader = document.getElementById('inputFileToLoad');
var filesSelected = document.getElementById("inputFileToLoad").files;
if (filesSelected.length > 0) {
var fileToLoad = filesSelected[0];
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
var srcData = fileLoadedEvent.target.result; // <--- data: base64
//add base64 image on the beggining of the template
var rteObj = $("#rteTemplateEditorId").data("ejRTE");
var htmlContent = rteObj.getHtml();
var newImage = "<img src='" + srcData + "' >"
rteObj.setHtml(newImage + htmlContent);
}
fileReader.readAsDataURL(fileToLoad);
}
}