Skip to content

Commit 42413fb

Browse files
committed
Fixing more apps for CSP #137
1 parent 74e608a commit 42413fb

File tree

6 files changed

+168
-172
lines changed

6 files changed

+168
-172
lines changed

server/demos/imagestudio/pages/index.html

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,8 @@
66
<link rel=icon href="favicon.ico" />
77
<intent action="http://webintents.org/view"
88
type="image/*" />
9-
<script type="text/javascript">
10-
$(function() {
11-
var loadImage = function(data) {
12-
var url = $.isArray(data) ? data[0] : data;
13-
$("#result").attr('src', url).css({ "width": "auto", "height": "auto"});
14-
$("#edit, #share, #save").removeClass("disabled")
15-
.removeAttr('disabled');
16-
};
17-
18-
if(window.intent) {
19-
laodImage(window.intent.data);
20-
}
21-
22-
$('#choose').click(function(e) {
23-
var intent = new Intent( 'http://webintents.org/pick', 'image/*');
24-
window.navigator.startActivity(intent, function(data) {
25-
loadImage(data);
26-
});
27-
});
28-
29-
$("#edit").click(function (e) {
30-
var intent = new Intent( 'http://webintents.org/edit', 'image/*', $("#result").attr("src"));
31-
window.navigator.startActivity(intent, function(data) {
32-
loadImage(data);
33-
});
34-
});
35-
36-
$('#save').click(function(e) {
37-
var intent = new Intent( 'http://webintents.org/save', 'image/*', $('#result').attr('src'));
38-
window.navigator.startActivity(intent);
39-
});
40-
41-
$('#share').click(function() {
42-
var intent = new Intent( 'http://webintents.org/share', 'image/*', $('#result').attr('src'));
43-
44-
window.navigator.startActivity(intent);
45-
});
46-
});
47-
</script>
9+
<script type="text/javascript" src="/scripts/index.js">
10+
</script>
4811
{% endblock %}
4912
{% block content %}
5013
<div id="steps">
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
$(function() {
2+
var loadImage = function(data) {
3+
var url = $.isArray(data) ? data[0] : data;
4+
$("#result").attr('src', url).css({ "width": "auto", "height": "auto"});
5+
$("#edit, #share, #save").removeClass("disabled")
6+
.removeAttr('disabled');
7+
};
8+
9+
if(window.intent) {
10+
loadImage(window.intent.data);
11+
}
12+
13+
$('#choose').click(function(e) {
14+
var intent = new Intent( 'http://webintents.org/pick', 'image/*');
15+
window.navigator.startActivity(intent, function(data) {
16+
loadImage(data);
17+
});
18+
});
19+
20+
$("#edit").click(function (e) {
21+
var intent = new Intent( 'http://webintents.org/edit', 'image/*', $("#result").attr("src"));
22+
window.navigator.startActivity(intent, function(data) {
23+
loadImage(data);
24+
});
25+
});
26+
27+
$('#save').click(function(e) {
28+
var intent = new Intent( 'http://webintents.org/save', 'image/*', $('#result').attr('src'));
29+
window.navigator.startActivity(intent);
30+
});
31+
32+
$('#share').click(function() {
33+
var intent = new Intent( 'http://webintents.org/share', 'image/*', $('#result').attr('src'));
34+
window.navigator.startActivity(intent);
35+
});
36+
});
37+

server/demos/inspirationmator/pages/index.html

Lines changed: 1 addition & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -4,123 +4,7 @@
44
{% block scripts %}
55
<link rel=icon href="favicon.ico" />
66
<script type="text/javascript" src="scripts/memegen.js"></script>
7-
<script type="text/javascript">
8-
var context;
9-
var canvas;
10-
11-
var draw = function(topline, bottomline) {
12-
var image = $("#image");
13-
var width = image.width();
14-
var height = image.height();
15-
var canvasWidth = width + 100;
16-
var canvasHeight = height + 200;
17-
canvas.width = canvasWidth;
18-
canvas.height = canvasHeight;
19-
canvas.parentElement.parentElement.style.height = canvasHeight + "px";
20-
canvas.parentElement.parentElement.style.width = canvasWidth + "px";
21-
context = canvas.getContext('2d');
22-
context.save();
23-
context.fillStyle = "rgb(0,0,0)";
24-
context.fillRect(0,0, canvas.width, canvas.height);
25-
context.save();
26-
context.strokeStyle = "rgb(255,255,255)";
27-
context.lineWidth = 2;
28-
context.strokeRect(46, 46, width + 8, height + 8);
29-
context.restore();
30-
context.drawImage(image.get()[0], 50, 50);
31-
context.save();
32-
context.font = "62px Josefin Slab";
33-
context.textAlign = "center";
34-
context.fillStyle = "white";
35-
context.strokeStyle = "white";
36-
context.lineWidth = 2;
37-
context.fillText(topline, canvasWidth * 0.5, height + 105, canvasWidth * 0.9);
38-
context.restore();
39-
context.save();
40-
context.font = "24px Josefin Slab";
41-
context.textAlign = "center";
42-
context.fillStyle = "white";
43-
context.strokeStyle = "white";
44-
context.lineWidth = 2;
45-
context.fillText(bottomline, canvasWidth * 0.5, height + 150, canvasWidth * 0.9);
46-
context.restore();
47-
48-
context.restore();
49-
};
50-
51-
function textChanged() {
52-
if (context) {
53-
topText = $('#top').val() || "";
54-
bottomText = $('#bottom').val() || "";
55-
draw(topText, bottomText);
56-
}
57-
}
58-
59-
var updateImage = function(data) {
60-
var url = $.isArray(data) ? data[0] : data;
61-
var img = $('#image');
62-
img.load(function() {
63-
var image = $('#image');
64-
canvas = $('#container canvas');
65-
if(canvas.length == 0) {
66-
canvas = document.createElement('canvas');
67-
$('#container').append(canvas);
68-
}
69-
else
70-
canvas = canvas[0];
71-
72-
draw("","");
73-
74-
if(window.intent) {
75-
$('#done').show();
76-
}
77-
else {
78-
$('#save').show();
79-
$('#share').show();
80-
}
81-
});
82-
loadImage(img, url);
83-
};
84-
85-
$(function() {
86-
if (window.intent) {
87-
$('#done').show();
88-
$('#done').click(function() {
89-
if (canvas) {
90-
window.intent.postResult(canvas.toDataURL());
91-
window.setTimeout(function() { window.close(); }, 1000);
92-
}
93-
});
94-
95-
updateImage(window.intent.data);
96-
}
97-
else {
98-
$('#container').click(function() {
99-
$('#save').hide();
100-
$('#share').hide();
101-
$('#done').hide();
102-
103-
var i = new Intent("http://webintents.org/pick", "image/*");
104-
window.navigator.startActivity(i, function(data) {
105-
updateImage(data);
106-
});
107-
});
108-
}
109-
110-
$('#save').click(function() {
111-
var i = new Intent("http://webintents.org/save", "image/*", canvas.toDataURL());
112-
window.navigator.startActivity(i);
113-
});
114-
115-
$('#share').click(function() {
116-
var i = new Intent("http://webintents.org/share", "image/*", canvas.toDataURL());
117-
window.navigator.startActivity(i);
118-
});
119-
120-
$('#top').change(textChanged);
121-
$('#bottom').change(textChanged);
122-
});
123-
</script>
7+
<script type="text/javascript" src="scripts/index.js"></script>
1248
<intent action="http://webintents.org/edit"
1259
type="image/*"
12610
href="index.html" />

server/demos/inspirationmator/pages/pick.html

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{% extends "demos/mememator/layouts/application.html" %}
2-
{% block title %}Mememator: Pick an Image{% endblock %}
1+
{% extends "demos/inspirationmator/layouts/application.html" %}
2+
{% block title %}Inspirationmator: Pick an Image{% endblock %}
33
{% block headline %}Pick an Image{% endblock %}
44
{% block scripts %}
55
<script src="//webintents.org/webintents.min.js"></script>
@@ -12,20 +12,7 @@
1212
title="Mememator"
1313
href="pick.html"/>
1414
<script src="scripts/memegen.js"></script>
15-
<script>
16-
$(function() {
17-
$('#images img').click(function(e) {
18-
if(!!window.intent == false) {
19-
var i = new Intent("http://webintents.org/edit", "image/*", this.src);
20-
window.navigator.startActivity(i);
21-
}
22-
else {
23-
window.intent.postResult(this.src);
24-
setTimeout(function() { window.close(); }, 1000);
25-
}
26-
});
27-
});
28-
</script>
15+
<script src="scripts/pick.js"></script>
2916
{% endblock %}
3017
{% block content %}
3118
<div id="images">
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
var context;
2+
var canvas;
3+
var draw = function(topline, bottomline) {
4+
var image = $("#image");
5+
var width = image.width();
6+
var height = image.height();
7+
var canvasWidth = width + 100;
8+
var canvasHeight = height + 200;
9+
canvas.width = canvasWidth;
10+
canvas.height = canvasHeight;
11+
canvas.parentElement.parentElement.style.height = canvasHeight + "px";
12+
canvas.parentElement.parentElement.style.width = canvasWidth + "px";
13+
context = canvas.getContext('2d');
14+
context.save();
15+
context.fillStyle = "rgb(0,0,0)";
16+
context.fillRect(0,0, canvas.width, canvas.height);
17+
context.save();
18+
context.strokeStyle = "rgb(255,255,255)";
19+
context.lineWidth = 2;
20+
context.strokeRect(46, 46, width + 8, height + 8);
21+
context.restore();
22+
context.drawImage(image.get()[0], 50, 50);
23+
context.save();
24+
context.font = "62px Josefin Slab";
25+
context.textAlign = "center";
26+
context.fillStyle = "white";
27+
context.strokeStyle = "white";
28+
context.lineWidth = 2;
29+
context.fillText(topline, canvasWidth * 0.5, height + 105, canvasWidth * 0.9);
30+
context.restore();
31+
context.save();
32+
context.font = "24px Josefin Slab";
33+
context.textAlign = "center";
34+
context.fillStyle = "white";
35+
context.strokeStyle = "white";
36+
context.lineWidth = 2;
37+
context.fillText(bottomline, canvasWidth * 0.5, height + 150, canvasWidth * 0.9);
38+
context.restore();
39+
context.restore();
40+
};
41+
42+
function textChanged() {
43+
if (context) {
44+
topText = $('#top').val() || "";
45+
bottomText = $('#bottom').val() || "";
46+
draw(topText, bottomText);
47+
}
48+
}
49+
50+
var updateImage = function(data) {
51+
var url = $.isArray(data) ? data[0] : data;
52+
var img = $('#image');
53+
img.load(function() {
54+
var image = $('#image');
55+
canvas = $('#container canvas');
56+
if(canvas.length == 0) {
57+
canvas = document.createElement('canvas');
58+
$('#container').append(canvas);
59+
}
60+
else
61+
canvas = canvas[0];
62+
63+
draw("","");
64+
65+
if(window.intent) {
66+
$('#done').show();
67+
}
68+
else {
69+
$('#save').show();
70+
$('#share').show();
71+
}
72+
});
73+
loadImage(img, url);
74+
};
75+
76+
$(function() {
77+
if (window.intent) {
78+
$('#done').show();
79+
$('#done').click(function() {
80+
if (canvas) {
81+
window.intent.postResult(canvas.toDataURL());
82+
window.setTimeout(function() { window.close(); }, 1000);
83+
}
84+
});
85+
86+
updateImage(window.intent.data);
87+
}
88+
else {
89+
$('#container').click(function() {
90+
$('#save').hide();
91+
$('#share').hide();
92+
$('#done').hide();
93+
94+
var i = new Intent("http://webintents.org/pick", "image/*");
95+
window.navigator.startActivity(i, function(data) {
96+
updateImage(data);
97+
});
98+
});
99+
}
100+
101+
$('#save').click(function() {
102+
var i = new Intent("http://webintents.org/save", "image/*", canvas.toDataURL());
103+
window.navigator.startActivity(i);
104+
});
105+
106+
$('#share').click(function() {
107+
var i = new Intent("http://webintents.org/share", "image/*", canvas.toDataURL());
108+
window.navigator.startActivity(i);
109+
});
110+
111+
$('#top').change(textChanged);
112+
$('#bottom').change(textChanged);
113+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$(function() {
2+
$('#images img').click(function(e) {
3+
if(!!window.intent == false) {
4+
var i = new Intent("http://webintents.org/edit", "image/*", this.src);
5+
window.navigator.startActivity(i);
6+
}
7+
else {
8+
window.intent.postResult(this.src);
9+
setTimeout(function() { window.close(); }, 1000);
10+
}
11+
});
12+
});

0 commit comments

Comments
 (0)