From 4bd77f8dbf0e64d9bddcf279dd2039dc3e390ffb Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Sat, 14 Jun 2014 21:38:37 +0200 Subject: [PATCH] Remove html from Tags, Description and Title input --- assets/js/album.js | 13 ++++++++++++- assets/js/lychee.js | 8 ++++++++ assets/js/photo.js | 11 +++++++++++ assets/min/main.js | 6 +++--- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/assets/js/album.js b/assets/js/album.js index f1f3c7b..864a9c6 100644 --- a/assets/js/album.js +++ b/assets/js/album.js @@ -207,7 +207,14 @@ album = { buttons = [ ["Set Title", function() { - newTitle = ($(".message input.text").val()==="") ? "Untitled" : $(".message input.text").val(); + // Get input + newTitle = $(".message input.text").val(); + + // Remove html from input + newTitle = lychee.removeHTML(newTitle); + + // Set to Untitled when empty + newTitle = (newTitle==="") ? "Untitled" : newTitle; if (visible.album()) { @@ -249,8 +256,12 @@ album = { buttons = [ ["Set Description", function() { + // Get input description = $(".message input.text").val(); + // Remove html from input + description = lychee.removeHTML(description); + if (visible.album()) { album.json.description = description; view.album.description(); diff --git a/assets/js/lychee.js b/assets/js/lychee.js index 346dd41..e640c16 100644 --- a/assets/js/lychee.js +++ b/assets/js/lychee.js @@ -336,6 +336,14 @@ var lychee = { }, + removeHTML: function(html) { + + var tmp = document.createElement("DIV"); + tmp.innerHTML = html; + return tmp.textContent || tmp.innerText; + + }, + error: function(errorThrown, params, data) { console.log("Error Description: " + errorThrown); diff --git a/assets/js/photo.js b/assets/js/photo.js index ef90cf8..e4aa7d3 100644 --- a/assets/js/photo.js +++ b/assets/js/photo.js @@ -207,8 +207,12 @@ photo = { buttons = [ ["Set Title", function() { + // Get input newTitle = $(".message input.text").val(); + // Remove html from input + newTitle = lychee.removeHTML(newTitle); + if (visible.photo()) { photo.json.title = (newTitle==="") ? "Untitled" : newTitle; view.photo.title(); @@ -337,8 +341,12 @@ photo = { buttons = [ ["Set Description", function() { + // Get input description = $(".message input.text").val(); + // Remove html from input + description = lychee.removeHTML(description); + if (visible.photo()) { photo.json.description = description; view.photo.description(); @@ -410,6 +418,9 @@ photo = { tags = tags.replace(/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/g, ','); tags = tags.replace(/,$|^,|(\ ){0,}$/g, ''); + // Remove html from input + tags = lychee.removeHTML(tags); + if (visible.photo()) { photo.json.tags = tags; view.photo.tags(); diff --git a/assets/min/main.js b/assets/min/main.js index 7842240..039f2e5 100644 --- a/assets/min/main.js +++ b/assets/min/main.js @@ -2,6 +2,6 @@ function mobileBrowser(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)?!0:!1}function gup(a){a=a.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var b="[\\?&]"+a+"=([^&#]*)",c=new RegExp(b),d=c.exec(window.location.href);return null===d?"":d[1]}!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){function c(a){var b=a.length,c=ab.type(a);return"function"===c||ab.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}function d(a,b,c){if(ab.isFunction(b))return ab.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return ab.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(hb.test(b))return ab.filter(b,a,c);b=ab.filter(b,a)}return ab.grep(a,function(a){return U.call(b,a)>=0!==c})}function e(a,b){for(;(a=a[b])&&1!==a.nodeType;);return a}function f(a){var b=ob[a]={};return ab.each(a.match(nb)||[],function(a,c){b[c]=!0}),b}function g(){$.removeEventListener("DOMContentLoaded",g,!1),a.removeEventListener("load",g,!1),ab.ready()}function h(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=ab.expando+Math.random()}function i(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(ub,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:tb.test(c)?ab.parseJSON(c):c}catch(e){}sb.set(a,b,c)}else c=void 0;return c}function j(){return!0}function k(){return!1}function l(){try{return $.activeElement}catch(a){}}function m(a,b){return ab.nodeName(a,"table")&&ab.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function n(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function o(a){var b=Kb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function p(a,b){for(var c=0,d=a.length;d>c;c++)rb.set(a[c],"globalEval",!b||rb.get(b[c],"globalEval"))}function q(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(rb.hasData(a)&&(f=rb.access(a),g=rb.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)ab.event.add(b,e,j[e][c])}sb.hasData(a)&&(h=sb.access(a),i=ab.extend({},h),sb.set(b,i))}}function r(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&ab.nodeName(a,b)?ab.merge([a],c):c}function s(a,b){var c=b.nodeName.toLowerCase();"input"===c&&yb.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}function t(b,c){var d=ab(c.createElement(b)).appendTo(c.body),e=a.getDefaultComputedStyle?a.getDefaultComputedStyle(d[0]).display:ab.css(d[0],"display");return d.detach(),e}function u(a){var b=$,c=Ob[a];return c||(c=t(a,b),"none"!==c&&c||(Nb=(Nb||ab("