mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-10-06 02:02:24 +02:00
Added 'activateLinks' ability to description tags
This commit is contained in:
parent
050a1307cb
commit
05eb7d0f54
@ -411,6 +411,131 @@ function et2_csvSplit(_str, _num, _delimiter, _enclosure)
|
|||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given string and returns an array marking parts which are URLs
|
||||||
|
*/
|
||||||
|
function et2_activateLinks(_content)
|
||||||
|
{
|
||||||
|
var _match = false;
|
||||||
|
var arr = [];
|
||||||
|
|
||||||
|
function _splitPush(_matches, _proc)
|
||||||
|
{
|
||||||
|
if (_matches)
|
||||||
|
{
|
||||||
|
// We had a match
|
||||||
|
_match = true;
|
||||||
|
|
||||||
|
// Replace "undefined" with ""
|
||||||
|
for (var i = 1; i < _matches.length; i++)
|
||||||
|
{
|
||||||
|
if (typeof _matches[i] == "undefined")
|
||||||
|
{
|
||||||
|
_matches[i] = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split the content string at the given position
|
||||||
|
var splitted = _content.split(_matches[0], 2);
|
||||||
|
|
||||||
|
// Push the not-matched part
|
||||||
|
if (splitted[0])
|
||||||
|
{
|
||||||
|
// activate the links of the left string
|
||||||
|
arr = arr.concat(et2_activateLinks(splitted[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the callback function which converts the matches into an object
|
||||||
|
// and appends it to the string
|
||||||
|
_proc(_matches);
|
||||||
|
|
||||||
|
// Set the new working string to the right part
|
||||||
|
_content = splitted[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var mail_regExp = /mailto:([a-z0-9._-]+)@([a-z0-9_-]+)\.([a-z0-9._-]+)/i;
|
||||||
|
|
||||||
|
// First match things beginning with http:// (or other protocols)
|
||||||
|
var protocol = '(http:\\/\\/|(ftp:\\/\\/|https:\\/\\/))'; // only http:// gets removed, other protocolls are shown
|
||||||
|
var domain = '([\\w-]+\\.[\\w-.]+)';
|
||||||
|
var subdir = '([\\w\\-\\.,@?^=%&;:\\/~\\+#]*[\\w\\-\\@?^=%&\\/~\\+#])?';
|
||||||
|
var http_regExp = new RegExp(protocol + domain + subdir, 'i');
|
||||||
|
|
||||||
|
// Now match things beginning with www.
|
||||||
|
var domain = 'www(\\.[\\w-.]+)';
|
||||||
|
var subdir = '([\\w\\-\\.,@?^=%&:\\/~\\+#]*[\\w\\-\\@?^=%&\\/~\\+#])?';
|
||||||
|
var www_regExp = new RegExp(domain + subdir, 'i');
|
||||||
|
|
||||||
|
do {
|
||||||
|
_match = false;
|
||||||
|
|
||||||
|
// Abort if the remaining length of _content is smaller than 20 for
|
||||||
|
// performance reasons
|
||||||
|
if (!_content)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No need make emailaddress spam-save, as it gets dynamically created
|
||||||
|
_splitPush(_content.match(mail_regExp), function(_matches) {
|
||||||
|
arr.push({
|
||||||
|
"href": _matches[0],
|
||||||
|
"text": _matches[1] + "@" + _matches[2] + "." + _matches[3]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create hrefs for links starting with "http://"
|
||||||
|
_splitPush(_content.match(http_regExp), function(_matches) {
|
||||||
|
arr.push({
|
||||||
|
"href": _matches[0],
|
||||||
|
"text": _matches[2] + _matches[3] + _matches[4]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create hrefs for links starting with "www."
|
||||||
|
_splitPush(_content.match(www_regExp), function(_matches) {
|
||||||
|
arr.push({
|
||||||
|
"href": "http://" + _matches[0],
|
||||||
|
"text": _matches[0]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} while (_match)
|
||||||
|
|
||||||
|
arr.push(_content);
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts the structure generated by et2_activateLinks into the given DOM-Node
|
||||||
|
*/
|
||||||
|
function et2_insertLinkText(_text, _node, _target)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < _text.length; i++)
|
||||||
|
{
|
||||||
|
var s = _text[i];
|
||||||
|
|
||||||
|
if (typeof s == "string")
|
||||||
|
{
|
||||||
|
_node.appendChild(document.createTextNode(s));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var a = $j(document.createElement("a"))
|
||||||
|
.attr("href", s.href)
|
||||||
|
.text(s.text);
|
||||||
|
|
||||||
|
if (typeof _target != "undefined" && _target && _target != "_self")
|
||||||
|
{
|
||||||
|
a.attr("target", _target);
|
||||||
|
}
|
||||||
|
|
||||||
|
a.appendTo(_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a copy of the given object (non recursive)
|
* Creates a copy of the given object (non recursive)
|
||||||
*/
|
*/
|
||||||
|
@ -82,6 +82,7 @@ var et2_description = et2_baseWidget.extend({
|
|||||||
this.value = "";
|
this.value = "";
|
||||||
this.font_style = "";
|
this.font_style = "";
|
||||||
|
|
||||||
|
// Create the span/label tag which contains the label text
|
||||||
this.span = $j(document.createElement(this.options.label_for ? "label" : "span"))
|
this.span = $j(document.createElement(this.options.label_for ? "label" : "span"))
|
||||||
.addClass("et2_label");
|
.addClass("et2_label");
|
||||||
|
|
||||||
@ -91,13 +92,29 @@ var et2_description = et2_baseWidget.extend({
|
|||||||
this.span.attr("for", this.options.label_for);
|
this.span.attr("for", this.options.label_for);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create an array which contains the parts of the text with links around
|
||||||
|
// it
|
||||||
|
et2_insertLinkText(this._parseText(), this.span[0], this.options.extra_link_target);
|
||||||
|
|
||||||
this.setDOMNode(this.span[0]);
|
this.setDOMNode(this.span[0]);
|
||||||
},
|
},
|
||||||
|
|
||||||
set_value: function(_value) {
|
_parseText: function() {
|
||||||
this.value = _value;
|
if (this.options.href)
|
||||||
|
{
|
||||||
this.span.text(_value);
|
return [{
|
||||||
|
"href": this.options.href,
|
||||||
|
"text": this.options.value
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
else if (this.options.activate_links)
|
||||||
|
{
|
||||||
|
return et2_activateLinks(this.options.value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return [this.options.value];
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
set_font_style: function(_value) {
|
set_font_style: function(_value) {
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
<vbox>
|
<vbox>
|
||||||
<description value="This is only a test" options="bi" />
|
<description value="This is only a test" options="bi" />
|
||||||
<description value="This is only a test" font_style="italic" statustext="This is only an italic label!"/>
|
<description value="This is only a test" font_style="italic" statustext="This is only an italic label!"/>
|
||||||
|
<description value="Welcome to http://www.egroupware.org/, if you have any question feel free to write a mail to mailto:info@egroupware.org" activate_links="true" />
|
||||||
|
<description value="Go to the EGroupware homepage" href="http://www.egroupware.org/" extra_link_target="_popup"/>
|
||||||
</vbox>
|
</vbox>
|
||||||
</overlay>
|
</overlay>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user