-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblanktemplate.html
More file actions
164 lines (157 loc) · 5.51 KB
/
blanktemplate.html
File metadata and controls
164 lines (157 loc) · 5.51 KB
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
<html>
<head>
<title>Blank Template</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="stylesheet" href="bootstrap.min.css" type="text/css" />
<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//////////////////////////////////////////////////////////////////////
// Variables
//////////////////////////////////////////////////////////////////////
var mode = "none";
var i = 0;
var $dragged_object = null;
var mouseToObjectOffset = {left: 0, top: 0};
var canvas_offset = $("#painting-canvas").offset();
// Painting variables
var isDrawing = false;
var canvas = document.getElementById('painting-canvas');
canvas.width = $("#workspace").width();
canvas.height = $("#workspace").height();
var context = canvas.getContext('2d');
//////////////////////////////////////////////////////////////////////
// Icon listeners
//////////////////////////////////////////////////////////////////////
$("#text-icon").click(function() {
mode = "text";
});
$("#button-icon").click(function() {
mode = "button";
});
$("#paint-icon").click(function() {
if (mode == "paint") {
mode = "none";
}
else {
mode = "paint";
}
});
$("#camera-icon").click(function() {
mode = "camera";
});
$("#link-icon").click(function() {
mode = "link";
});
$("#calendar-icon").click(function() {
mode = "calendar";
});
$("#map-icon").click(function() {
mode = "map";
});
$("#contacts-icon").click(function() {
mode = "contacts";
});
//////////////////////////////////////////////////////////////////////
// Workspace listener
//////////////////////////////////////////////////////////////////////
$("#workspace").click(function(e) {
switch(mode) {
case "none":
break;
case "text":
var $new_textarea = $("<div class='msgpro-object user-textarea'><textarea class='form-control' rows=3></textarea></div>");
$("#workspace").append($new_textarea);
$new_textarea.offset({left: e.pageX, top: e.pageY});
i++;
mode = "none";
break;
case "button":
var $new_button = $("<button type='button' class='btn btn-default msgpro-object user-button'><input type='text'></input></button>");
$("#workspace").append($new_button);
$new_button.offset({left: e.pageX, top: e.pageY});
i++;
mode = "none";
break;
case "paint":
break;
case "camera":
break;
case "link":
break;
case "calendar":
break;
case "map":
break;
case "contacts":
break;
}
});
//////////////////////////////////////////////////////////////////////
// Painting listeners
//////////////////////////////////////////////////////////////////////
$("#workspace").mousedown(function(e) {
if (mode == "paint") {
isDrawing = true;
context.beginPath();
context.moveTo(e.pageX - canvas_offset.left, e.pageY - canvas_offset.top);
}
});
$("#workspace").mouseup(function() {
if (mode == "paint") {
isDrawing = false;
}
});
$("#workspace").mousemove(function(e) {
if (mode == "paint" && isDrawing) {
context.lineTo(e.pageX - canvas_offset.left, e.pageY - canvas_offset.top);
context.stroke();
}
});
//////////////////////////////////////////////////////////////////////
// User-added elements listeners
//////////////////////////////////////////////////////////////////////
$("#workspace").bind("mousedown", ".msgpro-object", function(e) {
if ($(e.target).is("input") || $(e.target).is("textarea")) {
$dragged_object = $(e.target).parent();
console.log($dragged_object);
}
else {
$dragged_object = $(e.target);
}
var offset = $dragged_object.offset();
mouseToObjectOffset = {left: e.pageX - offset.left, top: e.pageY - offset.top};
});
$("#workspace").bind("mouseup", ".msgpro-object", function() {
$dragged_object = null;
});
$("#workspace").bind("mousemove", ".msgpro-object", function(e) {
if (mode != "paint" && $dragged_object) {
$dragged_object.offset({left: e.pageX - mouseToObjectOffset.left, top: e.pageY - mouseToObjectOffset.top});
}
});
});
</script>
</head>
<body>
<div class="msgpro-header">
<h1>My Masterpiece</h1>
<a href="send.html"><img id="send-icon" src="Media/send-icon.png" height="40px" width="40px" /></a>
</div>
<div id="workspace">
<canvas id="painting-canvas"></canvas>
</div>
<div id="toolbox-container">
<div id="toolbox">
<div class="icon" id="text-icon"><img src="Media/text-icon.png" height="50px" width="50px"/></div>
<div class="icon" id="button-icon"><img src="Media/button-icon.png" height="50px" width="50px"/></div>
<div class="icon" id="paint-icon"><img src="Media/paint-icon.png" height="50px" width="50px"/></div>
<div class="icon" id="camera-icon"><img src="Media/camera-icon.png" height="50px" width="50px"/></div>
<div class="icon" id="link-icon"><img src="Media/link-icon.png" height="50px" width="50px"/></div>
<div class="icon" id="calendar-icon"><img src="Media/calendar-icon.png" height="50px" width="50px"/></div>
<div class="icon" id="map-icon"><img src="Media/map-icon.png" height="50px" width="50px"/></div>
<div class="icon" id="contacts-icon"><img src="Media/contacts-icon.jpg" height="50px" width="50px"/></div>
</div>
</div>
</body>
</html>