mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Experemental Plain2Html/Html2Plain convertor (+ jQuery linkify)
This commit is contained in:
parent
8cfd52ef12
commit
e4333a6f90
18 changed files with 1211 additions and 604 deletions
88
vendors/jquery-linkify/jquery.linkify.js
vendored
Normal file
88
vendors/jquery-linkify/jquery.linkify.js
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Linkify - v1.1.6
|
||||
* Find URLs in plain text and return HTML for discovered links.
|
||||
* https://github.com/HitSend/jQuery-linkify/
|
||||
*
|
||||
* Made by SoapBox Innovations, Inc.
|
||||
* Under MIT License
|
||||
*/
|
||||
!function($, window, document) {
|
||||
"use strict";
|
||||
function Linkified(element, options) {
|
||||
this._defaults = defaults, this.element = element, this.setOptions(options), this.init();
|
||||
}
|
||||
var defaults = {
|
||||
tagName: "a",
|
||||
newLine: "\n",
|
||||
target: "_blank",
|
||||
linkClass: null,
|
||||
linkClasses: [],
|
||||
linkAttributes: null
|
||||
};
|
||||
Linkified.prototype = {
|
||||
constructor: Linkified,
|
||||
init: function() {
|
||||
1 === this.element.nodeType ? Linkified.linkifyNode.call(this, this.element) : this.element = Linkified.linkify.call(this, this.element.toString());
|
||||
},
|
||||
setOptions: function(options) {
|
||||
this.settings = Linkified.extendSettings(options, this.settings);
|
||||
},
|
||||
toString: function() {
|
||||
return this.element.toString();
|
||||
}
|
||||
}, Linkified.extendSettings = function(options, settings) {
|
||||
var prop;
|
||||
settings = settings || {};
|
||||
for (prop in defaults) settings[prop] || (settings[prop] = defaults[prop]);
|
||||
for (prop in options) settings[prop] = options[prop];
|
||||
return settings;
|
||||
}, Linkified.linkMatch = new RegExp([ "(", '\\s|[^a-zA-Z0-9.\\+_\\/"\\>\\-]|^', ")(?:", "(", "[a-zA-Z0-9\\+_\\-]+", "(?:", "\\.[a-zA-Z0-9\\+_\\-]+", ")*@", ")?(", "http:\\/\\/|https:\\/\\/|ftp:\\/\\/", ")?(", "(?:(?:[a-zA-Z0-9][a-zA-Z0-9_%\\-_+]*\\.)+)", ")(", "(?:com|ca|co|edu|gov|net|org|dev|biz|cat|int|pro|tel|mil|aero|asia|coop|info|jobs|mobi|museum|name|post|travel|local|[a-z]{2})", ")(", "(?::\\d{1,5})", ")?(", "(?:", "[\\/|\\?]", "(?:", "[\\-a-zA-Z0-9_%#*&+=~!?,;:.\\/]*", ")*", ")", "[\\-\\/a-zA-Z0-9_%#*&+=~]", "|", "\\/?", ")?", ")(", '[^a-zA-Z0-9\\+_\\/"\\<\\-]|$', ")" ].join(""), "g"),
|
||||
Linkified.emailLinkMatch = /(<[a-z]+ href=\")(http:\/\/)([a-zA-Z0-9\+_\-]+(?:\.[a-zA-Z0-9\+_\-]+)*@)/g,
|
||||
Linkified.linkify = function(text, options) {
|
||||
var attr, settings, linkClasses, linkReplace = [];
|
||||
this.constructor === Linkified && this.settings ? (settings = this.settings, options && (settings = Linkified.extendSettings(options, settings))) : settings = Linkified.extendSettings(options),
|
||||
linkClasses = settings.linkClass ? settings.linkClass.split(/\s+/) : [], linkClasses.push.apply(linkClasses, settings.linkClasses),
|
||||
text = text.replace(/</g, "<").replace(/(\s)/g, "$1$1"), linkReplace.push("$1<" + settings.tagName, 'href="http://$2$4$5$6$7"'),
|
||||
linkReplace.push('class="linkified' + (linkClasses.length > 0 ? " " + linkClasses.join(" ") : "") + '"'),
|
||||
settings.target && linkReplace.push('target="' + settings.target + '"');
|
||||
for (attr in settings.linkAttributes) linkReplace.push([ attr, '="', settings.linkAttributes[attr].replace(/\"/g, """).replace(/\$/g, "$"), '"' ].join(""));
|
||||
return linkReplace.push(">$2$3$4$5$6$7</" + settings.tagName + ">$8"), text = text.replace(Linkified.linkMatch, linkReplace.join(" ")),
|
||||
text = text.replace(Linkified.emailLinkMatch, "$1mailto:$3"), text = text.replace(/(\s){2}/g, "$1"),
|
||||
text = text.replace(/\n/g, settings.newLine);
|
||||
}, Linkified.linkifyNode = function(node) {
|
||||
var children, childNode, childCount, dummyElement, i;
|
||||
if (node && "object" == typeof node && 1 === node.nodeType && "a" !== node.tagName.toLowerCase() && !/[^\s]linkified[\s$]/.test(node.className)) {
|
||||
for (children = [], dummyElement = Linkified._dummyElement || document.createElement("div"),
|
||||
childNode = node.firstChild, childCount = node.childElementCount; childNode; ) {
|
||||
if (3 === childNode.nodeType) {
|
||||
for (;dummyElement.firstChild; ) dummyElement.removeChild(dummyElement.firstChild);
|
||||
for (dummyElement.innerHTML = Linkified.linkify.call(this, childNode.textContent || childNode.innerText || childNode.nodeValue),
|
||||
children.push.apply(children, dummyElement.childNodes); dummyElement.firstChild; ) dummyElement.removeChild(dummyElement.firstChild);
|
||||
} else 1 === childNode.nodeType ? children.push(Linkified.linkifyNode(childNode)) : children.push(childNode);
|
||||
childNode = childNode.nextSibling;
|
||||
}
|
||||
for (;node.firstChild; ) node.removeChild(node.firstChild);
|
||||
for (i = 0; i < children.length; i++) node.appendChild(children[i]);
|
||||
}
|
||||
return node;
|
||||
}, Linkified._dummyElement = document.createElement("div"), $.fn.linkify = function(options) {
|
||||
return this.each(function() {
|
||||
var linkified;
|
||||
(linkified = $.data(this, "plugin-linkify")) ? (linkified.setOptions(options), linkified.init()) : $.data(this, "plugin-linkify", new Linkified(this, options));
|
||||
});
|
||||
}, $.fn.linkify.Constructor = Linkified, $(window).on("load", function() {
|
||||
$("[data-linkify]").each(function() {
|
||||
var $target, $this = $(this), target = $this.attr("data-linkify"), options = {
|
||||
tagName: $this.attr("data-linkify-tagname"),
|
||||
newLine: $this.attr("data-linkify-newline"),
|
||||
target: $this.attr("data-linkify-target"),
|
||||
linkClass: $this.attr("data-linkify-linkclass")
|
||||
};
|
||||
for (var option in options) "undefined" == typeof options[option] && delete options[option];
|
||||
$target = "this" === target ? $this : $this.find(target), $target.linkify(options);
|
||||
});
|
||||
}), $("body").on("click", ".linkified", function() {
|
||||
var $link = $(this), url = $link.attr("href"), isEmail = /^mailto:/i.test(url), target = $link.attr("target");
|
||||
return isEmail ? window.location.href = url : window.open(url, target), !1;
|
||||
});
|
||||
}(jQuery, window, document);
|
||||
9
vendors/jquery-linkify/jquery.linkify.min.js
vendored
Normal file
9
vendors/jquery-linkify/jquery.linkify.min.js
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* Linkify - v1.1.6
|
||||
* Find URLs in plain text and return HTML for discovered links.
|
||||
* https://github.com/HitSend/jQuery-linkify/
|
||||
*
|
||||
* Made by SoapBox Innovations, Inc.
|
||||
* Under MIT License
|
||||
*/
|
||||
!function(a,b,c){"use strict";function d(a,b){this._defaults=e,this.element=a,this.setOptions(b),this.init()}var e={tagName:"a",newLine:"\n",target:"_blank",linkClass:null,linkClasses:[],linkAttributes:null};d.prototype={constructor:d,init:function(){1===this.element.nodeType?d.linkifyNode.call(this,this.element):this.element=d.linkify.call(this,this.element.toString())},setOptions:function(a){this.settings=d.extendSettings(a,this.settings)},toString:function(){return this.element.toString()}},d.extendSettings=function(a,b){var c;b=b||{};for(c in e)b[c]||(b[c]=e[c]);for(c in a)b[c]=a[c];return b},d.linkMatch=new RegExp(["(",'\\s|[^a-zA-Z0-9.\\+_\\/"\\>\\-]|^',")(?:","(","[a-zA-Z0-9\\+_\\-]+","(?:","\\.[a-zA-Z0-9\\+_\\-]+",")*@",")?(","http:\\/\\/|https:\\/\\/|ftp:\\/\\/",")?(","(?:(?:[a-zA-Z0-9][a-zA-Z0-9_%\\-_+]*\\.)+)",")(","(?:com|ca|co|edu|gov|net|org|dev|biz|cat|int|pro|tel|mil|aero|asia|coop|info|jobs|mobi|museum|name|post|travel|local|[a-z]{2})",")(","(?::\\d{1,5})",")?(","(?:","[\\/|\\?]","(?:","[\\-a-zA-Z0-9_%#*&+=~!?,;:.\\/]*",")*",")","[\\-\\/a-zA-Z0-9_%#*&+=~]","|","\\/?",")?",")(",'[^a-zA-Z0-9\\+_\\/"\\<\\-]|$',")"].join(""),"g"),d.emailLinkMatch=/(<[a-z]+ href=\")(http:\/\/)([a-zA-Z0-9\+_\-]+(?:\.[a-zA-Z0-9\+_\-]+)*@)/g,d.linkify=function(a,b){var c,e,f,g=[];this.constructor===d&&this.settings?(e=this.settings,b&&(e=d.extendSettings(b,e))):e=d.extendSettings(b),f=e.linkClass?e.linkClass.split(/\s+/):[],f.push.apply(f,e.linkClasses),a=a.replace(/</g,"<").replace(/(\s)/g,"$1$1"),g.push("$1<"+e.tagName,'href="http://$2$4$5$6$7"'),g.push('class="linkified'+(f.length>0?" "+f.join(" "):"")+'"'),e.target&&g.push('target="'+e.target+'"');for(c in e.linkAttributes)g.push([c,'="',e.linkAttributes[c].replace(/\"/g,""").replace(/\$/g,"$"),'"'].join(""));return g.push(">$2$3$4$5$6$7</"+e.tagName+">$8"),a=a.replace(d.linkMatch,g.join(" ")),a=a.replace(d.emailLinkMatch,"$1mailto:$3"),a=a.replace(/(\s){2}/g,"$1"),a=a.replace(/\n/g,e.newLine)},d.linkifyNode=function(a){var b,e,f,g,h;if(a&&"object"==typeof a&&1===a.nodeType&&"a"!==a.tagName.toLowerCase()&&!/[^\s]linkified[\s$]/.test(a.className)){for(b=[],g=d._dummyElement||c.createElement("div"),e=a.firstChild,f=a.childElementCount;e;){if(3===e.nodeType){for(;g.firstChild;)g.removeChild(g.firstChild);for(g.innerHTML=d.linkify.call(this,e.textContent||e.innerText||e.nodeValue),b.push.apply(b,g.childNodes);g.firstChild;)g.removeChild(g.firstChild)}else 1===e.nodeType?b.push(d.linkifyNode(e)):b.push(e);e=e.nextSibling}for(;a.firstChild;)a.removeChild(a.firstChild);for(h=0;h<b.length;h++)a.appendChild(b[h])}return a},d._dummyElement=c.createElement("div"),a.fn.linkify=function(b){return this.each(function(){var c;(c=a.data(this,"plugin-linkify"))?(c.setOptions(b),c.init()):a.data(this,"plugin-linkify",new d(this,b))})},a.fn.linkify.Constructor=d,a(b).on("load",function(){a("[data-linkify]").each(function(){var b,c=a(this),d=c.attr("data-linkify"),e={tagName:c.attr("data-linkify-tagname"),newLine:c.attr("data-linkify-newline"),target:c.attr("data-linkify-target"),linkClass:c.attr("data-linkify-linkclass")};for(var f in e)"undefined"==typeof e[f]&&delete e[f];b="this"===d?c:c.find(d),b.linkify(e)})}),a("body").on("click",".linkified",function(){var c=a(this),d=c.attr("href"),e=/^mailto:/i.test(d),f=c.attr("target");return e?b.location.href=d:b.open(d,f),!1})}(jQuery,window,document);
|
||||
Loading…
Add table
Add a link
Reference in a new issue