Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

The generator now remembers the glyphs you've previously used, and do…

…mains can be saved too.
  • Loading branch information...
commit 9355628c72405e2d8ac0413fb3d09f4a7618e9a1 1 parent f3747d1
@sorccu authored
View
2  generate/convert.php
@@ -99,7 +99,7 @@ function usage()
),
'domains' => array(
'filter' => FILTER_UNSAFE_RAW,
- 'flags' => FILTER_NULL_ON_FAILURE
+ 'flags' => FILTER_FORCE_ARRAY | FILTER_NULL_ON_FAILURE
),
'callback' => array(
'filter' => FILTER_SANITIZE_STRING,
View
29 generate/css/style.css
@@ -102,6 +102,35 @@ input {
color: red;
}
+ul.input-list {
+ list-style: none;
+ padding: 0;
+}
+
+.new, .del {
+ background: url(../img/icons.png) 0 0 no-repeat;
+ display: -moz-inline-box;
+ display: inline-block;
+ height: 0;
+ overflow: hidden;
+ text-indent: -10000in;
+ padding: 0 0 16px 16px;
+ vertical-align: 3px;
+ width: 0;
+}
+
+html>/**/body .new, html>/**/body .del {
+ vertical-align: text-bottom;
+}
+
+.del {
+ background-position: 0 -16px;
+}
+
+.no-del .del {
+ display: none;
+}
+
#nav {
list-style: none;
text-align: center;
View
BIN  generate/img/icons.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
12 generate/index.html
@@ -56,7 +56,7 @@
<div id="content">
- <form action="convert.php" method="post" enctype="multipart/form-data">
+ <form id="generator" action="convert.php" method="post" enctype="multipart/form-data">
<div class="section">
@@ -140,16 +140,18 @@
</div>
- <div class="section">
+ <div id="security" class="section">
<h3>Security</h3>
<dl>
- <dt><label for="idomains">Limit usage to the following domain(s)</label></dt>
+ <dt><label for="idomains">Limit usage to the following domains</label></dt>
<dd>
- <input type="text" name="domains" id="idomains" size="70" maxlength="250" value="" /> <span class="example">(example.org, www.example.org)</span>
+ <ul class="input-list no-del">
+ <li><input type="text" name="domains[]" size="50" maxlength="250" value="" /> <a href="#" class="new">[add]</a> <a href="#" class="del">[del]</a> <label><input type="checkbox" class="remember" value="yes" /> Remember this domain</label></li>
+ </ul>
<p class="info"><strong><em>Utilizing this feature is highly recommended, and may even be required if you're using commercial fonts.</em></strong></p>
- <p class="info">Separate multiple domains by either commas or spaces. You can also use wildcards (e.g. *.example.org to cover all subdomains of example.org). Using a font that doesn't match any of the allowed domains results in no text showing up.</p>
+ <p class="info">You can also use wildcards (e.g. *.example.org to cover example.org and all subdomains of example.org). Using a font that doesn't match any of the allowed domains results in only plain text showing up.</p>
</dd>
</dl>
View
115 generate/js/ui.js
@@ -1,6 +1,24 @@
(function() {
+ var Cookie = {
+
+ read: function(name) {
+ var re = new RegExp('(?:^|\\s|;)' + name + '=([^;]+)');
+ return decodeURIComponent((document.cookie.match(re) || [])[1] || '');
+ },
+
+ write: function(name, value, maxAge) {
+ value = value.toString();
+ document.cookie = [
+ encodeURIComponent(name) + '=' + encodeURIComponent(value),
+ 'Max-Age: ' + (value === '' ? -1 : (isNaN(maxAge) ? 2592000 : maxAge))
+ ].join('; ');
+ }
+
+ };
+
function addEvent(el, type, listener) {
+ if (!el) return;
if (el.addEventListener) {
el.addEventListener(type, listener, false);
}
@@ -11,7 +29,17 @@
}
}
+ function byId(id) {
+ return document.getElementById(id);
+ }
+
+ function byTag(tag, el) {
+ if (!el) return [];
+ return el.getElementsByTagName(tag);
+ }
+
function handle(el) {
+ var callback, node, clone, anchor, list, input;
switch (el.nodeName.toLowerCase()) {
case '#text':
// fall through
@@ -19,18 +47,97 @@
return handle(el.parentNode);
case 'a':
if (/callback/.test(el.className)) {
- var callback = document.getElementById('icallback');
+ callback = byId('icallback');
if (callback) {
callback.value = el.title;
el.blur();
return true;
}
}
+ if (/new/.test(el.className)) {
+ for (node = el.parentNode; node; node = node.parentNode) {
+ if (node.nodeName.toLowerCase() != 'li') continue;
+ clone = node.cloneNode(true);
+ anchor = node.nextSibling;
+ list = node.parentNode;
+ if (anchor) list.insertBefore(clone, anchor);
+ else list.appendChild(clone);
+ input = byTag('input', clone)[0];
+ input.value = '';
+ input.focus();
+ byTag('input', clone)[1].checked = false;
+ Cufon.CSS.removeClass(list, 'no-del');
+ return true;
+ }
+ }
+ if (/del/.test(el.className)) {
+ for (node = el.parentNode; node; node = node.parentNode) {
+ if (node.nodeName.toLowerCase() != 'li') continue;
+ list = node.parentNode;
+ list.removeChild(node);
+ if (byTag('li', list).length < 2) {
+ Cufon.CSS.addClass(list, 'no-del');
+ }
+ return true;
+ }
+ }
return false;
}
return false;
}
+ function fetch() {
+ var list, template, container, el, i, l;
+ list = Cookie.read('cu_dom');
+ if (list) {
+ list = decodeURIComponent(list).split(',');
+ template = byTag('li', byId('security'))[0];
+ for (i = 0, l = list.length; i < l; ++i) {
+ el = template.cloneNode(true);
+ byTag('input', el)[0].value = list[i].replace(/\s/g, '');
+ byTag('input', el)[1].checked = true;
+ container = template.parentNode;
+ container.insertBefore(el, template);
+ Cufon.CSS.removeClass(container, 'no-del');
+ }
+ }
+ list = Cookie.read('cu_gly');
+ if (list) {
+ list = decodeURIComponent(list).split(',');
+ for (i = 0, l = list.length; i < l; ++i) {
+ el = byId(list[i]);
+ if (el) el.checked = true;
+ }
+ }
+ el = byId('icustomGlyphs');
+ if (el) el.value = (Cookie.read('cu_cly') || '');
+ el = byId('iuseGlyphCSSRange');
+ if (el) el.checked = (Cookie.read('cu_lyr') == 'yes');
+ }
+
+ function store(e) {
+ var form = byId('generator'), inputs, input, list;
+ inputs = form.elements['domains[]']
+ if (inputs.nodeType) inputs = [ inputs ];
+ list = [];
+ for (i = 0; input = inputs[i]; ++i) {
+ if (input.value === '' || !byTag('input', input.parentNode)[1].checked) continue;
+ list.push(input.value);
+ }
+ Cookie.write('cu_dom', list);
+ inputs = form.elements['glyphs[]'];
+ if (inputs.nodeType) inputs = [ inputs ];
+ list = [];
+ for (i = 0; input = inputs[i]; ++i) {
+ if (input.checked) list.push(input.id);
+ }
+ Cookie.write('cu_gly', list);
+ input = byId('icustomGlyphs');
+ Cookie.write('cu_cly', input ? input.value : '');
+ input = byId('iuseGlyphCSSRange');
+ Cookie.write('cu_lyr', (input && input.checked) ? 'yes' : '');
+ }
+
addEvent(document, 'click', function(e) {
if (!handle(e.target || e.srcElement)) return;
if (e.preventDefault) e.preventDefault();
@@ -39,4 +146,10 @@
else e.returnValue = false;
});
+ addEvent(window, 'load', function() {
+ if (!byId('generator')) return;
+ addEvent(byId('generator'), 'submit', store);
+ fetch();
+ });
+
})();
View
2  generate/lib/SVGFont.php
@@ -248,7 +248,7 @@ public function toJavaScript()
*/
private static function processFont($data, $options)
{
- $domains = preg_split('/\s*[, ]\s*/', trim($options['domains']), -1, PREG_SPLIT_NO_EMPTY);
+ $domains = preg_split('/\s*[, ]\s*/', trim(implode(', ', $options['domains'])), -1, PREG_SPLIT_NO_EMPTY);
if (empty($domains))
{
Please sign in to comment.
Something went wrong with that request. Please try again.