User talk:Technical 13

From Wikisource
Latest comment: 9 years ago by George Orwell III in topic Console won't shut up
Jump to navigation Jump to search

Pitiful plea for help with jquery - javascript[edit]

I don't know where else to turn but here for some help in [re]developing some of our now-obsolete jquery scripting that affects a large portion of all main-space works for us.

Background. — At some point in the development history of en.WS, a feature called "Dynamic Layouts" was implemented for a certain type of main namespace works that, in short, auto [re]formats the content to render in 1 of 4 preset layouts. Since the specific type of content under the spell of Dynamic Layouts are those transcluded-in from another namespace, anything manually added in the main namespace -- like headers, footers, copyright disclaimers, authority control banners and similar entities much akin to Wikipedia's infobox usage -- are inadvertently auto-[re]formatted as well.

The "long-time fix" for this has been the below snippet applied from our Common.js; moving the containing DIV or TABLE holding the non-content related items "outside of" the influence of Dynamic Layouts before final rendering of the viewable main-space article takes place.

/**
 * Force license-tags & authority-control out of dynamic layouts.
 * See also ___
 */
jQuery( document ).ready( function ( $ ) {
	$( 'body.ns-0 div.licenseContainer' )
			.insertAfter( $ ( 'div.printfooter' ) );
	$( 'body.ns-0 table#authorityControl' )
			.insertBefore( $ ( 'div#catlinks' ) );
} );

The problem. — In the time since the above's inception, some of the "advancements" at en.WS have made it obsolete, if not crippled altogether. The new points resulting from those advancements that I need help with in coming up with a "new design" now are (specifically)...

  1. the need to expand the current affected/detected namespace for both "moves" from just the main namespace (body.ns-0 ) to include the Translation: namespace (body.ns-0, body.ns-114 ?)
  2. the need to tweak the first item moved to target the DIV with an id= attribute of licenseContainer instead of the current target -- a DIV with a class= attribute of licenseContainer (same) -- BUT ONLY when the new target container is not a child or descendant of a table cell <TD> element.

Any and all comments or help is greatly appreciated & welcomed in advance. -- George Orwell III (talk) 00:28, 20 January 2015 (UTC)Reply

  • Hi George.
/**
 * Force license-tags & authority-control out of dynamic layouts.
 * See also ___
 */
jQuery( document ).ready( function ( $ ) {
	var nsNumbers = [ 0, 114 ];
	if ( $.inArray( mw.config.get( 'wgNamespaceNumber' ), nsNumbers ) !== -1 ) {
		$( 'div#licenseContainer' ).insertAfter( $ ( 'div.printfooter' ) );
		$( 'table#authorityControl' ).insertBefore( $ ( 'div#catlinks' ) );
	}
} );
I think that is what you want. I added an array that will make it easy for you to add or remove namespaces this will work in and I changed looking for class to looking for id (# instead of .). Does that do what you want, do you need any more tweaks for it? Let me know. (ping me on IRC, I don't watch this wiki much). Happy coding! Technical 13 (talk) 20:36, 25 January 2015 (UTC)Reply
@Technical13:, Doh! A solution that I can actually grasp both at face-value and at it's core. One of those times where it makes perfect sense now that its done by someone else & right there in front me (admittedly, I should have come up with an array-like approach on y own and then just have somebody fix the syntax (or whatever).

Thank you very very Much :0.

But I'm going to hold you to your offer.

  • The 2nd move -= the ' insertBefore ' part =- is a-OK as it is.
  • The first move -= ' insertAfter ' part =- is fine as far as the target & results are concerned... BUT
I only need it to kick-in and "move" itself only in those instances where the DIV in question, with a current id= of licenseContainer is not a child-to or ancestor-of > nor is in any, way shape or form contained within < either a true table-cell element (<TD... /TD>) as well as one those new CSS3-ish faux table-cell (div style="display:table-cell; ... deals. My bad, I'm overly irritated and thus paranoid that such stupidty can only be a plot to drive me to drink, kill my neighbors.... yada, yada dadya.

To make life a billion times easier, I can assign the TD this little snippet needs to focus-on detecting its own unique id or class value as you direct (or basically any other element working backwards from the opening TD tag all the way up to after the closing TABLE tag --- the element where OF COURSE somebody thought it was a good idea to recycle/consolidate every previous incarnation and all the whot-nots in between into a single template family & [re]using the same moniker (licenseContainer) that we need to use from now on.

I'm kind busy this weekend but I'll hit Billinghurst up for another favor in the coming week if I can't break free before you do a another fly-by or somethin' Thanks again ., -- George Orwell III (talk) 00:12, 26 January 2015 (UTC)Reply

  • Ahh... I overlooked that part of your request.
/**
 * Force license-tags & authority-control out of dynamic layouts.
 * See also ___
 */
jQuery( document ).ready( function ( $ ) {
	var nsNumbers = [ 0, 114 ];
	if ( $.inArray( mw.config.get( 'wgNamespaceNumber' ), nsNumbers ) !== -1 ) {
		if ( $( 'div#licenseContainer' ).closest( 'td' ) === undefined &&
			$( 'div#licenseContainer' ).find( 'td' ) === undefined
		) {
			$( 'div#licenseContainer' ).insertAfter( $ ( 'div.printfooter' ) );
		}
		$( 'table#authorityControl' ).insertBefore( $ ( 'div#catlinks' ) );
	}
} );
Should do it as closest goes up the tree and find goes down. If there is no TD above or below, then process. Is TD the best thing to look for though? Wouldn't it be easier to just look up the tree if there is a TABLE? — {{U|Technical 13}} (etc) 16:05, 26 January 2015 (UTC)Reply
Hmmm.... that's a new one for me. I'll have to read up on it when I get some time.

That's the other thing about this nonsense. I ported over to what amounted to a bunch of single table-row with 2 or 3 table cells per row license banners to use div-column or faux-table divs whenever I could but there where still some intricate licenses that I left alone as well as some works here with up to 5 licenses covering translations, multiple authors, dual-editors, illustrators etc. etc. These are then placed in another Christmas tree-like HTML table which I figure best to leave as is - the caveat again - even these 'gun rack of licenses' can use the familiar licenseContainer label.

I have instances where a "tree" of licenses are "pretending" as if they were a single license banner like those applied for a short story or something too. Its one big unorganized mess when it comes to this nuance that shouldn't have to be that way. Over time, doing this will go a long way in exposing the remaining oddities. At some point afterwards, I can safely go about re-labeling one type or the other and then completely fork one class out from underneath another too. So in the end - your solution to look both before/up or after/down to make sure it's not a child decedent was a good idea for our purposes.

I'll plug it in as soon as I get free again -- 3 feet of snow predicted here :( -- George Orwell III (talk) 23:08, 26 January 2015 (UTC)Reply

┌─────────┘
As usual, my horrific track record with 'all things scripted' like this kicked-in so your last effort failed to produce a result; never mind the desired one (nothing happened afaict). You did manage to get my curiosity up re: === undefined etc. enough so that I just had to go read up on whatever I could find on it -- which, in turn, eventually led me to a solution (a damn good one) after getting side-tracked over & over again from what I originally set out to research upon coming across some new factoid or interesting link.

/**
 * Force license-tags & authority-control out of dynamic layouts.
 * See also ___
 */
jQuery( document ).ready( function ( $ ) {
	var nsNumbers = [ 0, 114 ];
	if ( $.inArray( mw.config.get( 'wgNamespaceNumber' ), nsNumbers ) !== -1 ) {
		$( 'div.licenseContainer' ).not( 'div.licenseContainer div.licenseContainer' ).insertAfter( $( 'div.printfooter' ) ); 
		$( 'table#authorityControl' ).insertBefore( $ ( 'div#catlinks' ) );
	}
} );

That's it.

Kind of unbelievable huh?

My thanks once again - it was your insight and effort that made it possible for me to work through the issue by putting me on the right path -- as well the right mindset.

I've got about a half-a-dozen or so other scripting issues on my "to-do" list for en.WS from (yikes!) 2011 on, if you're interested and can spare the time. If not; I understand & we'll "part ways" here; Prost!...
but if that's not a problem for you, I'll summarize an issue w/history and the like in a new section below ⇒ you/we can get to it at your leisure or however your meat-space schedule dictates. -- George Orwell III (talk) 11:00, 27 January 2015 (UTC)Reply

  • George, that's odd. The documentation on all of the traversal stuff is on http://api.jquery.com/category/traversing/ and your .not() is especially specific and redundant. It says only insertAfter if a div with a class of licenseContainer is not a div with a class of licenseContainer that is a div with a class of licenseContainer. That's how it reads. The end result should be it is never insertedAfter. Anyways, if you think it works, that's great and I'm glad I could be of some help. — {{U|Technical 13}} (etc) 14:29, 27 January 2015 (UTC)Reply
    I dunno seems right to me..
  • jQuery( 'ancestor descendant' ) = jQuery( 'ancestor: Any valid selector. descendant: A selector to filter the descendant elements.' ) noting the hash mark use
  • .not() = .not(selector)
You see, the crux of the problem was that @ the time of the moves, the "Christmas tree" container holding one or more banners resulted in a.) the moving of the banners out of the tree so they were now in effect stand-alones again; and b.) then the empty tree was moved as well. But realize that a true container can hold >> 1 << or more license banners (in short: a 2 banner minimum should have been the requirement to use a "true" container; didn't happen). So since a container could hold as few as just one banner, there was little to dissuade people from consolidating one approach with the other... and another... and another until there was but a single way of doing things and all the templates changes to support "that way". When that 'one way' mentality eventually ran into one roadblock or the other later on, the labeling for class and id were sacrificed to resolve the matter at hand so those also became, in effect, faux singularities too.

Am I crazy or do you not see the blue-toned license boxes (or box) under the green footer field near the very bottom of ..
* Manifesto_of_the_Communist_Party (true container use; a translation); and
* Constitution_of_the_United_States_of_America
I'm sure you do @Technical 13:... so it must be 'correct' jQuery-wise no? (cause I'm the type to break it again just to be spec compliant) -- George Orwell III (talk) 15:33, 27 January 2015 (UTC)Reply

Good. Now can you tell me... George Orwell III (talk) 17:44, 27 January 2015 (UTC)Reply

Console won't shut up[edit]

Can you tell me wtf is going on in the first 2? Going by the 2nd one - the problem(s) are in MediaWiki:PageNumbers.js (another troublemaker for me) but I can't wrap my head what is wrong exactly. To the best of my eyesight mw.config.get is being used...

Use of "wgNamespaceNumber" is deprecated. Use mw.config instead.
console.trace()
   at log.warn (https://bits.wikimedia.org/en.wikisource.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150113T190609Z:154:581)
   at $j.get (https://bits.wikimedia.org/en.wikisource.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150113T190609Z:154:871)
   at Anonymous function (eval code:93:30) at fire (https://bits.wikimedia.org/en.wikisource.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150113T190609Z:45:103)
   at self.add (https://bits.wikimedia.org/en.wikisource.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150113T190609Z:45:664)
   at jQuery.fn.ready (https://bits.wikimedia.org/en.wikisource.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150113T190609Z:49:40)
   at Anonymous function (eval code:93:1)
   at runScript (https://bits.wikimedia.org/en

2/1/2015 UPDATE:

Either the above, the below or both will come up on pages like...

* Above was caused by bad line in MediaWiki:Gadget-addViafData.js‎
* In the MediaWiki:PageNumbers.js below, the full string needed to be enclosed in parenthesis with hash marks ( 'self.proofreadpage_source_href' ) in order to be detected properly.
Use of "proofreadpage_source_href" is deprecated. Use mw.config instead.
console.trace()
   at log.warn (https://bits.wikimedia.org/en.wikisource.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150113T190609Z:154:581)
   at $j.get (https://bits.wikimedia.org/en.wikisource.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150113T190609Z:154:871)
   at set_by_name (https://en.wikisource.org/w/index.php?title=MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript:58:3)
   at init (https://en.wikisource.org/w/index.php?title=MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript:88:4)
   at Anonymous function (https://bits.wikimedia.org/en.wikisource.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150113T190609Z:47:109)
   at fire (https://bits.wikimedia.org/en.wikisource.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150113T190609Z:45:103)
   at self.add (https://bits.wikimedia.org/en.wikisourc

.

DOM7009: Unable to decode image at URL: 'https://meta.wikimedia.org/wiki/Special:RecordImpression
?country=US
&uselang=en
&project=wikisource
&db=enwikisource
&anonymous=false
&device=desktop
&reason=empty
&result=hide'.
File: Special:RecordImpression

This above seems to be the Fund Raising banner blocker gadget -- its not completely stopping the scraping of other info?

Any pointers are greatly appreciated. -- George Orwell III (talk) 17:44, 27 January 2015 (UTC)Reply

  • I only see "proofreadpage_source_href" issues coming up, and it's not an element I've worked with before and have no idea where it comes from... It doesn't show up in a search of everything on MW: either, so I've no idea. I don't see the "wgNamespaceNumber" error. I see a little MW:CC/JS work could be done, but don't see anything that would break it. I do see a couple of mw.loader calls at the bottom and wonder if it is inheriting these issues from those. — {{U|Technical 13}} (etc) 00:02, 28 January 2015 (UTC)Reply
    proofreadpage_source_href. -- Let me introduced you two. Go back to the above linked page(s). Even in vector, you should see a new tab along the top between Page and Talk labeled Source. Anytime something is transcluded-in from the Page: namespace to the main namespace - that tab should be generated & link back to the Index: namespace (where the [re]page numbering and [re]labeling of ranges etc. for the Page: namespace is done).

    Its that source tab generation that was once used(?) as the indication the extension was loaded (or a simple check for its existence?). The whole extension is a galactic pain in the azz (who checks to see if the extension's "done" by searching for something like that?). -- George Orwell III (talk) 00:45, 28 January 2015 (UTC)Reply