2014-04-27 15:29:54 +00:00
|
|
|
/*!
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
* Show gallery captions when focused. Copied directly from jquery.mw-jump.js.
|
|
|
|
|
* Also Dynamically resize images to justify them.
|
|
|
|
|
*/
|
mediawiki.page.gallery.resize: Remove weird mw.hook call
This mw.hook has no place here, there's various things wrong
with it:
* Naming.
We don't prefix event names with "mediawiki" nor the module
name. This pattern does not exist and this being here makes
understanding mw.hook by example harder and only adds to the
confusion.
* Synchronous behaviour.
Aside from the naming (details..), mw.hook simply doesn't do
what the code is asking for here and exhibits behaviour the
gallery relies on to to happen.
By design, mw.hook is asynchronous and memorises the last call
for new event handlers to allow modifying the last version of a
particular interface. It's like document-ready, if you bind
after the document is already ready, it's just to declare it
needs the document to be ready. It's not for exactly when that
happened, just that it happens after.
* Plurality.
To make matters worse, aside from naming and asynchonisity,
the gallery is also calling it in a loop, which is another
violation of mw.hook's design. When something emits mw.hook,
it means any previous state is no longer active (e.g. the user
switched modes, or navigated to another page with AJAX, or
closed the relevant dialog, or opened another one etc.).
Also removed some mw.log calls that seems to be left from
development. If these are important during regular usage, it should
probably throw an exception or use mw.log.warn instead.
Change-Id: Iefdfab26fcd24e3f9f8f3f2fc7f1fdba9f838a25
2014-06-11 15:31:34 +00:00
|
|
|
( function ( $ ) {
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
$( function () {
|
|
|
|
|
var isTouchScreen,
|
|
|
|
|
gettingFocus,
|
|
|
|
|
galleries = 'ul.mw-gallery-packed-overlay, ul.mw-gallery-packed-hover, ul.mw-gallery-packed';
|
|
|
|
|
|
|
|
|
|
// Is there a better way to detect a touchscreen? Current check taken from stack overflow.
|
|
|
|
|
isTouchScreen = !!( window.ontouchstart !== undefined || window.DocumentTouch !== undefined && document instanceof window.DocumentTouch );
|
|
|
|
|
|
|
|
|
|
if ( isTouchScreen ) {
|
|
|
|
|
// Always show the caption for a touch screen.
|
|
|
|
|
$( 'ul.mw-gallery-packed-hover' )
|
|
|
|
|
.addClass( 'mw-gallery-packed-overlay' )
|
|
|
|
|
.removeClass( 'mw-gallery-packed-hover' );
|
|
|
|
|
} else {
|
|
|
|
|
// Note use of just "a", not a.image, since we want this to trigger if a link in
|
|
|
|
|
// the caption receives focus
|
|
|
|
|
$( 'ul.mw-gallery-packed-hover li.gallerybox' ).on( 'focus blur', 'a', function ( e ) {
|
|
|
|
|
// Confusingly jQuery leaves e.type as focusout for delegated blur events
|
|
|
|
|
gettingFocus = e.type !== 'blur' && e.type !== 'focusout';
|
|
|
|
|
$( this ).closest( 'li.gallerybox' ).toggleClass( 'mw-gallery-focused', gettingFocus );
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now on to justification.
|
2015-01-04 07:32:52 +00:00
|
|
|
function justify() {
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
var lastTop,
|
|
|
|
|
$img,
|
|
|
|
|
imgWidth,
|
|
|
|
|
imgHeight,
|
2015-01-04 07:32:52 +00:00
|
|
|
captionWidth,
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
rows = [],
|
|
|
|
|
$gallery = $( this );
|
|
|
|
|
|
2014-01-21 20:49:07 +00:00
|
|
|
$gallery.children( 'li' ).each( function () {
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
// Math.floor to be paranoid if things are off by 0.00000000001
|
2014-01-21 20:49:07 +00:00
|
|
|
var top = Math.floor( $( this ).position().top ),
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
$this = $( this );
|
|
|
|
|
|
|
|
|
|
if ( top !== lastTop ) {
|
|
|
|
|
rows[rows.length] = [];
|
|
|
|
|
lastTop = top;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$img = $this.find( 'div.thumb a.image img' );
|
|
|
|
|
if ( $img.length && $img[0].height ) {
|
|
|
|
|
imgHeight = $img[0].height;
|
|
|
|
|
imgWidth = $img[0].width;
|
|
|
|
|
} else {
|
|
|
|
|
// If we don't have a real image, get the containing divs width/height.
|
|
|
|
|
// Note that if we do have a real image, using this method will generally
|
|
|
|
|
// give the same answer, but can be different in the case of a very
|
|
|
|
|
// narrow image where extra padding is added.
|
|
|
|
|
imgHeight = $this.children().children( 'div:first' ).height();
|
|
|
|
|
imgWidth = $this.children().children( 'div:first' ).width();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hack to make an edge case work ok
|
|
|
|
|
if ( imgHeight < 30 ) {
|
|
|
|
|
// Don't try and resize this item.
|
|
|
|
|
imgHeight = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-04 07:32:52 +00:00
|
|
|
captionWidth = $this.children().children( 'div.gallerytextwrapper' ).width();
|
2014-01-31 02:03:11 +00:00
|
|
|
rows[rows.length - 1][rows[rows.length - 1].length] = {
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
$elm: $this,
|
|
|
|
|
width: $this.outerWidth(),
|
|
|
|
|
imgWidth: imgWidth,
|
2014-01-31 02:03:11 +00:00
|
|
|
// XXX: can divide by 0 ever happen?
|
|
|
|
|
aspect: imgWidth / imgHeight,
|
2015-01-04 07:32:52 +00:00
|
|
|
captionWidth: captionWidth,
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
height: imgHeight
|
|
|
|
|
};
|
2015-01-04 07:32:52 +00:00
|
|
|
|
|
|
|
|
// Save all boundaries so we can restore them on window resize
|
|
|
|
|
$this.data( 'imgWidth', imgWidth );
|
|
|
|
|
$this.data( 'imgHeight', imgHeight );
|
|
|
|
|
$this.data( 'width', $this.outerWidth() );
|
|
|
|
|
$this.data( 'captionWidth', captionWidth );
|
2014-01-21 20:49:07 +00:00
|
|
|
} );
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
|
2014-01-21 20:49:07 +00:00
|
|
|
( function () {
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
var maxWidth,
|
|
|
|
|
combinedAspect,
|
|
|
|
|
combinedPadding,
|
|
|
|
|
curRow,
|
|
|
|
|
curRowHeight,
|
|
|
|
|
wantedWidth,
|
|
|
|
|
preferredHeight,
|
|
|
|
|
newWidth,
|
|
|
|
|
padding,
|
|
|
|
|
$outerDiv,
|
|
|
|
|
$innerDiv,
|
|
|
|
|
$imageDiv,
|
|
|
|
|
$imageElm,
|
|
|
|
|
imageElm,
|
|
|
|
|
$caption,
|
|
|
|
|
i,
|
2013-08-21 17:00:47 +00:00
|
|
|
j,
|
|
|
|
|
avgZoom,
|
|
|
|
|
totalZoom = 0;
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
|
|
|
|
|
for ( i = 0; i < rows.length; i++ ) {
|
|
|
|
|
maxWidth = $gallery.width();
|
|
|
|
|
combinedAspect = 0;
|
|
|
|
|
combinedPadding = 0;
|
|
|
|
|
curRow = rows[i];
|
|
|
|
|
curRowHeight = 0;
|
|
|
|
|
|
|
|
|
|
for ( j = 0; j < curRow.length; j++ ) {
|
|
|
|
|
if ( curRowHeight === 0 ) {
|
|
|
|
|
if ( isFinite( curRow[j].height ) ) {
|
|
|
|
|
// Get the height of this row, by taking the first
|
|
|
|
|
// non-out of bounds height
|
|
|
|
|
curRowHeight = curRow[j].height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( curRow[j].aspect === 0 || !isFinite( curRow[j].aspect ) ) {
|
|
|
|
|
// One of the dimensions are 0. Probably should
|
|
|
|
|
// not try to resize.
|
|
|
|
|
combinedPadding += curRow[j].width;
|
|
|
|
|
} else {
|
|
|
|
|
combinedAspect += curRow[j].aspect;
|
|
|
|
|
combinedPadding += curRow[j].width - curRow[j].imgWidth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add some padding for inter-element spacing.
|
|
|
|
|
combinedPadding += 5 * curRow.length;
|
|
|
|
|
wantedWidth = maxWidth - combinedPadding;
|
|
|
|
|
preferredHeight = wantedWidth / combinedAspect;
|
|
|
|
|
|
|
|
|
|
if ( preferredHeight > curRowHeight * 1.5 ) {
|
|
|
|
|
// Only expand at most 1.5 times current size
|
|
|
|
|
// As that's as high a resolution as we have.
|
|
|
|
|
// Also on the off chance there is a bug in this
|
|
|
|
|
// code, would prevent accidentally expanding to
|
|
|
|
|
// be 10 billion pixels wide.
|
2013-08-21 17:00:47 +00:00
|
|
|
if ( i === rows.length - 1 ) {
|
|
|
|
|
// If its the last row, and we can't fit it,
|
|
|
|
|
// don't make the entire row huge.
|
|
|
|
|
avgZoom = ( totalZoom / ( rows.length - 1 ) ) * curRowHeight;
|
|
|
|
|
if ( isFinite( avgZoom ) && avgZoom >= 1 && avgZoom <= 1.5 ) {
|
|
|
|
|
preferredHeight = avgZoom;
|
|
|
|
|
} else {
|
|
|
|
|
// Probably a single row gallery
|
|
|
|
|
preferredHeight = curRowHeight;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
preferredHeight = 1.5 * curRowHeight;
|
|
|
|
|
}
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
}
|
|
|
|
|
if ( !isFinite( preferredHeight ) ) {
|
|
|
|
|
// This *definitely* should not happen.
|
|
|
|
|
// Skip this row.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ( preferredHeight < 5 ) {
|
|
|
|
|
// Well something clearly went wrong...
|
|
|
|
|
// Skip this row.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-08-21 17:00:47 +00:00
|
|
|
|
|
|
|
|
if ( preferredHeight / curRowHeight > 1 ) {
|
|
|
|
|
totalZoom += preferredHeight / curRowHeight;
|
|
|
|
|
} else {
|
|
|
|
|
// If we shrink, still consider that a zoom of 1
|
|
|
|
|
totalZoom += 1;
|
|
|
|
|
}
|
|
|
|
|
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
for ( j = 0; j < curRow.length; j++ ) {
|
|
|
|
|
newWidth = preferredHeight * curRow[j].aspect;
|
|
|
|
|
padding = curRow[j].width - curRow[j].imgWidth;
|
|
|
|
|
$outerDiv = curRow[j].$elm;
|
|
|
|
|
$innerDiv = $outerDiv.children( 'div' ).first();
|
|
|
|
|
$imageDiv = $innerDiv.children( 'div.thumb' );
|
|
|
|
|
$imageElm = $imageDiv.find( 'img' ).first();
|
|
|
|
|
imageElm = $imageElm.length ? $imageElm[0] : null;
|
|
|
|
|
$caption = $outerDiv.find( 'div.gallerytextwrapper' );
|
|
|
|
|
|
|
|
|
|
// Since we are going to re-adjust the height, the vertical
|
|
|
|
|
// centering margins need to be reset.
|
|
|
|
|
$imageDiv.children( 'div' ).css( 'margin', '0px auto' );
|
|
|
|
|
|
|
|
|
|
if ( newWidth < 60 || !isFinite( newWidth ) ) {
|
|
|
|
|
// Making something skinnier than this will mess up captions,
|
|
|
|
|
if ( newWidth < 1 || !isFinite( newWidth ) ) {
|
|
|
|
|
$innerDiv.height( preferredHeight );
|
|
|
|
|
// Don't even try and touch the image size if it could mean
|
|
|
|
|
// making it disappear.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$outerDiv.width( newWidth + padding );
|
|
|
|
|
$innerDiv.width( newWidth + padding );
|
|
|
|
|
$imageDiv.width( newWidth );
|
2014-01-21 20:49:07 +00:00
|
|
|
$caption.width( curRow[j].captionWidth + ( newWidth - curRow[j].imgWidth ) );
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
mediawiki.page.gallery.resize: Remove weird mw.hook call
This mw.hook has no place here, there's various things wrong
with it:
* Naming.
We don't prefix event names with "mediawiki" nor the module
name. This pattern does not exist and this being here makes
understanding mw.hook by example harder and only adds to the
confusion.
* Synchronous behaviour.
Aside from the naming (details..), mw.hook simply doesn't do
what the code is asking for here and exhibits behaviour the
gallery relies on to to happen.
By design, mw.hook is asynchronous and memorises the last call
for new event handlers to allow modifying the last version of a
particular interface. It's like document-ready, if you bind
after the document is already ready, it's just to declare it
needs the document to be ready. It's not for exactly when that
happened, just that it happens after.
* Plurality.
To make matters worse, aside from naming and asynchonisity,
the gallery is also calling it in a loop, which is another
violation of mw.hook's design. When something emits mw.hook,
it means any previous state is no longer active (e.g. the user
switched modes, or navigated to another page with AJAX, or
closed the relevant dialog, or opened another one etc.).
Also removed some mw.log calls that seems to be left from
development. If these are important during regular usage, it should
probably throw an exception or use mw.log.warn instead.
Change-Id: Iefdfab26fcd24e3f9f8f3f2fc7f1fdba9f838a25
2014-06-11 15:31:34 +00:00
|
|
|
if ( imageElm ) {
|
|
|
|
|
// We don't always have an img, e.g. in the case of an invalid file.
|
|
|
|
|
imageElm.width = newWidth;
|
|
|
|
|
imageElm.height = preferredHeight;
|
|
|
|
|
} else {
|
|
|
|
|
// Not a file box.
|
|
|
|
|
$imageDiv.height( preferredHeight );
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-13 18:53:28 +00:00
|
|
|
}() );
|
2015-01-04 07:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$( galleries ).each( justify );
|
|
|
|
|
$( window ).resize( $.debounce( 300, true, function () {
|
|
|
|
|
$( galleries ).children( 'li' ).each( function () {
|
|
|
|
|
var imgWidth = $( this ).data( 'imgWidth' ),
|
|
|
|
|
imgHeight = $( this ).data( 'imgHeight' ),
|
|
|
|
|
width = $( this ).data( 'width' ),
|
|
|
|
|
captionWidth = $( this ).data( 'captionWidth' ),
|
2015-01-09 21:59:51 +00:00
|
|
|
$innerDiv = $( this ).children( 'div' ).first(),
|
|
|
|
|
$imageDiv = $innerDiv.children( 'div.thumb' ),
|
2015-01-04 07:32:52 +00:00
|
|
|
$imageElm, imageElm;
|
|
|
|
|
|
|
|
|
|
// Restore original sizes so we can arrange the elements as on freshly loaded page
|
|
|
|
|
$( this ).width( width );
|
2015-01-09 21:59:51 +00:00
|
|
|
$innerDiv.width( width );
|
|
|
|
|
$imageDiv.width( imgWidth );
|
2015-01-04 07:32:52 +00:00
|
|
|
$( this ).find( 'div.gallerytextwrapper' ).width( captionWidth );
|
|
|
|
|
|
|
|
|
|
$imageElm = $( this ).find( 'img' ).first();
|
|
|
|
|
imageElm = $imageElm.length ? $imageElm[0] : null;
|
|
|
|
|
if ( imageElm ) {
|
|
|
|
|
imageElm.width = imgWidth;
|
|
|
|
|
imageElm.height = imgHeight;
|
2015-01-09 21:59:51 +00:00
|
|
|
} else {
|
|
|
|
|
$imageDiv.height( imgHeight );
|
2015-01-04 07:32:52 +00:00
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
} ) );
|
|
|
|
|
$( window ).resize( $.debounce( 300, function () {
|
|
|
|
|
$( galleries ).each( justify );
|
|
|
|
|
} ) );
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
} );
|
mediawiki.page.gallery.resize: Remove weird mw.hook call
This mw.hook has no place here, there's various things wrong
with it:
* Naming.
We don't prefix event names with "mediawiki" nor the module
name. This pattern does not exist and this being here makes
understanding mw.hook by example harder and only adds to the
confusion.
* Synchronous behaviour.
Aside from the naming (details..), mw.hook simply doesn't do
what the code is asking for here and exhibits behaviour the
gallery relies on to to happen.
By design, mw.hook is asynchronous and memorises the last call
for new event handlers to allow modifying the last version of a
particular interface. It's like document-ready, if you bind
after the document is already ready, it's just to declare it
needs the document to be ready. It's not for exactly when that
happened, just that it happens after.
* Plurality.
To make matters worse, aside from naming and asynchonisity,
the gallery is also calling it in a loop, which is another
violation of mw.hook's design. When something emits mw.hook,
it means any previous state is no longer active (e.g. the user
switched modes, or navigated to another page with AJAX, or
closed the relevant dialog, or opened another one etc.).
Also removed some mw.log calls that seems to be left from
development. If these are important during regular usage, it should
probably throw an exception or use mw.log.warn instead.
Change-Id: Iefdfab26fcd24e3f9f8f3f2fc7f1fdba9f838a25
2014-06-11 15:31:34 +00:00
|
|
|
}( jQuery ) );
|