MediaWiki:UploadForm.js/Upload.js

var ufInput = { type: [], game: [], subject: [], description: "", source: "", holder: "", license: [] };

//Generates section HTML. function ufSection(header, description, content) { "use strict"; var temp = "" + header + " "; if (description !== undefined) { temp += description; }   if (content !== undefined) { temp += "" + content + " "; }   return temp; }

//Generates button HTML. function ufButton(data, purpose) { "use strict"; var temp = "<div class=\"uf-button\" onclick=\"ufSelect(this,";   var valid = true;    //Checks for problems. Will be likely be made more useful later.    switch (purpose) {        case "type":            break;        case "game":            break;        case "subject":            break;        case "license":            break;        case "source":            //Reserved for later.            break;        default:            temp = "Error!";            valid = false;            break;    }    if (valid) {        temp += purpose + "," + data.category + ");\" title=\"" + data.description + "\">" + data.name + " "; }   return temp; }

//Generates expanding button html. function ufMoreButton(name, description, data, purpose) { "use strict"; return "" + "" + name + " " + "&larr; " + name + " " + ufButtons(data, purpose) + " "; } function ufButtons(data, purpose) { "use strict"; var returnData = ""; for (var prop in data) { if (data[prop].more === true) { returnData += ufMoreButton(data[prop].name, data[prop].description, data[prop].list, purpose); }       else { returnData += ufButton(data[prop], purpose); }   }    return returnData; }

function ufTextArea(id, placeholder) { "use strict"; return " "; }

function ufExpand(sender) { "use strict"; $(sender).parent.parent.children.toggleClass("uf-hide"); $(sender).parent.toggleClass("uf-hide"); $(sender).parent.children.toggleClass("uf-hide"); }

function ufSelect(sender) { "use strict"; //Stores expander buttons that navigate to the selected button. var ancestorButtons = []; //Checks if sender is within an expander button. if ($(sender).parent.parent.hasClass("uf-more-buttons")) { //Grab first expander ancestorButtons.push($(sender).parent.parent.first); //Start looking for others. }   //Searches for expander buttons after first var searching = true; var lastButton; while (searching) { }   var expanderButton = $(sender).parent.parent.children(".uf-expander"); if ($(expanderButton).attr("data-selected") >= 0) { if ($(sender).hasClass("uf-selected")) { $(expanderButton).attr("data-selected", +$(expanderButton).attr("data-selected") - 1); if ($(expanderButton).attr("data-selected") > 0) { expanderButton.addClass("uf-selected"); }           else { expanderButton.removeClass("uf-selected"); }       }        else { $(expanderButton).attr("data-selected", +$(expanderButton).attr("data-selected") + 1); expanderButton.addClass("uf-selected"); }   }    $(sender).toggleClass("uf-selected"); if ($(sender).hasClass("uf-selected")) { if ($(sender).attr("data-type") === undefined) { //not type if ($(sender).attr("data-game") === undefined) { //not game if ($(sender).attr("data-subject") === undefined) { //not subject, but license ufInput.license.push($(sender).attr("data-license")); }               else { //subject ufInput.subject.push($(sender).attr("data-subject")); }           }            else { //game ufInput.game.push($(sender).attr("data-game")); }       }        else { //type ufInput.type.push($(sender).attr("data-type")); }   }    else { if ($(sender).attr("data-type") === undefined) { //not type if ($(sender).attr("data-game") === undefined) { //not game if ($(sender).attr("data-subject") === undefined) { //not subject, but license var i = ufInput.license.indexOf($(sender).attr("data-license")); if (i != -1) { ufInput.license.splice(i, 1); }               }                else { //subject var i = ufInput.subject.indexOf($(sender).attr("data-subject")); if (i != -1) { ufInput.subject.splice(i, 1); }               }            }            else { //game var i = ufInput.game.indexOf($(sender).attr("data-game")); if (i != -1) { ufInput.game.splice(i, 1); }           }        }        else { //type var i = ufInput.type.indexOf($(sender).attr("data-type")); if (i != -1) { ufInput.type.splice(i, 1); }       }    }

ufInput.description = $("#description").val; ufInput.source = $("#source").val; ufInput.holder = $("#holder").val;

ufUpdateDescription; }

function ufUpdateDescription { var content = "\n"; for (var i in ufInput.subject) { content += "\n"; }   for (var i in ufInput.type) { content += "\n"; }   for (var i in ufInput.game) { content += "\n"; }   $("#wpUploadDescription").html(content); }

//Implement warning messages. function ufWarnings(event) { //Make sure description is up-to-date. ufUpdateDescription; var response = ""; var totalWarnings = 0; //Check that 1, and only 1 image type selected. if (ufInput.type.length != 1){ totalWarnings++; response += "Select 1 (and only 1) image type.\n"; }   //Need to add an override. if (ufInput.game.length != 1){ totalWarnings++; response += "Select 1 (and only 1) game or expansion.\n"; }   if (ufInput.subject.length < 1){ totalWarnings++; response += "Select the subject(s) the image is related to.\n"; }   if (ufInput.description === ""){ totalWarnings++; response += "Provide a description.\n"; }   if (ufInput.source === ""){ totalWarnings++; response += "Provide the image source.\n"; }   if (ufInput.holder === ""){ totalWarnings++; response += "Provide the images copyright holder (owner).\n"; }   if (ufInput.license.length != 1){ totalWarnings++; response += "Select 1 (and only 1) license.\n"; }   if (response !== "") { alert("Error(s) has been found.\n\n" + response + "\nPlease fix before submitting."); return false; } }

function ufExecute { "use strict"; //Minified using http://httputility.net/json-minifier.aspx var categoryData = {imageType:[{name:"3D Render",category:"3D Renders",description:"Images of 3D game models.\nIncludes: 3D weapon 3D armor models, 3D character models, etc."},{name:"Advert",category:"Adverts",description:"Images of advertisements."},{name:"Animation",category:"Animations",description:"Any animated images.\nIncludes: Emote animations, reload animations, etc."},{name:"Box Art",category:"Box Art",description:"The cover art from merchandise boxes.\nIncludes: Game covers, book covers, sound track covers, etc."},{name:"Concept Art",category:"Concept Art",description:"Bungie concept art of current and future Destiny series content.\nIncludes: Map concept art, weapon concept art, character concept art, etc."},{name:"Diagram",category:"Diagrams",description:"Images of diagrams, graphs, or tables.\n Includes: Raid diagrams, weapon damage over distance graphs, and crucible statistic tables."},{name:"Drawing",category:"Drawings",description:"Pencil, fine pen, or other stylus based drawings of Destiny series content.\nIncludes: Character drawings, weapon drawings, etc."},{name:"Graphic",category:"Graphics",description:"Images of digital art work, or designs.\nIncludes: Banners, backgrounds, grimoire cards, etc."},{name:"Icon",category:"Icons",description:"Images representing a specific topic or content.\nIncludes: Inventory item icons, quest icons, perk icons, rating icons, etc."},{name:"Logo",category:"Logos",description:"Images of in-game or real life logos.\nIncludes: Omolon logo, Bungie logo, etc."},{name:"Photograph",category:"Photographs",description:"Images taken with a camera.\nIncludes: Employee photos, gaming event photos, etc."},{name:"Poster",category:"Posters",description:"Images of posters related to the Destiny series.\nIncludes: Destiny poster, Destiny Guardian Fireteam poster, etc."},{name:"Scan",category:"Scans",description:"Scanned images of physical objects.\nIncludes: Scanned game manual images, scanned documents, etc."},{name:"Screenshot",category:"Screenshots",description:"Screen capture of computer or in-game image.\nIncludes: Weapon screenshots, armor screenshots, environment screenshots, boss screenshots, etc."},{name:"Unknown",category:"Unknown Type Images",description:"Images that don't fit into the prior types."}],imageGame:[{name:"Destiny",category:"Destiny Images",description:"All images related to Destiny The Game.\nIf the image is related to a specific expanion for Destiny, select that expansion."},{name:"The Dark Below",category:"The Dark Below Images",description:"All images related to The Dark Below expansion."},{name:"House of Wolves",category:"House of Wolves Images",description:"All images related to the House of Wolves expansion."},{name:"The Taken King",category:"The Taken King Images",description:"All images related to The Taken King expansion."},{name:"Rise of Iron",category:"Rise of Iron Images",description:"All images related to the Rise of Iron expansion."}],imageSubject:[{name:"Inventory Item",category:"Inventory Item Images",description:"",more:!0,list:[{name:"Inventory Item",category:"Inventory Item Images",description:"For inventory item images that don't fit the predefined options."},{name:"Class",description:"",more:!0,list:[{name:"Hunter",category:"Hunter Item Images",description:""},{name:"Titan",category:"Titan Item Images",description:""},{name:"Warlock",category:"Warlock Item Images",description:""}]},{name:"Rarity",description:"",more:!0,list:[{name:"Exotic",category:"Exotic Item Images",description:""},{name:"Legendary",category:"Legendary Item Images",description:""},{name:"Rare",category:"Rare Item Images",description:""},{name:"Uncommon",category:"Uncommon Item Images",description:""},{name:"Basic",category:"Basic Item Images",description:""}]},{name:"Type",description:"",more:!0,list:[{name:"Armor",description:"",more:!0,list:[{name:"Armor",category:"Armor Images",description:""},{name:"Armor Set",category:"Armor Set Images",description:""},{name:"Artifact",category:"Artifact Images",description:""},{name:"Bond",category:"Bond Images",description:""},{name:"Chest Armor",category:"Chest Armor Images",description:""},{name:"Clock",category:"Cloak Images",description:""},{name:"Gauntlets",category:"Gauntlets Images",description:""},{name:"Ghost Shell",category:"Ghost Shell Images",description:""},{name:"Helmet",category:"Helmet Images",description:""},{name:"Leg Armor",category:"Leg Armor Images",description:""},{name:"Mark",category:"Mark Images",description:""},{name:"Mask",category:"Mask Images",description:""}]},{name:"Consumable",description:"",more:!0,list:[{name:"Consumable",category:"Consumable Images",description:""},{name:"Ammo Synthesis",category:"Ammo Synthesis Images",description:""},{name:"Glimmer-Drop Consumable",category:"Glimmer-Drop Consumable Images",description:""},{name:"Sparrow Upgrade",category:"Sparrow Upgrade Images",description:""},{name:"Summoning Rune",category:"Summoning Rune Images",description:""},{name:"Treasure Key",category:"Treasure Key Images",description:""},{name:"Weapon Telemetry",category:"Weapon Telemetry Images",description:""}]},{name:"Currency",category:"Currency Images",description:""},{name:"Emblem",category:"Emblem Images",description:""},{name:"Emote",category:"Emote Images",description:""},{name:"Engram",category:"Engram Images",description:""},{name:"Material",category:"Material Images",description:""},{name:"Mystery Bag",category:"Mystery Bag Images",description:""},{name:"Relic",category:"Relic Item Images",description:""},{name:"Shader",category:"Shader Images",description:""},{name:"Vehicle",description:"",more:!0,list:[{name:"Vehicle",category:"Vehicle Images",description:""},{name:"Jumpship",category:"Jumpship Images",description:""},{name:"Sparrow",category:"Sparrow Images",description:""}]},{name:"Weapon",description:"",more:!0,list:[{name:"Weapon",category:"Weapon Images",description:""},{name:"Auto Rifle",category:"Auto Rifle Images",description:""},{name:"Fusion Rifle",category:"Fusion Rifle Images",description:""},{name:"Hand Cannon",category:"Hand Cannon Images",description:""},{name:"Machine Gun",category:"Machine Gun Images",description:""},{name:"Pulse Rifle",category:"Pulse Rifle Images",description:""},{name:"Rocket Launcher",category:"Rocket Launcher Images",description:""},{name:"Scout Rifle",category:"Scout Rifle Images",description:""},{name:"Shotgun",category:"Shotgun Images",description:""},{name:"Sidearm",category:"Sidearm Images",description:""},{name:"Sniper Rifle",category:"Sniper Rifle Images",description:""},{name:"Sword",category:"Sword Images",description:""}]}]}]},{name:"Everything Else",description:"",more:!0,list:[{name:"Achievement and Trophy",category:"Achievement and Trophy Images",description:""},{name:"Activity",description:"",more:!0,list:[{name:"Activity",category:"Activity Images",description:""},{name:"Arena",category:"Arena Images",description:""},{name:"Bounty",category:"Bounty Images",description:""},{name:"Crucible",category:"Crucible Images",description:""},{name:"Event",category:"Event Images",description:""},{name:"Patrol",description:"",more:!0,list:[{name:"Patrol",category:"Patrol Images",description:""},{name:"Public Event",category:"Public Event Images",description:""},{name:"Patrol Mission",category:"Patrol Mission Images",description:""}]},{name:"Quest",category:"Quest Images",description:""},{name:"Raid",category:"Raid Images",description:""},{name:"Social Space",category:"Social Space Images",description:""},{name:"Story Mission",category:"Story Mission Images",description:""},{name:"Strike",category:"Strike Images",description:""}]},{name:"Announcement",description:"",more:!0,list:[{name:"Announcement",category:"Announcement Images",description:""},{name:"Promotional Event",description:"",more:!0,list:[{name:"Promotional Event",category:"Promotional Event Images",description:""},{name:"Alpha Lupi Experience",category:"Alpha Lupi Images",description:""},{name:"Destiny First Look Alpha",category:"Destiny First Look Alpha Images",description:""},{name:"Destiny Public Beta",category:"Destiny Public Beta Images",description:""},{name:"Destiny Selfie",category:"Destiny Selfie Images",description:""}]}]},{name:"Character",description:"",more:!0,list:[{name:"Character",category:"Character Images",description:""},{name:"Guardian",category:"Guardian Images",description:""},{name:"Named Enemy",category:"Named Enemy Images",description:""},{name:"Vendor",category:"Vendor Images",description:""}]},{name:"Cut Content",category:"Cut Content Images",description:""},{name:"Development",category:"Development Images",description:""},{name:"Easter Egg",category:"Easter Egg Images",description:""},{name:"Faction",category:"Faction Images",description:""},{name:"Gameplay",description:"",more:!0,list:[{name:"Gameplay",category:"Gameplay Images",description:""},{name:"Ability",category:"Ability Images",description:""},{name:"Attribute",category:"Attribute Images",description:""},{name:"Class",category:"Class Images",description:""},{name:"Combat",category:"Combat Images",description:""},{name:"Equipable Relic",category:"Equipable Relic Images",description:""},{name:"HUD",category:"HUD Images",description:""},{name:"Medal",category:"Medal Images",description:""},{name:"Modifier",category:"Modifier Images",description:""},{name:"Perk",description:"",more:!0,list:[{name:"Perk",category:"Perk Images",description:""},{name:"Armor Perk",category:"Armor Perk Images",description:""},{name:"Class Perk",category:"Class Perk Images",description:""},{name:"Sparrow Perk",category:"Sparrow Perk Images",description:""},{name:"Weapon Perk",category:"Weapon Perk Images",description:""}]},{name:"UI",category:"UI Images",description:""}]},{name:"Grimoire Card",category:"Grimoire Card Images",description:""},{name:"Leak",category:"Leak Images",description:""},{name:"Location",category:"Location Images",description:""},{name:"Merchandise",category:"Merchandise Images",description:""},{name:"People",category:"People Images",description:""},{name:"Species",category:"Species Images",description:""},{name:"Unknown",category:"Unknown Subject Images",description:""}]},{name:"Maintenance",description:"",more:!0,list:[{name:"Category",category:"Category Images",description:""},{name:"Flag",category:"Flag Images",description:""},{name:"Policy",category:"Policy Images",description:""},{name:"Portal",category:"Portal Images",description:""},{name:"Rating",category:"Rating Images",description:""},{name:"Reward",category:"Reward Images",description:""},{name:"Template",category:"Template Images",description:""},{name:"Theme",category:"Theme Images",description:""},{name:"Wikia",category:"Wikia Images",description:""}]}],imageSource:[{name:"Game",description:"If the image was taken from a game.",explanation:"Enter the name of the game which the image was taken from. Using this example format: Destiny: The Taken King � You can include the mission or activity by using a hyphen, i.e. \" - The King's Fall\". � You can also include the location by using a hyphen again \" - The Tower, Earth\"."},{name:"Book",description:"If the image was taken from a book.",explanation:"Enter the name of the book and the page number(s) which the image was taken from. Using this example format: 'Destiny Limited Edition Strategy Guide- 152 � Use # for one page or #-# for a range of pages."},{name:"Magazine",description:"If the image was taken from a magazine.",explanation:"Enter the name of the magazine and the page number(s) which the image was taken from. Using this example format: 'Official Xbox Magazine- 13-14 � Use # for one page or #-# for a range of pages."},{name:"Video",description:"If the image was taken from a video.",explanation:"Enter the link to the video and time which the image was taken from. Using this example format: https://www.youtube.com/watch?v=SXyMmrgH5d8 (00:52) � (00:00) is the time of the video when the image was seen. � If there is no link, give the full name of the video."},{name:"Website",description:"If the image was taken from a website.",explanation:"Enter the link to the website where the image was taken from. Using this example format: https://www.bungie.net/en/pub/TheTakenKing � For images from the API include the whole API call URL with parameters."},{name:"Other",description:"If the image was taken from somewhere else.",explanation:"Enter as much information as possible about the source of the image, including links and/or titles of the source."}],imageLicense:[{name:"Copyright",template:"Copyright",description:"If the image is owned by someone but permission was given."},{name:"Fair Use",template:"Fair Use",description:"If the image is copyrighted but it'll be used to illistrate the article and there's no free version available."},{name:"Share Alike",template:"Share Alike",description:"If the image has been published under the CC-BY-SA license."},{name:"GNU GPL",template:"GNU GPL",description:"If the image has been published under the GNU General Public License."},{name:"Public Domain",template:"Public Domain",description:"If the image has been taken from or published into the public domain."},{name:"Other",template:"Other",description:"If the image has been published under a different license or you do not know what license the image was published under.\nPlease remember the source of the image."}]}; //Variable to hold HTML to be injected. var htmlToInject;

//Image Name generation and retrival. $(".mw-htmlform-field-HTMLTextField").before(" " + ufSection("Name") + " ");

//Image Type generation. htmlToInject += " " + ufSection("Type", "Select at least 1 image type that best fits the image to be uploaded.", ufButtons(categoryData.imageType, "type"));

//Image Game generation. htmlToInject += ufSection("Game", "Select the game this image is related to.", ufButtons(categoryData.imageGame, "game"));

//Image Subject generation. htmlToInject += ufSection("Subject(s)", "Select the subjects that this image fits.", ufButtons(categoryData.imageSubject, "subject"));

//Image Description generation. htmlToInject += ufSection("Description", "", ufTextArea("description", "Enter a brief description of the image."));

//Image Source generation. htmlToInject += ufSection("Source", "", ufTextArea("source", "Enter source details here..."));

//Image Copyright Holder generation. htmlToInject += ufSection("Copyright Holder", "Provide the name/username of the individual or company that originally created this image. Images such as in-game screenshots are considered to be owned by developer. (EG: Bungie)", ufTextArea("holder", "Enter copyright holder here..."));

//Image License generation. htmlToInject += ufSection("License", "Select the license the image is under.", ufButtons(categoryData.imageLicense, "license")); //Description htmlToInject += ufSection("Page Preview", "", "") + " "; $(".mw-htmlform-field-HTMLTextAreaField").before(htmlToInject); $(".mw-htmlform-field-Licenses").remove; //Attach warning event to submit button. $("#wpUploadDescription").closest("form").submit(ufWarnings); }

$(document).ready(ufWarnings);