-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
192 lines (175 loc) · 7.03 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>FilteredPaste.js</title>
<link type="text/css" media='all' rel="stylesheet" href='css/normalize.css'/>
<style>
body, html { font: 14px arial, verdana; margin: 0px; padding: 0px; color: #222233; background: #cc1919; background: #fbfbfb; }
h1, h2, h3, h4 { color: #cc1919; }
a { text-decoration: none; border: none; }
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.header { width: 800px; margin: 20px auto; padding: 20px; }
.header a { display: block-inline; padding: 10px; }
.container { width: 800px; margin: 20px auto; background: #fff; padding: 20px; box-shadow: 0px 0px 5px #777; }
#contenteditables > div[contenteditable] { width: 100%; height: 100px; background: #eee; padding: 10px; margin: 10px; overflow: auto; margin-bottom: 30px; }
.syntaxhighlighter.js { overflow: hidden !important; }
</style>
<script src='js/jquery-1.8.1.min.js'></script>
<script src='js/jquery-filteredPaste.js'></script>
<script>
$(function() {
// Go with default settings
$("#input1").filteredPaste();
// Go with default settings
$("#input2").filteredPaste({
"filters" : ["default"]
});
// Go with no filters
$("#input3").filteredPaste({
"filters" : []
});
// Go with default filter but custom options that allows style attribute on any tag
$("#input4").filteredPaste({
"filters" : {
"default" : {
options : { "tags" : { "*" : { "attributes" : ["style"] }}}
}
}
});
// Go with custom filter. It makes all pasted text yellow
$("#input5").filteredPaste({
"filters" : {
"someName" : {
filter : function(content, options) {
return "<ins style='background: #eeee00;'>" + content + "</ins>";
},
options : { }
}
}
});
// Same as above, but define custom filter on $.filteredPaste *and* now also use default filter
$.filteredPaste.filters.customFilter = function(content, options) {
return "<ins style='background: #eeee00;'>" + content + "</ins>";
}
$("#input6").filteredPaste({
"filters" : ["default", "customFilter"]
});
});
</script>
<script type="text/javascript" src="syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="syntaxhighlighter/scripts/shBrushJScript.js"></script>
<link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shCoreDefault.css"/>
<script type="text/javascript">
SyntaxHighlighter.defaults.toolbar = false;
SyntaxHighlighter.all();
</script>
</head>
<body>
<div class="header">Projects <a href='http://willemmulder.github.com/Presenteer.js/'>Presenteer.js</a> <a href='http://willemmulder.github.com/BetterExamples.js/'>BetterExamples.js</a> <a href='http://willemmulder.github.com/FilteredPaste.js/'>FilteredPaste.js</a></div>
<div class="container">
<h1>FilteredPaste.js</h1>
<p class='source'>
Source code at <a href="https://github.com/willemmulder/FilteredPaste.js">https://github.com/willemmulder/FilteredPaste.js</a>
</p>
<h2>What does it do?</h2>
<p>
FilteredPaste.js is a jQuery plugin that filters any pasted input so that your application gets clean input, without any tags or attributes that you don't want. It supports native undo with control+z. IE and Opera are not supported yet.
</p>
<pre class="brush: js;" style='overflow: hidden;'>
// Simply works like this
$("#anytextarea").filteredPaste();
</pre>
<p>
Comes with a default filter that
</p>
<ul>
<li>allows the alt attribute on any tag</li>
<li>allows the src attribute on img tags</li>
<li>allows the href attribute on a and link tags</li>
</ul>
<p>
FilteredPaste also allows for custom filters. See below examples for how that works!
</p>
<h2>Examples</h2>
<div id='contenteditables'>
<p style='line-height: 35px; width: 300px; background: #ddf;'>
<span style='font: 16px serif;'>This is a snippet you could copy. It has </span><span style='font: 12px serif;'>custom styling that you don't want</span> and way too much whitespace between lines.
<p>
This is how pasting works without FilteredPaste
</p>
<div contenteditable='true'>Paste here. This contenteditable uses *no filteredPaste*</div>
<p>
And this is how it works *with* FilteredPaste
</p>
<pre class="brush: js;" style='overflow: hidden;'>
// Go with default settings
$("#input1").filteredPaste();
</pre>
<div contenteditable='true' id='input1'>Paste here. This contenteditable uses default settings of filteredPaste</div>
<pre class="brush: js;" style='overflow: hidden;'>
// Explicitly use default filter
$("#input2").filteredPaste({
"filters" : ["default"]
});
</pre>
<div contenteditable='true' id='input2'>Paste here. This contenteditable explicitly specifies the default filter</div>
<pre class="brush: js;" style='overflow: hidden;'>
// Use no filters
$("#input3").filteredPaste({
"filters" : []
});
</pre>
<div contenteditable='true' id='input3'>Paste here. This contenteditable uses filteredPaste, but with no filters.</div>
<pre class="brush: js;" style='overflow: hidden;'>
// Use default filter but set custom options that allows only style attribute on any tag
$("#input4").filteredPaste({
"filters" : {
"default" : {
options : { "tags" : { "*" : { "attributes" : ["style"] }}}
}
}
});
</pre>
<div contenteditable='true' id='input4'>Paste here. This contenteditable uses the default filter but with custom options. The style attribute is allowed on all tags.</div>
<pre class="brush: js;" style='overflow: hidden;'>
// Go with custom filter. It makes all pasted text yellow
$("#input5").filteredPaste({
"filters" : {
"someName" : {
filter : function(content, options) {
return "<ins style='background: #eeee00;'>" + content + "</ins>";
},
options : { }
}
}
});
</pre>
<div contenteditable='true' id='input5'>Paste here. It uses a custom filter that colors the inserted text yellow.</div>
<pre class="brush: js;" style='overflow: hidden;'>
// Same as above, but define custom filter on $.filteredPaste *and* now also use default filter
$.filteredPaste.filters.customFilter = function(content, options) {
return "<ins style='background: #eeee00;'>" + content + "</ins>";
}
$("#input6").filteredPaste({
"filters" : ["default", "customFilter"]
});
</pre>
<div contenteditable='true' id='input6'>Paste here. It uses the default filter, and additionally a custom filter that colors the inserted text yellow.</div>
</div>
</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-258109-14']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>