Skip to content

Instantly share code, notes, and snippets.

@serkanince
Created October 13, 2016 07:41
Show Gist options
  • Save serkanince/3923e84f4983a872e45511c05b110afe to your computer and use it in GitHub Desktop.
Save serkanince/3923e84f4983a872e45511c05b110afe to your computer and use it in GitHub Desktop.
tincymce install & image plugin
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Sample05_TincymceSample.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
public ActionResult ImageFileBrowser()
{
return View();
}
public ActionResult SaveImageFile()
{
//gelen image bilgisi kayıt yapılacak ve kayıt yapılan yerin url bilgisi geriye döndürülecek.
//boş bırakıyorum çünkü bir çok farklı yöntem mevcut.ben örnek bir url döndürdüm.
return new JsonResult()
{
Data = new { IsSave = true, Url = "https://www.lav.com.tr/Files/products/ADR25_AY016AF_MDM.jpg" },
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
}
}
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/assets/css/bootstrap.min.css" rel="stylesheet" />
<title></title>
</head>
<body>
<div class="panel panel-primary">
<div class="panel-heading">
</div>
<div class="panel-body">
<div class="col-md-3">
<button id="btnUpload" class="btn btn-default" type="button">
Yüklemek İçin Tıklayınız
</button>
</div>
</div>
</div>
</body>
</html>
<script src="~/assets/plugins/jquery/jquery.min.js"></script>
<script src="~/assets/plugins/dropzone/dropzone.min.js"></script>
<script type="text/javascript" language="javascript">
$("#btnUpload").dropzone({
url: "@Url.Action("SaveImageFile", "Home",new { ImageType = "2"})",
addRemoveLinks: true,
uploadMultiple: false,
acceptedFiles: '.jpg, .jpeg, .png',
maxFilesize: 100,
maxFiles: 3,
parallelUploads: 1,
addedfile: function (file) {
},
init: function () {
this.on("maxfilesexceeded", function (file) {
alert('Tek seferde en fazla 3 dosya yükleyebilirsiniz');
});
this.on("processing", function (file) {
$('#btnUpload').prop('disabled', true);
});
},
error: function (file) {
alert('Yükleme işlemi başarısız');
},
success: function (file) {
var response = JSON.parse(file.xhr.response);
if (response.IsSave) {
$('#btnUpload').prop('disabled', false);
var item_url = response.Url;
var args = top.tinymce.activeEditor.windowManager.getParams();
win = (args.window);
input = (args.input);
win.document.getElementById(input).value = item_url;
top.tinymce.activeEditor.windowManager.close();
}
else {
alert('İşlem Başarısız');
}
}
});
</script>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
<div class="form-group">
<textarea id="mytextarea"></textarea>
</div>
</div>
<script src="~/assets/plugins/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
//Editör initialize için gerekli config kodları
tinymce.init({
selector: '#mytextarea',
height: '350',
plugins: [
'advlist autolink lists link image charmap preview anchor',
'visualblocks fullscreen',
'media table contextmenu paste'
],
automatic_uploads: false,
file_browser_callback_types: 'image',
file_browser_callback: function (field_name, url, type, win) {
var filebrowser = "/Home/ImageFileBrowser";
filebrowser += (filebrowser.indexOf("?") < 0) ? "?type=" + type : "&type=" + type;
tinymce.activeEditor.windowManager.open({
title: "Dosya Seç",
width: 520,
height: 400,
url: filebrowser
}, {
window: win,
input: field_name
});
},
language_url: '../assets/plugins/tinymce/js/langs/tr_TR.js',
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment