Add Photoswipe controllable classes, escape parents (#551)

1. Escape photoswipe
 - `.rx-escape`
 - `.photoswipe-escape`
2. No caption
 - `.photoswipe-no-caption`

3. if the img is a child of `a, pre, xml, textarea, input, select,
option, code, script, style, iframe, button, img, embed, object, ins`,
then escape photoswipe.
This commit is contained in:
Min-Soo Kim 2016-07-19 23:34:47 +09:00 committed by GitHub
parent 102f96207a
commit a8de6048ac

View file

@ -41,11 +41,12 @@ var initPhotoSwipeFromDOM = function(gallerySelector) {
pid: $(imgEl).attr('data-pswp-pid')
};
if(imgEl.alt) {
var ps_skip_alt_class = '.photoswipe-no-caption';
if(imgEl.alt && !$(imgEl).is(ps_skip_alt_class)) {
item.title = imgEl.alt;
}
if(imgEl.title) {
if(imgEl.title && !$(imgEl).is(ps_skip_alt_class)) {
item.title = imgEl.title;
}
@ -217,15 +218,19 @@ var initPhotoSwipeFromDOM = function(gallerySelector) {
// do not activate PhotoSwipe at the editor-component or other module components
var regx_skip = /(?:(modules|addons|classes|common|layouts|libs|widgets|widgetstyles)\/)/i;
var regx_allow_i6pngfix = /(?:common\/tpl\/images\/blank\.gif$)/i;
var ps_skip_class = 'rx-escape';
var ps_skip_class = '.rx-escape, .photoswipe-escape';
var ps_skip_elements = 'a, pre, xml, textarea, input, select, option, code, script, style, iframe, button, img, embed, object, ins';
var galleryImgEls = $(galleryElements[i]).find('img');
for(var j = 0, jl = galleryImgEls.length; j < jl; j++) {
// if the item has skip class, skip it.
if($(galleryImgEls[j]).hasClass(ps_skip_class)) continue;
// if the item has skip class(es), skip it.
if($(galleryImgEls[j]).is(ps_skip_class)) continue;
// skip components
if(regx_skip.test($(galleryImgEls[j]).attr('src')) && !regx_allow_i6pngfix.test($(galleryImgEls[j]).attr('src'))) continue;
// if the image is an item of some elements, skip it.
if($(galleryImgEls[j]).parent(ps_skip_elements).length > 0) continue;
//$(galleryImgEls[j]).attr('data-pswp-uid', i+1);
$(galleryImgEls[j]).attr('data-pswp-pid', j+1);