X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=view%2Fjs%2FlinkPreview.js;h=28c8df9b673f01f53ae1af88663a0c73432bddc0;hb=96d2cddb54f3ea3ead6e43e5ca1f814ed6327987;hp=7644af7fee4f37b41ee25eada88458284020ade5;hpb=e7c3d327cc566b23ef008bedc0c743ba327f65f6;p=friendica.git diff --git a/view/js/linkPreview.js b/view/js/linkPreview.js index 7644af7fee..28c8df9b67 100644 --- a/view/js/linkPreview.js +++ b/view/js/linkPreview.js @@ -14,45 +14,43 @@ $.fn.linkPreview = function (options) { var opts = jQuery.extend({}, $.fn.linkPreview.defaults, options); - var selector = $(this).selector; - selector = selector.substr(1); + var id = $(this).attr('id'); var previewTpl = '\ -
\ +
\ {1}\ - \ - \ - \ + \ + \ + \
'; var attachmentTpl = '\
\ -
\ +
\ \
\ -
\ -
\ - \
\ -
\ +
\
\ - \ - \ - \ - \ + \ + \ + \ + \
\ -
\ -

\ -
\ -
\ - \ +
\ +

\ +
\ +
\ + \
\
\
'; var text; - var urlRegex = /(?" + escapeHTML(data.title) + "\ - " + $('#previewTitle_' + id).html("\ + " + escapeHTML(data.title) + "\ + " ); - $('#previewDescription_' + selector).html("\ - " + escapeHTML(description) + "\n\ - " + $('#previewDescription_' + id).html("\ + " + escapeHTML(description) + "\n\ + " ); }; @@ -328,7 +324,7 @@ var regexpr = "(https?://)([^:^/]*)(:\\d*)?(.*)?"; var regResult = url.match(regexpr); var urlHost = regResult[1] + regResult[2]; - $('#previewUrl_' + selector).html("" + urlHost + ""); + $('#previewUrl_' + id).html("" + urlHost + ""); } }; @@ -343,12 +339,12 @@ var imageClass = 'attachment-preview'; if (Array.isArray(images)) { - $('#previewImages_' + selector).show(); - $('#attachmentImageSrc_' + selector).val(bin2hex(images[photoNumber].src)); - $('#attachmentImageWidth_' + selector).val(images[photoNumber].width); - $('#attachmentImageHeight_' + selector).val(images[photoNumber].height); + $('#previewImages_' + id).show(); + $('#attachmentImageSrc_' + id).val(bin2hex(images[photoNumber].src)); + $('#attachmentImageWidth_' + id).val(images[photoNumber].width); + $('#attachmentImageHeight_' + id).val(images[photoNumber].height); } else { - $('#previewImages_' + selector).hide(); + $('#previewImages_' + id).hide(); } images.length = parseInt(images.length); @@ -356,32 +352,32 @@ for (i = 0; i < images.length; i++) { // For small preview images we use a smaller attachment format. - ///@todo here we need to add a check for !Config::get('system', 'always_show_preview'). + ///@todo here we need to add a check for !DI::config()->get('system', 'always_show_preview'). if (images[i].width >= 500 && images[i].width >= images[i].height) { imageClass = 'attachment-image'; } if (i === 0) { - appendImage += ""; + appendImage += ""; } else { - appendImage += ""; + appendImage += ""; } } - $('#previewImage_' + selector).html(appendImage + ""); + $('#previewImage_' + id).html(appendImage + ""); // More than just one image. if (images.length > 1) { - // Enable the the button to change the preview pictures. - $('#previewChangeImg_' + selector).show(); + // Enable the button to change the preview pictures. + $('#previewChangeImg_' + id).show(); if (firstPosted === false) { firstPosted = true; - $('#previewChangeImg_' + selector).unbind('click').click(function (e) { + $('#previewChangeImg_' + id).unbind('click').click(function (e) { e.stopPropagation(); if (images.length > 1) { - $('#imagePreview_' + selector + '_' + photoNumber).css({ + $('#imagePreview_' + id + '_' + photoNumber).css({ 'display': 'none' }); photoNumber += 1; @@ -391,13 +387,13 @@ photoNumber = 0; } - $('#imagePreview_' + selector + '_' + photoNumber).css({ + $('#imagePreview_' + id + '_' + photoNumber).css({ 'display': 'block' }); - $('#photoNumber_' + selector).val(photoNumber); - $('#attachmentImageSrc_' + selector).val(bin2hex(images[photoNumber].src)); - $('#attachmentImageWidth_' + selector).val(images[photoNumber].width); - $('#attachmentImageHeight_' + selector).val(images[photoNumber].height); + $('#photoNumber_' + id).val(photoNumber); + $('#attachmentImageSrc_' + id).val(bin2hex(images[photoNumber].src)); + $('#attachmentImageWidth_' + id).val(images[photoNumber].width); + $('#attachmentImageHeight_' + id).val(images[photoNumber].height); } }); } @@ -410,101 +406,101 @@ * @returns {void} */ var processEventListener = function() { - $('#previewSpanTitle_' + selector).unbind('click').click(function (e) { + $('#previewSpanTitle_' + id).unbind('click').click(function (e) { e.stopPropagation(); if (blockTitle === false) { blockTitle = true; - $('#previewSpanTitle_' + selector).hide(); - $('#previewInputTitle_' + selector).show(); - $('#previewInputTitle_' + selector).val($('#previewInputTitle_' + selector).val()); - $('#previewInputTitle_' + selector).focus().select(); + $('#previewSpanTitle_' + id).hide(); + $('#previewInputTitle_' + id).show(); + $('#previewInputTitle_' + id).val($('#previewInputTitle_' + id).val()); + $('#previewInputTitle_' + id).focus().select(); } }); - $('#previewInputTitle_' + selector).blur(function () { + $('#previewInputTitle_' + id).blur(function () { blockTitle = false; - $('#previewSpanTitle_' + selector).html($('#previewInputTitle_' + selector).val()); - $('#previewSpanTitle_' + selector).show(); - $('#previewInputTitle_' + selector).hide(); + $('#previewSpanTitle_' + id).html($('#previewInputTitle_' + id).val()); + $('#previewSpanTitle_' + id).show(); + $('#previewInputTitle_' + id).hide(); }); - $('#previewInputTitle_' + selector).keypress(function (e) { + $('#previewInputTitle_' + id).keypress(function (e) { if (e.which === 13) { blockTitle = false; - $('#previewSpanTitle_' + selector).html($('#previewInputTitle_' + selector).val()); - $('#previewSpanTitle_' + selector).show(); - $('#previewInputTitle_' + selector).hide(); + $('#previewSpanTitle_' + id).html($('#previewInputTitle_' + id).val()); + $('#previewSpanTitle_' + id).show(); + $('#previewInputTitle_' + id).hide(); } }); - $('#previewSpanDescription_' + selector).unbind('click').click(function (e) { + $('#previewSpanDescription_' + id).unbind('click').click(function (e) { e.stopPropagation(); if (blockDescription === false) { blockDescription = true; - $('#previewSpanDescription_' + selector).hide(); - $('#previewInputDescription_' + selector).show(); - $('#previewInputDescription_' + selector).val($('#previewInputDescription_' + selector).val()); - $('#previewInputDescription_' + selector).focus().select(); + $('#previewSpanDescription_' + id).hide(); + $('#previewInputDescription_' + id).show(); + $('#previewInputDescription_' + id).val($('#previewInputDescription_' + id).val()); + $('#previewInputDescription_' + id).focus().select(); } }); - $('#previewInputDescription_' + selector).blur(function () { + $('#previewInputDescription_' + id).blur(function () { blockDescription = false; - $('#previewSpanDescription_' + selector).html($('#previewInputDescription_' + selector).val()); - $('#previewSpanDescription_' + selector).show(); - $('#previewInputDescription_' + selector).hide(); + $('#previewSpanDescription_' + id).html($('#previewInputDescription_' + id).val()); + $('#previewSpanDescription_' + id).show(); + $('#previewInputDescription_' + id).hide(); }); - $('#previewInputDescription_' + selector).keypress(function (e) { + $('#previewInputDescription_' + id).keypress(function (e) { if (e.which === 13) { blockDescription = false; - $('#previewSpanDescription_' + selector).html($('#previewInputDescription_' + selector).val()); - $('#previewSpanDescription_' + selector).show(); - $('#previewInputDescription_' + selector).hide(); + $('#previewSpanDescription_' + id).html($('#previewInputDescription_' + id).val()); + $('#previewSpanDescription_' + id).show(); + $('#previewInputDescription_' + id).hide(); } }); - $('#previewSpanTitle_' + selector).mouseover(function () { - $('#previewSpanTitle_' + selector).css({ + $('#previewSpanTitle_' + id).mouseover(function () { + $('#previewSpanTitle_' + id).css({ "background-color": "#ff9" }); }); - $('#previewSpanTitle_' + selector).mouseout(function () { - $('#previewSpanTitle_' + selector).css({ + $('#previewSpanTitle_' + id).mouseout(function () { + $('#previewSpanTitle_' + id).css({ "background-color": "transparent" }); }); - $('#previewSpanDescription_' + selector).mouseover(function () { - $('#previewSpanDescription_' + selector).css({ + $('#previewSpanDescription_' + id).mouseover(function () { + $('#previewSpanDescription_' + id).css({ "background-color": "#ff9" }); }); - $('#previewSpanDescription_' + selector).mouseout(function () { - $('#previewSpanDescription_' + selector).css({ + $('#previewSpanDescription_' + id).mouseout(function () { + $('#previewSpanDescription_' + id).css({ "background-color": "transparent" }); }); - $('#closePreview_' + selector).unbind('click').click(function (e) { + $('#closePreview_' + id).unbind('click').click(function (e) { e.stopPropagation(); block = false; images = ''; isActive = false; firstPosted = false; - $('#preview_' + selector).fadeOut("fast", function () { - $('#preview_' + selector).remove(); + $('#preview_' + id).fadeOut("fast", function () { + $('#preview_' + id).remove(); $('#profile-rotator').hide(); - $('#' + selector).focus(); + $('#' + id).focus(); }); }); }; /** - * Convert attachmant bbcode into an array. + * Convert attachment bbcode into an array. * * @param {string} content Text content with the attachment bbcode. * @returns {object || null} @@ -552,12 +548,12 @@ matches = attributes.match(/url='([\s\S]*?)'/im); if (matches !== null && typeof matches[1] !== 'undefined') { - url = matches[1].toLowerCase(); + url = matches[1]; } matches = attributes.match(/url="([\s\S]*?)"/im); if (matches !== null && typeof matches[1] !== 'undefined') { - url = matches[1].toLowerCase(); + url = matches[1]; } if(url !== '') { @@ -568,12 +564,12 @@ matches = attributes.match(/title='([\s\S]*?)'/im); if (matches !== null && typeof matches[1] !== 'undefined') { - title = matches[1].toLowerCase(); + title = trim(matches[1]); } matches = attributes.match(/title="([\s\S]*?)"/im); if (matches !== null && typeof matches[1] !== 'undefined') { - title = matches[1].toLowerCase(); + title = trim(matches[1]); } if (title !== '') { @@ -584,12 +580,12 @@ matches = attributes.match(/image='([\s\S]*?)'/im); if (matches !== null && typeof matches[1] !== 'undefined') { - image = matches[1].toLowerCase(); + image = trim(matches[1]); } matches = attributes.match(/image="([\s\S]*?)"/im); if (matches !== null && typeof matches[1] !== 'undefined') { - image = matches[1].toLowerCase(); + image = trim(matches[1]); } if (image !== '') { @@ -600,12 +596,12 @@ matches = attributes.match(/preview='([\s\S]*?)'/im); if (matches !== null && typeof matches[1] !== 'undefined') { - preview = matches[1].toLowerCase(); + preview = trim(matches[1]); } matches = attributes.match(/preview="([\s\S]*?)"/im); if (matches !== null && typeof matches[1] !== 'undefined') { - preview = matches[1].toLowerCase(); + preview = trim(matches[1]); } if (preview !== '') { @@ -631,8 +627,8 @@ reAddAttachment(attachmentData); // Remove the attachment bbcode from the textarea. var content = content.replace(/\[attachment[\s\S]*\[\/attachment]/im, ''); - $('#' + selector).val(content); - $('#' + selector).focus(); + $('#' + id).val(content); + $('#' + id).focus(); } }; @@ -679,16 +675,16 @@ } if (image !== '') { - var appendImage = "" - $('#previewImage_' + selector).html(appendImage); - $('#attachmentImageSrc_' + selector).val(bin2hex(image)); + var appendImage = "" + $('#previewImage_' + id).html(appendImage); + $('#attachmentImageSrc_' + id).val(bin2hex(image)); - // We need to add the image widht and height when it is + // We need to add the image width and height when it is // loaded. $('' ,{ load : function(){ - $('#attachmentImageWidth_' + selector).val(this.width); - $('#attachmentImageHeight_' + selector).val(this.height); + $('#attachmentImageWidth_' + id).val(this.width); + $('#attachmentImageHeight_' + id).val(this.height); }, src : image }); @@ -754,8 +750,8 @@ * @returns {void} */ var destroy = function() { - $('#' + selector).unbind(); - $('#preview_' + selector).remove(); + $('#' + id).unbind(); + $('#preview_' + id).remove(); binurl; block = false; blockTitle = false; @@ -767,7 +763,7 @@ firstPosted = false; isActive = false; isCrawling = false; - selector = ""; + id = ""; }; var trim = function(str) { @@ -809,7 +805,7 @@ /** * Get in a textarea the previous word before the cursor. * - * @param {object} text Textarea elemet. + * @param {object} text Textarea element. * @param {integer} caretPos Cursor position. * * @returns {string} Previous word. @@ -817,7 +813,7 @@ function returnWord(text, caretPos) { var index = text.indexOf(caretPos); var preText = text.substring(0, caretPos); - // If the last charachter is a space or enter remove it + // If the last character is a space or enter remove it // We need this in friendica for the url preview. var lastChar = preText.slice(-1) if ( lastChar === " " @@ -857,9 +853,9 @@ } /** - * Get the cursor posiotion in an text element. + * Get the cursor position in an text element. * - * @param {object} ctrl Textarea elemet. + * @param {object} ctrl Textarea element. * @returns {integer} Position of the cursor. */ function getCaretPosition(ctrl) {