MediaWiki:Bracket.js

bracket={bracketClass:".bracketpage",templateName:"Bracket",bracketPageName:"Bracket:",editSummary:"Submitting my bracket entry.",genericErrorMessage:"An error occurred. Please try again.",bracketPages:["Wookieepedia_Contests:Create_your_Bracket"],articleTitle:"Wookieepedia_Contests:Predict_the_Madness",articleID:"2173",submittedMessage:"Your+bracket+has+been+successfully+submitted.",editMessage:"Your+bracket+has+been+successfully+edited.+Click+here+to+view+it.",bracketItems:{"left-2-1":{first:{name:"R2-D2",image:"http://img1.wikia.nocookie.net/swfans/images/f/ff/Bracket_R2-D2_Large.png",readmore:"http://starwars.wikia.com/wiki/R2-D2/Canon",template:"left-1-1"},second:{name:"Rebels Play-in",image:"http://img4.wikia.nocookie.net/swfans/images/c/cb/Bracket_Rebels_Play-in_Large.png",readmore:"",template:"left-1-2"},next:"left-2-2",votefor:"left-3-1"},"left-2-2":{first:{name:"Princess Leia",image:"http://img4.wikia.nocookie.net/swfans/images/1/14/Bracket_Leia_Organa_Solo_Large.png",readmore:"http://starwars.wikia.com/wiki/Leia_Organa",template:"left-1-3"},second:{name:"Hera Syndulla",image:"http://vignette1.wikia.nocookie.net/swfans/images/1/16/Bracket_Hera_Syndulla_Large.png/revision/latest?cb=20150309172648",readmore:"http://starwars.wikia.com/wiki/Hera_Syndulla",template:"left-1-4"},next:"left-2-3",prev:"left-2-1",votefor:"left-3-1"},"left-2-3":{first:{name:"Obi-Wan Kenobi",image:"http://img2.wikia.nocookie.net/swfans/images/6/62/Bracket_Obi-Wan_Kenobi_Large.png",readmore:"http://starwars.wikia.com/wiki/Obi-Wan_Kenobi/Canon",template:"left-1-5"},second:{name:"Jedi Play-in",image:"http://img1.wikia.nocookie.net/swfans/images/d/de/Bracket_Jedi_Play-in_Large.png",readmore:"",template:"left-1-6"},next:"left-2-4",prev:"left-2-2",votefor:"left-3-2"},"left-2-4":{first:{name:"Yoda",image:"http://img2.wikia.nocookie.net/swfans/images/4/43/Bracket_Yoda_Large.png",readmore:"http://starwars.wikia.com/wiki/Yoda/Canon",template:"left-1-7"},second:{name:"Qui-Gon Jinn",image:"http://img4.wikia.nocookie.net/swfans/images/0/0a/Bracket_Qui-Gon_Jinn_Large.png",readmore:"http://starwars.wikia.com/wiki/Qui-Gon_Jinn/Canon",template:"left-1-8"},next:"left-2-5",prev:"left-2-3",votefor:"left-3-2"},"left-2-5":{first:{name:"Chewbacca",image:"http://img3.wikia.nocookie.net/swfans/images/3/37/Bracket_Chewbacca_Large.png",readmore:"http://starwars.wikia.com/wiki/Chewbacca/Canon",template:"left-1-9"},second:{name:"Zeb Orrelios",image:"http://vignette3.wikia.nocookie.net/swfans/images/8/87/Bracket_Zeb_Orrelios_Large.png/revision/latest?cb=20150309173507",readmore:"http://starwars.wikia.com/wiki/Garazeb_Orrelios",template:"left-1-10"},next:"left-2-6",prev:"right-2-4",votefor:"left-3-3"},"left-2-6":{first:{name:"Han Solo",image:"http://img2.wikia.nocookie.net/swfans/images/b/be/Bracket_Han_Solo_Large.png",readmore:"http://starwars.wikia.com/wiki/Han_Solo/Canon",template:"left-1-11"},second:{name:"Lando Calrissian",image:"http://img1.wikia.nocookie.net/swfans/images/8/87/Bracket_Lando_Calrissian_Large.png",readmore:"http://starwars.wikia.com/wiki/Lando_Calrissian/Canon",template:"left-1-12"},next:"left-2-7",prev:"right-2-5",votefor:"left-3-3"},"left-2-7":{first:{name:"Padmé Amidala",image:"http://img2.wikia.nocookie.net/swfans/images/0/0f/Bracket_Padmé_Amidala_Large.png",readmore:"http://starwars.wikia.com/wiki/Padmé_Amidala/Canon",template:"left-1-13"},second:{name:"Jar Jar Binks",image:"http://vignette2.wikia.nocookie.net/swfans/images/1/14/Bracket_Jar_Jar_Binks_Large.png/revision/latest?cb=20150309173910",readmore:"http://starwars.wikia.com/wiki/Jar_Jar_Binks/Canon",template:"left-1-14"},next:"left-2-8",prev:"right-2-6",votefor:"left-3-4"},"left-2-8":{first:{name:"Captain Rex",image:"http://img2.wikia.nocookie.net/swfans/images/f/f2/Bracket_Rex_Large.png",readmore:"http://starwars.wikia.com/wiki/CT-7567",template:"left-1-15"},second:{name:"Gregor",image:"http://vignette4.wikia.nocookie.net/swfans/images/6/61/Bracket_Gregor_Large.png/revision/latest?cb=20150309174212",readmore:"http://starwars.wikia.com/wiki/CC-5576-39",template:"left-1-16"},next:"right-2-1",prev:"left-2-7",votefor:"left-3-4"},"right-2-1":{first:{name:"Tarkin",image:"http://img1.wikia.nocookie.net/swfans/images/d/d4/Bracket_Wilhuff_Tarkin_Large.png",readmore:"http://starwars.wikia.com/wiki/Wilhuff_Tarkin/Canon",template:"right-1-1"},second:{name:"Empire and Seperatist Play-in",image:"http://img2.wikia.nocookie.net/swfans/images/e/e7/Bracket_Empire_Play-in_Large.png",readmore:"",template:"right-1-2"},next:"right-2-2",prev:"left-2-8",votefor:"right-3-1"},"right-2-2":{first:{name:"General Grievous",image:"http://img1.wikia.nocookie.net/swfans/images/8/88/Bracket_Grievous_Large.png",readmore:"http://starwars.wikia.com/wiki/Grievous/Canon",template:"right-1-3"},second:{name:"The Inquisitor",image:"http://vignette3.wikia.nocookie.net/swfans/images/a/a5/Bracket_The_Inquisitor_Large.png/revision/latest?cb=20150309174538",readmore:"http://starwars.wikia.com/wiki/The_Inquisitor",template:"right-1-4"},next:"right-2-3",prev:"right-2-1",votefor:"right-3-1"},"right-2-3":{first:{name:"Boba Fett",image:"http://img2.wikia.nocookie.net/swfans/images/f/f4/Bracket_Boba_Fett_Large.png",readmore:"http://starwars.wikia.com/wiki/Boba_Fett/Canon",template:"right-1-5"},second:{name:"Bounty Hunter Play-in",image:"http://img2.wikia.nocookie.net/swfans/images/c/c9/Bracket_Bounty_Hunter_Play-in_Large.png",readmore:"",template:"right-1-6"},next:"right-2-4",prev:"right-2-2",votefor:"right-3-2"},"right-2-4":{first:{name:"Jango Fett",image:"http://img3.wikia.nocookie.net/swfans/images/b/bc/Bracket_Jango_Fett_Large.png",readmore:"http://starwars.wikia.com/wiki/Jango_Fett/Canon",template:"right-1-7"},second:{name:"Greedo",image:"http://img2.wikia.nocookie.net/swfans/images/5/55/Bracket_Greedo_Large.png",readmore:"http://starwars.wikia.com/wiki/Greedo/Canon",template:"right-1-8"},next:"right-2-5",prev:"right-2-3",votefor:"right-3-2"},"right-2-5":{first:{name:"Darth Vader",image:"http://img3.wikia.nocookie.net/swfans/images/c/c1/Bracket_Darth_Vader_Large.png",readmore:"http://starwars.wikia.com/wiki/Anakin_Skywalker/Canon",template:"right-1-9"},second:{name:"Count Dooku",image:"http://img2.wikia.nocookie.net/swfans/images/e/ed/Bracket_Dooku_Large.png",readmore:"http://starwars.wikia.com/wiki/Dooku/Canon",template:"right-1-10"},next:"right-2-6",prev:"right-2-4",votefor:"right-3-3"},"right-2-6":{first:{name:"Emperor Palpatine",image:"http://img3.wikia.nocookie.net/swfans/images/3/3b/Bracket_Darth_Sidious_Large.png",readmore:"http://starwars.wikia.com/wiki/Darth_Sidious",template:"right-1-11"},second:{name:"Darth Maul",image:"http://img3.wikia.nocookie.net/swfans/images/5/57/Bracket_Darth_Maul_Large.png",readmore:"http://starwars.wikia.com/wiki/Darth_Maul/Canon",template:"right-1-12"},next:"right-2-7",prev:"right-2-5",votefor:"right-3-3"},"right-2-7":{first:{name:"Jabba the Hutt",image:"http://img3.wikia.nocookie.net/swfans/images/c/c9/Bracket_Jabba_the_Hutt_Large.png",readmore:"http://starwars.wikia.com/wiki/Jabba",template:"right-1-13"},second:{name:"Bib Fortuna",image:"http://vignette2.wikia.nocookie.net/swfans/images/4/42/Bracket_Bib_Fortuna_Large.png/revision/latest?cb=20150309175122",readmore:"http://starwars.wikia.com/wiki/Bib_Fortuna/Canon",template:"right-1-14"},next:"right-2-8",prev:"right-2-6",votefor:"right-3-4"},"right-2-8":{first:{name:"Pre Vizsla",image:"http://img2.wikia.nocookie.net/swfans/images/e/eb/Bracket_Pre_Vizsla_Large.png",readmore:"http://starwars.wikia.com/wiki/Pre_Vizsla",template:"right-1-15"},second:{name:"Hondo Ohnaka",image:"http://img2.wikia.nocookie.net/swfans/images/0/09/Bracket_Hondo_Ohnaka_Large.png",readmore:"http://starwars.wikia.com/wiki/Hondo_Ohnaka",template:"right-1-16"},next:"left-3-1",prev:"right-2-7",votefor:"right-3-4"},"left-3-1":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"left-3-2",prev:"right-2-8",votefor:"left-4-1"},"left-3-2":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"left-3-3",prev:"left-3-1",votefor:"left-4-1"},"left-3-3":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"left-3-4",prev:"left-3-2",votefor:"left-4-2"},"left-3-4":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"right-3-1",prev:"left-3-3",votefor:"left-4-2"},"right-3-1":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"right-3-2",prev:"left-3-4",votefor:"right-4-1"},"right-3-2":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"right-3-3",prev:"right-3-1",votefor:"right-4-1"},"right-3-3":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"right-3-4",prev:"right-3-2",votefor:"right-4-2"},"right-3-4":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"left-4-1",prev:"right-3-3",votefor:"right-4-2"},"left-4-1":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"left-4-2",prev:"right-3-4",votefor:"left-5-1"},"left-4-2":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"right-4-1",prev:"left-4-1",votefor:"left-5-1"},"right-4-1":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"right-4-2",prev:"left-4-2",votefor:"right-5-1"},"right-4-2":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"left-5-1",prev:"right-4-1",votefor:"right-5-1"},"left-5-1":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"right-5-1",prev:"right-4-2",votefor:"winner",last:1},"right-5-1":{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},next:"winner",prev:"left-5-1",votefor:"winner",last:1},winner:{first:{name:"",image:"",readmore:""},second:{name:"",image:"",readmore:""},prev:"right-5-1"}},template:{},disablePrevNext:0,userName:"",skin:"",votesLeft:"0",init:function{if("undefined"!=typeof skin)this.skin=skin,this.userName=wgUserName;else{this.skin="mercury",this.userName="";var e=this.bracketPages[0]}return this.userName?(this.handleNotification,this.handleTutorial,this.createBracket,this.styleBracket,this.prepBracket,this.updateVotesLeft,void 0):($(this.bracketClass).append(' Oops! It seems you\'re not logged in! Please log in or create an account before creating your bracket. '),0)},handleNotification:function{var e=this.getParameterByName("bracketSubmit").replace(/<[^>]*>?/g,""),t=this.getParameterByName("bracketLink").replace(/<[^>]*>?/g,"");""!=e&&$(".global-navigation").after('  '+e+" ")},handleTutorial:function{"wikiamobile"!=skin&&"mercury"!=skin?$(".bracket-header").append('Click on the portrait of the character you think will win. Remaining votes: 0 .'):($("html, body").animate({scrollTop:$(this.bracketClass).offset.top},0),$("body").prepend(' Choose the character you think will win! Swipe up to vote on the top character. Swipe down to vote on the bottom character. Swipe left to view your previous choice. Swipe right to move on to the next vote after voting. Tap to continue and start voting. '),$("body").prepend(' '))},createBracket:function{var e=this,t=0,a=0;$.each(this.bracketItems,function(i,r){t++,e.votesLeft++;var n=2;"right"!=e.getLevelPart(i,0)||a||(a=1,t=1),(t%2||1==t)&&(n=1);var s=$(' '),o=' ';s.append(o);var m=' ';s.append(m),$(e.bracketClass).append(s),2==e.getLevelPart(i,1)&&(e.updateTemplate(r.first.template,r.first.name),e.updateTemplate(r.second.template,r.second.name))})},styleBracket:function{var e=this,t=0;$(".item",this.bracketClass).each(function{if(1>=t){var a=$(this).attr("data-level");$(e.bracketClass).attr("data-current",a)}else $(this).css("display","none");$(".entrant",this).each(function{var e=$(this).attr("data-name"),a=$(this).attr("data-image"),i=$(this).attr("data-readmore");$(this).append(i?' '+e+' <img class="readmore-image" src="http://vignette2.wikia.nocookie.net/swfans/images/e/e2/Icon_info.png/revision/latest?cb=20150309140752"></a> ':' '+e+" "),$(this).append(' <img src="'+a+'" alt="'+e+'"> '),t++})}),$(this.bracketClass).append('  Submit <img style="display:none;" class="loader" src="http://slot1.images.wikia.nocookie.net/common/skins/common/images/ajax.gif" alt="Loading..."> '),$(this.bracketClass).append(' <img src="http://vignette2.wikia.nocookie.net/swfans/images/b/b2/Arrow_left.png/revision/latest?cb=20150309170340"> <img src="http://vignette3.wikia.nocookie.net/swfans/images/4/4a/Arrow_right.png/revision/latest?cb=20150309170341"> ')},prepBracket:function{var e=this,t=0;$("body").on("click",function{t||(t=1,$(".overlay").remove,$(".overlaytext").remove)}),$(".entrant",this.bracketClass).on("click",function{if(1!=e.disablePrevNext){e.disablePrevNext=1;var t=$(this).attr("data-number");e.vote(this,t)}}).children.find(".readmore-image").on("click",function(e){e.stopPropagation}),$(".prev",this.bracketClass).on("click",function{1!=e.disablePrevNext&&(e.disablePrevNext=1,e.prev)}),$(".next",this.bracketClass).on("click",function{1!=e.disablePrevNext&&(e.disablePrevNext=1,e.next)}),$(".button",this.bracketClass).on("click",function{e.finish}),("wikiamobile"==this.skin||"mercury"==this.skin)&&$("body").touchwipe({wipeUp:function{var t=$(e.bracketClass).attr("data-current"),a=$('.item[data-level="'+t+'"] .right'),i=a.attr("data-number");e.vote(a,i,0)},wipeDown:function{var t=$(e.bracketClass).attr("data-current"),a=$('.item[data-level="'+t+'"] .left'),i=a.attr("data-number");e.vote(a,i,0)},wipeLeft:function{e.prev},wipeRight:function{e.next},min_move_x:75,min_move_y:75,preventDefaultEvents:!0})},vote:function(e,t,a){var i=$(e).parent.attr("data-level"),r=$(e).attr("data-name"),n=$(e).attr("data-image"),s=$(e).attr("data-readmore"),t=$(e).attr("data-number"),o=$(e).attr("data-votefor");if($(this.bracketClass+' .item[data-level="'+i+'"] .active').removeClass("active"),$(e).addClass("active"),"undefined"==typeof a&&(a=1),this.updateTemplate(i,r),1==t)var m=" .left";else var m=" .right";var c="";if("undefined"!=typeof this.bracketItems[i].last)c=this.bracketClass+' .item[data-level="winner"]'+m;else{var l=parseInt(this.getLevelPart(i,1))+1,g=this.getLevelPart(i,2);2==t&&(g=parseInt(g)-1);{this.getLevelPart(i,0)+"-"+l+"-"+g}c=this.bracketClass+' .item[data-level="'+o+'"]'+m}$(e).parent.attr("data-voted",1),"winner"!=i&&($(c).attr("data-name",r),$(c).attr("data-image",n),$(c).attr("data-readmore",s),this.updateElement(c,r,n,s)),a&&this.next},next:function{var e=this,t=$(this.bracketClass).attr("data-current"),a=this.bracketClass+' .item[data-level="'+t+'"]',i="";"confirm"!=t&&(i=this.getNextLevel(t));var r=$(a).attr("data-voted"),n=this.bracketClass+' .item[data-level="'+i+'"]';return"winner"==t&&(n=this.bracketClass+" .confirm",i="confirm"),"undefined"!=typeof i&&i&&1==r?($(this.bracketClass).attr("data-current",i),this.votesLeft--,this.updateVotesLeft,void $(a).fadeOut("slow",function{$(n).fadeIn("slow",function{e.disablePrevNext=0})})):(e.disablePrevNext=0,0)},prev:function{var e=this,t=$(this.bracketClass).attr("data-current"),a=this.bracketClass+' .item[data-level="'+t+'"]',i="";if(i="confirm"==t?"winner":this.getPrevLevel(t),"undefined"==typeof i||!i)return e.disablePrevNext=0,0;var r=this.bracketClass+' .item[data-level="'+i+'"]';console.log(a),$(this.bracketClass).attr("data-current",i),this.votesLeft++,this.updateVotesLeft,$(a).fadeOut("slow",function{$(r).fadeIn("slow",function{e.disablePrevNext=0})})},updateVotesLeft:function{var e=this.votesLeft;$(".bracket-header .remainingvotes").text(e)},finish:function{var e="";$.each(this.template,function(e,a){t+=" |"+e+" = "+a});var i=e+""+t+" "+a+" ";this.submit(i)},submit:function(e){var t=this;$(".button",this.bracketClass).attr("disabled","disabled");var a=this.bracketPageName+""+this.userName,i=this.editSummary+" ("+this.skin+")",r=this.genericErrorMessage,n=this.articleID,s=this.articleTitle,o=this.submittedMessage,m=this.editMessage;t.callAPI({action:"query",prop:"info|revisions",intoken:"edit",titles:a,rvprop:"content",rvlimit:"1"},"GET",function(c){var l=c.query.pages,g=null;for(var d in l)g=l[d];""==g.missing?t.callAPI({minor:"yes",summary:i,action:"edit",title:a,startimestamp:g.starttimestamp,token:g.edittoken,watchlist:"unwatch",text:e},"POST",function(e){"Success"==e.edit.result?$.ajax({url:"index.php",type:"POST",data:"action=ajax&article="+n+"&convertToFormat=&method=axPost&rs=ArticleCommentsAjax&title="+s+"&wpArticleComment="}).done(function(e){$(".loader",t.bracketClass).css("display","none");var i=e.text.toString,r=/comm-([0-9]+)/g,n=r.exec(i),m="#comm-text-";("undefined"==typeof skin||"wikiamobile"==skin)&&(m="#"),window.location.replace(wgServer+"/wiki/"+s+"?useskin=oasis&bracketSubmit="+o+"&bracketLink="+a+m+n[1])}):($(".loader",t.bracketClass).css("display","none"),$(".result",t.bracketClass).text(r),$(".button",t.bracketClass).removeAttr("disabled"))}):t.callAPI({minor:"yes",summary:i,action:"edit",title:a,basetimestamp:g.revisions[0].timestamp,startimestamp:g.starttimestamp,token:g.edittoken,watchlist:"unwatch",text:e},"POST",function(e){"Success"==e.edit.result?($(".loader",t.bracketClass).css("display","inline"),window.location.replace(wgServer+"/wiki/"+s+"?useskin=oasis&bracketSubmit="+m+"&bracketLink="+a)):($(".loader",t.bracketClass).css("display","none"),$(".result",t.bracketClass).text(r),$(".button",t.bracketClass).removeAttr("disabled"))})})},callAPI:function(e,t,a){e.format="json",$.ajax({data:e,dataType:"json",url:wgScriptPath+"/api.php",type:t,success:function(e){e.error?console.log("API error: "+e.error.info):a(e)},error:function(e,t){console.log("AJAX error: "+t)},timeout:1e4})},updateElement:function(e,t,a,i){$(".header",e).text(t),$(".readmore a",e).attr("href",i),$(".image img",e).attr("alt",t),$(".image img",e).attr("src",a)},getLevelPart:function(e,t){return e.split("-")[t]},getNextLevel:function(e){return this.bracketItems[e].next},getPrevLevel:function(e){return this.bracketItems[e].prev},updateTemplate:function(e,t){this.template[e]=t},getParameterByName:function(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)"),a=t.exec(location.search);return null==a?"":decodeURIComponent(a[1].replace(/\+/g," "))}},$(function{bracket.init});