Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

"lazy load" CSS #78

Merged
merged 1 commit into from Oct 6, 2016
Merged

"lazy load" CSS #78

merged 1 commit into from Oct 6, 2016

Conversation

WMDE-Fisch
Copy link
Contributor

@WMDE-Fisch WMDE-Fisch commented Oct 5, 2016

moved CSS for hint-boxes and throbbers to separate files
corresponding CSS will only be loaded if really needed

see https://phabricator.wikimedia.org/T144168

+ '<img id="deepcat-smallhint-hide" title="' + mw.msg( 'deepcat-smallhint-close' ) + '" src="https://upload.wikimedia.org/wikipedia/commons/4/44/Curation_bar_icon_close.png">'
+ mw.msg( 'deepcat-hintbox-small' )
+ '</div>';
$( '#searchform' ).after( smallHintBox );
$( '#deepcat-smallhint-hide' ).on( 'click', hideSmallHint );
}

function loadHintCodeIfNeeded() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good function name. It seems it does more than "loading code". See the add… calls below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -1,19 +1,8 @@
/**
* DeepCat Gadget for MediaWiki
* @licence GNU GPL v2+
* @author Christoph Fischer < christoph.fischer@wikimedia.de >
* @author Christoph Jauera < christoph.jauera@wikimedia.de >
Copy link
Contributor

@thiemowmde thiemowmde Oct 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name change should be a separate patch, but this is not critical.

👍 overall, looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Will do it in an other patch :-)

@WMDE-Fisch
Copy link
Contributor Author

/me pokes @manicki or @jakob-WMDE to have a 2nd look on this PR

Copy link
Member

@manicki manicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a very quick look. Mostly old man nagging about function names. Please consider if my comment on CSS paths is relevant here, though.

I'll have another look on the patch today and will then verify it is actually working. Generally looking fine for me, we might be able to have this merged today!

hintCodeLoaded = true;
}

function loadThrobberCodeIfNeeded() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code seems a bit mysterious, then I check what it does, and it load styles. Maybe loadThrobberStyles or loadThrobberResources? I am not sure if I'd put the "IfNeeded" part to the method names but it might be just matter of taste, I am not saying you should change it one way or another.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point will change that

+ '<img id="deepcat-smallhint-hide" title="' + mw.msg( 'deepcat-smallhint-close' ) + '" src="https://upload.wikimedia.org/wikipedia/commons/4/44/Curation_bar_icon_close.png">'
+ mw.msg( 'deepcat-hintbox-small' )
+ '</div>';
$( '#searchform' ).after( smallHintBox );
$( '#deepcat-smallhint-hide' ).on( 'click', hideSmallHint );
}

function initializeHintCodeIfNeeded() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On first glimpse at the code I am really confused what "hint code" is.

Looking at the method what it does, it loads css styles and adds some HTML elements. That's OK but which of those two is the actual "code"? Or is the "hint code" something different hidden somewhere deeper?
Wouldn't initializeHintBoxes(IfNeeded)? sound more clear in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point will change that as well :-)

if( hintCodeLoaded ) {
return;
}
mw.loader.load( cssPath + 'DeepCat.hintbox.css&action=raw&ctype=text/css', 'text/css' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to put those CSS paths in some config-like variable (on top of the file or so), so it is easier to customize and paths are not hidden somewhere deep in private methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atm the path is in a config-like var at the top of the file :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bah, yeah. What I probably meant was having full paths (i.e. including filename) as config variables. But this indeed might not be necessary. Unless we believe it is likely to want to have those CSS files named different when gadget is copied over to some other place or whatever other evil things happens. But shortly: right, it is fine as it is now!

moved CSS for hint-boxes and throbbers to separate files
corrosponding CSS will only be loaded if really needed
@manicki
Copy link
Member

manicki commented Oct 6, 2016

Looks good to me now!
Just spotted no newline at the end of the new throbber CSS file but I am not going to block this PR on such thing.

@manicki manicki merged commit b2a80dd into master Oct 6, 2016
@manicki manicki deleted the lazy-load-css branch October 6, 2016 14:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
3 participants