-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_load.html
285 lines (256 loc) · 9.64 KB
/
index_load.html
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Comic Text Location</title>
<style>
@font-face {
font-family: NaraePro;
src: url("font/Core_Narae_Pro.otf") format("opentype");
}
@font-face {
font-family: NaraePro;
font-weight: bold;
src: url("font/Core_Narae_Pro.otf") format("opentype");
}
#canvas {
width:2000px;
height:2000px;
margin: 5em;
padding: 6px;
}
.rectangle {
position: absolute;
text-align: center;
white-space:nowrap;
}
.rectangle > * {white-space:normal;}
.rectangle:before,
.rectangle >* {display:inline-block; vertical-align:middle;}
.rectangle:before {content:""; height:100%;}
#userActions{
display: table-cell;
height: 150px;
width: 200px;
vertical-align: middle;
text-align: center;
color: #37474F;
background-color: #FFFFFF;
border: solid 2px #333333;
border-radius: 10px;
}
#userActions input{
width: 150px;
margin: auto;
}
#imgPrime{ display: none; }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/jquery.textfill.js"></script>
</head>
<body>
<div id="userActions">
<p>Drag & Drop Image</p>
<input type="file" id="fileUpload" />
</div>
<div id="canvas">
<img id="imgPrime" src="" alt="uploaded image placeholder" />
</div>
<script>
/**
* Fire an event handler to the specified node. Event handlers can detect that the event was fired programatically
* by testing for a 'synthetic=true' property on the event object
* @param {HTMLNode} node The node to fire the event handler on.
* @param {String} eventName The name of the event without the "on" (e.g., "focus")
*/
function fireEvent(node, eventName) {
// Make sure we use the ownerDocument from the provided node to avoid cross-window problems
var doc;
if (node.ownerDocument) {
doc = node.ownerDocument;
} else if (node.nodeType == 9){
// the node may be the document itself, nodeType 9 = DOCUMENT_NODE
doc = node;
} else {
throw new Error("Invalid node passed to fireEvent: " + node.id);
}
if (node.dispatchEvent) {
// Gecko-style approach (now the standard) takes more work
var eventClass = "";
// Different events have different event classes.
// If this switch statement can't map an eventName to an eventClass,
// the event firing is going to fail.
switch (eventName) {
case "click": // Dispatching of 'click' appears to not work correctly in Safari. Use 'mousedown' or 'mouseup' instead.
case "mousedown":
case "mouseup":
eventClass = "MouseEvents";
break;
case "focus":
case "change":
case "blur":
case "select":
eventClass = "HTMLEvents";
break;
default:
throw "fireEvent: Couldn't find an event class for event '" + eventName + "'.";
break;
}
var event = doc.createEvent(eventClass);
event.initEvent(eventName, true, true); // All events created as bubbling and cancelable.
event.synthetic = true; // allow detection of synthetic events
// The second parameter says go ahead with the default action
node.dispatchEvent(event, true);
} else if (node.fireEvent) {
// IE-old school style, you can drop this if you don't need to support IE8 and lower
var event = doc.createEventObject();
event.synthetic = true; // allow detection of synthetic events
node.fireEvent("on" + eventName, event);
}
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)===' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
document.cookie = name+'=; Max-Age=-99999999;';
}
</script>
<script>
var bubbleNum = 1;
'use strict';
/**
// ||||||||||||||||||||||||||||||| \\
// Global Object $: Generic controls
// ||||||||||||||||||||||||||||||| \\
**/
(function(){
// http://stackoverflow.com/questions/4083351/what-does-jquery-fn-mean
var $ = function( elem ){
if (!(this instanceof $)){
return new $(elem);
}
this.el = document.getElementById( elem );
};
window.$ = $;
$.prototype = {
onChange : function( callback ){
this.el.addEventListener('change', callback );
return this;
}
};
})();
/**
// ||||||||||||||||||||||||||||||| \\
// Drag and Drop code for Upload
// ||||||||||||||||||||||||||||||| \\
**/
var dragdrop = {
init : function( elem ){
elem.setAttribute('ondrop', 'dragdrop.drop(event)');
elem.setAttribute('ondragover', 'dragdrop.drag(event)' );
elem.setAttribute('onclick', 'dragdrop.click(event)')
},
drop : function(e){
e.preventDefault();
var file = e.dataTransfer.files[0];
runUpload( file );
},
drag : function(e){
e.preventDefault();
},
click : function (e) {
e.preventDefault();
var up = document.getElementById("fileUpload");
fireEvent(up, "click");
//fireEvent(up, "mouseup");
console.log("AAHH");
}
};
function setImage(base64) {
var imgPrime = document.getElementById("imgPrime");
imgPrime.src = base64;
imgPrime.style.display = 'inline';
document.getElementById("userActions").style.display = 'none';
imgPrime.onload = function () {
var element = null;
while (getCookie("left"+bubbleNum) != null) {
element = document.createElement('div');
element.id = "bubble"+bubbleNum;
element.style.fontFamily = "NaraePro,fantasy";
//element.style.overflow = "hidden";
element.innerHTML = "<span>" + getCookie("bubble"+bubbleNum).replace("-#", "<br>") + "</span>";
element.className = 'rectangle';
document.getElementById('canvas').appendChild(element);
var imgPosit = imgPrime.getBoundingClientRect();
var offsetLeft = imgPosit.left + parseInt(getCookie("left"+bubbleNum), 10) + window.pageXOffset;
var offsetTop = imgPosit.top + parseInt(getCookie("top"+bubbleNum), 10) + window.pageYOffset;
element.style.width = getCookie("width"+bubbleNum) + 'px';
element.style.height = getCookie("height"+bubbleNum) + 'px';
element.style.top = offsetTop + 'px';
element.style.left = offsetLeft + 'px';
(function($) {
$("#bubble"+bubbleNum).textfill({
maxFontPixels: 40,
minFontPixels: 4
});
})(jQuery);
element = null;
bubbleNum++;
}
};
}
/**
// ||||||||||||||||||||||||||||||| \\
// Code to capture a file (image)
// and upload it to the browser
// ||||||||||||||||||||||||||||||| \\
**/
function runUpload( file ) {
// http://stackoverflow.com/questions/12570834/how-to-preview-image-get-file-size-image-height-and-width-before-upload
if( file.type === 'image/png' ||
file.type === 'image/jpg' ||
file.type === 'image/jpeg' ||
file.type === 'image/gif' ||
file.type === 'image/bmp' ){
var reader = new FileReader();
reader.readAsDataURL( file );
reader.onload = function( _file ){
setImage(_file.target.result);
} // END reader.onload()
} // END test if file.type === image
}
/**
// ||||||||||||||||||||||||||||||| \\
// window.onload fun
// ||||||||||||||||||||||||||||||| \\
**/
window.onload = function(){
if( window.FileReader ){
// Connect the DIV surrounding the file upload to HTML5 drag and drop calls
dragdrop.init( $('userActions').el );
// Bind the input[type="file"] to the function runUpload()
$('fileUpload').onChange(function(){ runUpload( this.files[0] ); });
}else{
// Report error message if FileReader is unavilable
var p = document.createElement( 'p' ),
msg = document.createTextNode( 'Sorry, your browser does not support FileReader.' );
p.className = 'error';
p.appendChild( msg );
$('userActions').el.innerHTML = '';
$('userActions').el.appendChild( p );
}
var obj = localStorage.getItem("img");
if (obj != null) {
setImage(obj);
}
};
</script>
</body>
</html>