From 6777d8b2412bc328d995640ba2b38f7fdaa0ecb2 Mon Sep 17 00:00:00 2001 From: Nokita Kaze Date: Fri, 26 Dec 2014 09:45:36 +0300 Subject: [PATCH] =?UTF-8?q?https://bitbucket.org/skobkin/chrome=5Fpoint=5F?= =?UTF-8?q?plus/issue/47/fancybox=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome_point_plus/_locales/en/messages.json | 3 + chrome_point_plus/_locales/ru/messages.json | 3 + chrome_point_plus/js/point-plus.js | 106 +++++++++++--------- chrome_point_plus/manifest.json | 2 +- chrome_point_plus/options.html | 4 + 5 files changed, 68 insertions(+), 50 deletions(-) diff --git a/chrome_point_plus/_locales/en/messages.json b/chrome_point_plus/_locales/en/messages.json index 2da5306..46823c9 100644 --- a/chrome_point_plus/_locales/en/messages.json +++ b/chrome_point_plus/_locales/en/messages.json @@ -47,6 +47,9 @@ "option_fancybox_bind_images_to_one_flow": { "message": "Bind all images from fancybox to one flow" }, + "option_fancybox_smart_hints": { + "message": "Smart hints for images in fancybox gallery" + }, "option_images_load_original": { "message": "Load original images instead of thumbnails" }, diff --git a/chrome_point_plus/_locales/ru/messages.json b/chrome_point_plus/_locales/ru/messages.json index 3ba0d68..7b8c795 100644 --- a/chrome_point_plus/_locales/ru/messages.json +++ b/chrome_point_plus/_locales/ru/messages.json @@ -47,6 +47,9 @@ "option_fancybox_bind_images_to_one_flow": { "message": "Связать все картинки в одну галерею" }, + "option_fancybox_smart_hints": { + "message": "Включить умные описания для картинок при скроллинге галереи" + }, "option_images_load_original": { "message": "Загружать оригиналы вместо миниатюр" }, diff --git a/chrome_point_plus/js/point-plus.js b/chrome_point_plus/js/point-plus.js index f37114c..57d8df0 100644 --- a/chrome_point_plus/js/point-plus.js +++ b/chrome_point_plus/js/point-plus.js @@ -108,64 +108,26 @@ $(document).ready(function() { $('.post-content .text').each(function() { $(this).find('a.postimg:not(.youtube)').attr('data-fancybox-group', 'one_flow_gallery'); }); + }else{ + $('.post-content .text').each(function(idxPost) { + $(this).find('a.postimg:not(.youtube)').attr('data-fancybox-group', 'post' + idxPost); + }); } // Images if (options.option_fancybox_images.value == true) { - if (options.option_fancybox_bind_images_to_one_flow.value !== true) { - // Linking images in posts to the galleries - $('.post-content .text').each(function(idxPost) { - $(this).find('a.postimg:not(.youtube)').attr('data-fancybox-group', 'post' + idxPost); - }); - } // Init fancybox $('.postimg:not(.youtube)').fancybox({ type: 'image' }); } - // Правим хинт в FancyBox - $('.post').each(function() { - var all_post_images = $(this).find('.postimg'); - if (all_post_images.length == 0) { - return; - } - var tags = $(this).find('div.tags a.tag'); - var hint_text = '';// Текст для хинта в FancyBox - // Сначала теги - for (var i = 0; i < tags.length; i++) { - var tag_name = $(tags[i]).html().toLowerCase(); - hint_text += ' ' + tag_name; - } - - // Потом текст - var textcontent = $(this).find('.text-content'); - if (textcontent.length > 0) { - textcontent = textcontent[0]; - for (var i = 0; i < textcontent.childNodes.length; i++) { - var current_child_node = textcontent.childNodes[i]; - if ((current_child_node.nodeName !== 'P') && (current_child_node.nodeName !== '#text')) { - continue; - } - var a = $(current_child_node).find('a.postimg'); - if (a.length > 0) { - continue; - } - - var tmp_str = current_child_node.textContent.replace(/(\n(\r)?)/g, ' '); - tmp_str = tmp_str.replace("\t", " "); - hint_text += ' ' + tmp_str; - } - } - - // Режем - hint_text = hint_text.replace(new RegExp(' {2,}'), ' ').replace(new RegExp(' +$'), '').substr(1); - if (hint_text.length > 140) { - hint_text = hint_text.substr(0, 140 - 3) + '...'; - } - - all_post_images.attr('data-fancybox-title', hint_text); - }); + // Правим хинты у фансибокса + if (options.option_fancybox_smart_hints.value == true) { + fancybox_set_smart_hints(); + } else { + $('.post .postimg').attr('data-fancybox-title', ' '); + } // Videos if (options.option_fancybox_videos.value == true) { @@ -675,7 +637,7 @@ function parse_webm(current_options) { if (n = href.match(new RegExp('\\.webm(\\?.+)?$', 'i'))) { var player = document.createElement('video'); - // @todo Там может быть не vp8+vorbis + // Там может быть не vp8+vorbis, но мы этого никак не узнаем $(player).html('').attr('controls', 'controls').css({ 'display': 'block', 'max-width': '95%' @@ -1055,3 +1017,49 @@ function parse_coub_links(current_options) { } }); } + +// Правим хинт в FancyBox +function fancybox_set_smart_hints(){ + $('.post').each(function() { + var all_post_images = $(this).find('.postimg'); + if (all_post_images.length == 0) { + return; + } + + var tags = $(this).find('div.tags a.tag'); + var hint_text = '';// Текст для хинта в FancyBox + // Сначала теги + for (var i = 0; i < tags.length; i++) { + var tag_name = $(tags[i]).html().toLowerCase(); + hint_text += ' ' + tag_name; + } + + // Потом текст + var textcontent = $(this).find('.text-content'); + if (textcontent.length > 0) { + textcontent = textcontent[0]; + for (var i = 0; i < textcontent.childNodes.length; i++) { + var current_child_node = textcontent.childNodes[i]; + if ((current_child_node.nodeName !== 'P') && (current_child_node.nodeName !== '#text')) { + continue; + } + var a = $(current_child_node).find('a.postimg'); + if (a.length > 0) { + continue; + } + + var tmp_str = current_child_node.textContent.replace(/(\n(\r)?)/g, ' '); + tmp_str = tmp_str.replace("\t", " "); + hint_text += ' ' + tmp_str; + } + } + + // Режем + hint_text = hint_text.replace(new RegExp(' {2,}'), ' ').replace(new RegExp(' +$'), '').substr(1); + if (hint_text.length > 140) { + hint_text = hint_text.substr(0, 140 - 3) + '...'; + } + + all_post_images.attr('data-fancybox-title', hint_text); + }); +} diff --git a/chrome_point_plus/manifest.json b/chrome_point_plus/manifest.json index 69ac6e2..bda5e8d 100644 --- a/chrome_point_plus/manifest.json +++ b/chrome_point_plus/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Point+", - "version": "1.17.4", + "version": "1.18.0", "default_locale": "ru", "author": "__MSG_ext_author__", "homepage_url": "https://bitbucket.org/skobkin/chrome_point_plus", diff --git a/chrome_point_plus/options.html b/chrome_point_plus/options.html index aa4f4c9..e17e065 100644 --- a/chrome_point_plus/options.html +++ b/chrome_point_plus/options.html @@ -36,6 +36,10 @@
+ +
+ +