1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
<!doctype>
<html>
<head>
<style>
#modal_img{
display:none;
position:fixed;
top:0; right:0; bottom:0; left:0;
background-color: black;
opacity: 0.5;
z-index: 1000;
}
#modal_img:target{
display: block;
}
#modal_img a{
font-weight: bold;
padding: 10px 25px;
background-color: white;
position: absolute;
top: 50%;
left: 50px;
}
#file
{
position: absolute;
top: 40%;
left: 50px;
}
#dropfile{
width: 300px;
height: 50px;
border: 3px dashed #BBBBBB;
line-height:50px;
}
</style>
<title>Wysiwig</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#display').on('click', function() {
$('#menu').toggle();
$('#wysi').attr('contenteditable', $('#menu').is(':visible') ? 'true' : 'false');
$('#image').on('click', function() {
});
//console.log($('#wysi').prop('contenteditable'));
});
});
$('#display').on('click', function() {
$('#menu').toggle();
$('#wysi').attr('contenteditable', $('#menu').is(':visible') ? 'true' : 'false');
$('#image').on('click', function() {
});
//console.log($('#wysi').prop('contenteditable'));
});
$(document).on('drop', '#dropfile', function(e) {
if(e.originalEvent.dataTransfer){
if(e.originalEvent.dataTransfer.files.length) {
// Stop the propagation of the event
e.preventDefault();
e.stopPropagation();
$(this).css('border', '3px dashed green');
// Main function to upload
upload(e.originalEvent.dataTransfer.files);
}
}
else {
$(this).css('border', '3px dashed #BBBBBB');
}
return false;
});
$(document).on('dragenter', '#dropfile', function() {
$(this).css('border', '3px dashed red');
return false;
});
$(document).on('dragover', '#dropfile', function(e){
e.preventDefault();
e.stopPropagation();
$(this).css('border', '3px dashed red');
return false;
});
$(document).on('dragleave', '#dropfile', function(e) {
e.preventDefault();
e.stopPropagation();
$(this).css('border', '3px dashed #BBBBBB');
return false;
});
function upload(files) {
var f = files[0] ;
// Only process image files.
if (!f.type.match('image/jpeg')) {
alert('The file must be a jpeg image') ;
return false ;
}
var reader = new FileReader();
// When the image is loaded,
// run handleReaderLoad function
reader.onload = handleReaderLoad;
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
function handleReaderLoad(evt) {
var pic = {};
pic.file = evt.target.result.split(',')[1];
var str = jQuery.param(pic);
$.ajax({
type: 'POST',
url: 'url_to_php_script.php',
data: str,
success: function(data){
console.log(data)}
});
}
</script>
</head>
<body>
<div id="menu">
<div id="modal_img">
<div id="dropfile">glisser une image</div>
<a id="no_modal" href="#">fermer</a>
</div>
<a href="#modal_img">image </a>
<button id="b">en gras</button>
</div>
<div id="wysi" >
editer moi
</div>
<button id="display">
cacher
</button>
</body>
</html> |