From 093ae27ae8665d2fa41765af81d9f5353c0898d8 Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 15 Jul 2015 00:09:17 -0400 Subject: [PATCH] get upset when we neopets.com bans us :P --- app/assets/javascripts/modeling.js.jsx | 101 ++++++++++++----------- app/assets/javascripts/outfits/new.js | 29 +++++-- app/assets/stylesheets/outfits/_new.sass | 35 +++++--- app/controllers/outfits_controller.rb | 2 +- app/views/outfits/new.html.haml | 57 +++++++++---- config/locales/en-MEEP.yml | 12 +-- config/locales/en.yml | 11 +++ config/locales/es.yml | 12 +-- config/locales/pt.yml | 12 +-- 9 files changed, 168 insertions(+), 103 deletions(-) diff --git a/app/assets/javascripts/modeling.js.jsx b/app/assets/javascripts/modeling.js.jsx index a31a4e30..2a0d3546 100644 --- a/app/assets/javascripts/modeling.js.jsx +++ b/app/assets/javascripts/modeling.js.jsx @@ -1,5 +1,60 @@ /** @jsx React.DOM */ +var Neopia = { + User: { + get: function(id) { + return $.ajax({ + dataType: "json", + url: Neopia.API_URL + "/users/" + id, + useCSRFProtection: false + }).then(function(response) { + return response.users[0]; + }); + } + }, + Customization: { + request: function(petId, type) { + var data = {}; + if (ImpressUser.id) { + data.impress_user = ImpressUser.id; + } + return $.ajax({ + dataType: "json", + type: type, + url: Neopia.API_URL + "/pets/" + petId + "/customization", + useCSRFProtection: false, + data: data + }); + }, + get: function(petId) { + return this.request(petId, "GET"); + }, + post: function(petId) { + return this.request(petId, "POST"); + } + }, + Status: { + get: function() { + return $.ajax({ + dataType: "json", + url: Neopia.API_URL + "/status", + useCSRFProtection: false + }); + } + }, + init: function() { + var hostEl = $('meta[name=neopia-host]'); + if (!hostEl.length) { + throw "missing neopia-host meta tag"; + } + var host = hostEl.attr('content'); + if (!host) { + throw "neopia-host meta tag exists, but is empty"; + } + Neopia.API_URL = "http://" + host + "/api/1"; + } +}; + (function($, I18n) { // Console-polyfill. MIT license. // https://github.com/paulmillr/console-polyfill @@ -18,52 +73,6 @@ return con; })(window.console || {}); - var Neopia = { - User: { - get: function(id) { - return $.ajax({ - dataType: "json", - url: Neopia.API_URL + "/users/" + id, - useCSRFProtection: false - }).then(function(response) { - return response.users[0]; - }); - } - }, - Customization: { - request: function(petId, type) { - var data = {}; - if (ImpressUser.id) { - data.impress_user = ImpressUser.id; - } - return $.ajax({ - dataType: "json", - type: type, - url: Neopia.API_URL + "/pets/" + petId + "/customization", - useCSRFProtection: false, - data: data - }); - }, - get: function(petId) { - return this.request(petId, "GET"); - }, - post: function(petId) { - return this.request(petId, "POST"); - } - }, - init: function() { - var hostEl = $('meta[name=neopia-host]'); - if (!hostEl.length) { - throw "missing neopia-host meta tag"; - } - var host = hostEl.attr('content'); - if (!host) { - throw "neopia-host meta tag exists, but is empty"; - } - Neopia.API_URL = "http://" + host + "/api/1"; - } - }; - var ImpressUser = (function() { var userSignedIn = ($('meta[name=user-signed-in]').attr('content') === 'true'); if (userSignedIn) { diff --git a/app/assets/javascripts/outfits/new.js b/app/assets/javascripts/outfits/new.js index 8b569c47..e8c53a4e 100644 --- a/app/assets/javascripts/outfits/new.js +++ b/app/assets/javascripts/outfits/new.js @@ -4,8 +4,7 @@ var disqus_shortname = 'dresstoimpress'; var preview_el = $('#pet-preview'), img_el = preview_el.find('img'), - response_el = preview_el.find('span'), - name_el = $('#main-pet-name'); + response_el = preview_el.find('span'); var defaultPreviewUrl = img_el.attr('src'); @@ -29,7 +28,7 @@ var Preview = { response_el.empty(); $('#preview-' + key + '-template').tmpl(options).appendTo(response_el); }, - updateWithName: function () { + updateWithName: function (name_el) { var name = name_el.val(), job; if(name) { currentName = name; @@ -117,7 +116,7 @@ Preview.Job.Name = function (name) { Preview.Job.apply(this, [name, 'cpn']); this.visit = function() { - name_el.val(this.name).closest('form').submit(); + $('.main-pet-name').val(this.name).closest('form').submit(); } } @@ -153,15 +152,19 @@ Preview.Job.Feature = function(feature) { $(function () { var previewWithNameTimeout; + var name_el = $('.main-pet-name'); name_el.val(PetQuery.name); - Preview.updateWithName(); + Preview.updateWithName(name_el); name_el.keyup(function () { if(previewWithNameTimeout) { clearTimeout(previewWithNameTimeout); Preview.Job.current.loading = false; } - previewWithNameTimeout = setTimeout(Preview.updateWithName, 250); + var name_el = $(this); + previewWithNameTimeout = setTimeout(function() { + Preview.updateWithName(name_el); + }, 250); }); img_el.load(function () { @@ -284,12 +287,22 @@ $(function () { } } - $('#load-pet-to-wardrobe').submit(function(e) { - if (name_el.val() === "" && Preview.Job.current) { + $('.load-pet-to-wardrobe').submit(function(e) { + if ($(this).find('.main-pet-name').val() === "" && Preview.Job.current) { e.preventDefault(); Preview.Job.current.visit(); } }); + + function setNeopiaStatus(isOnline) { + $('#outfit-forms').attr('data-neopia-status', isOnline ? 'online' : 'offline'); + } + + Neopia.Status.get().then(function(r) { + setNeopiaStatus(!!r.status); + }).fail(function() { + setNeopiaStatus(false); + }); }); function addDisqusCount() { diff --git a/app/assets/stylesheets/outfits/_new.sass b/app/assets/stylesheets/outfits/_new.sass index c3a0a48f..051d875d 100644 --- a/app/assets/stylesheets/outfits/_new.sass +++ b/app/assets/stylesheets/outfits/_new.sass @@ -47,18 +47,29 @@ body.outfits-new left: 16px legend margin-left: -16px - #load-pet-to-wardrobe - font-size: 175% - margin: - bottom: 1em - top: 1.5em - input - font-size: 67% - padding: .5em - width: 10em - button - +loud-awesome-button - font-size: 67% + .primary + margin: + bottom: 2em + top: 3em + input + font-size: 115% + padding: .5em + width: 10em + button + +loud-awesome-button + legend + font-size: 175% + select + font-size: 120% + [data-require-neopia-status=offline] + display: none + &[data-neopia-status=offline] + [data-require-neopia-status=online] + display: none + [data-require-neopia-status=offline] + display: block + [data-require-neopia-status=offline] .load-pet-to-wardrobe legend a + font-size: 85% #description, #top-contributors float: left #description diff --git a/app/controllers/outfits_controller.rb b/app/controllers/outfits_controller.rb index 357b6eca..4dd88ac7 100644 --- a/app/controllers/outfits_controller.rb +++ b/app/controllers/outfits_controller.rb @@ -41,7 +41,7 @@ class OutfitsController < ApplicationController end def new - unless localized_fragment_exist?("outfits#new start_from_scratch_form pranks_funny=#{Color.pranks_funny?}") + unless localized_fragment_exist?("outfits#new neopia_online start_from_scratch_form pranks_funny=#{Color.pranks_funny?}") && localized_fragment_exist?("outfits#new neopia_offline start_from_scratch_form pranks_funny=#{Color.pranks_funny?}") @colors = Color.funny.alphabetical @species = Species.alphabetical end diff --git a/app/views/outfits/new.html.haml b/app/views/outfits/new.html.haml index cdba9664..67ee1908 100644 --- a/app/views/outfits/new.html.haml +++ b/app/views/outfits/new.html.haml @@ -13,24 +13,45 @@ %h1= t 'app_name' %h2= t '.tagline' - = form_tag remote_load_pet_path, method: 'GET', id: 'load-pet-to-wardrobe' do - = hidden_field_tag 'impress_user', current_user.try(:id) - - localized_cache action_suffix: 'outfits#new main_load_pet_form_content' do - = hidden_field_tag 'redirect', "#{wardrobe_url}\#{q}" - %fieldset - %legend= t '.load_pet.legend' - = pet_name_tag :id => 'main-pet-name' - %button{:type => "submit"} - = t '.load_pet.submit' + %div{'data-require-neopia-status' => 'online'} + = form_tag remote_load_pet_path, method: 'GET', class: 'primary load-pet-to-wardrobe' do + = hidden_field_tag 'impress_user', current_user.try(:id) + - localized_cache action_suffix: 'outfits#new neopia_online main_load_pet_form_content' do + = hidden_field_tag 'redirect', "#{wardrobe_url}\#{q}" + %fieldset + %legend= t '.neopia_online.load_pet' + = pet_name_tag class: 'main-pet-name' + %button{:type => "submit"} + = t '.submit.primary' - - localized_cache "outfits#new start_from_scratch_form pranks_funny=#{Color.pranks_funny?}" do - = form_tag wardrobe_path, method: 'GET', id: 'start-from-scratch', authenticity_token: false do - %fieldset - %legend= t '.start_from_scratch.legend' - = pet_attribute_select 'color', @colors, 8 - = pet_attribute_select 'species', @species - %button{:type => "submit"} - = t('.start_from_scratch.submit') + - localized_cache "outfits#new neopia_online start_from_scratch_form pranks_funny=#{Color.pranks_funny?}" do + = form_tag wardrobe_path, method: 'GET', class: 'secondary start-from-scratch', authenticity_token: false do + %fieldset + %legend= t '.neopia_online.start_from_scratch' + = pet_attribute_select 'color', @colors, 8 + = pet_attribute_select 'species', @species + %button{:type => "submit"} + = t('.submit.secondary') + + %div{'data-require-neopia-status' => 'offline'} + - localized_cache "outfits#new neopia_offline start_from_scratch_form pranks_funny=#{Color.pranks_funny?}" do + = form_tag wardrobe_path, method: 'GET', class: 'primary start-from-scratch', authenticity_token: false do + %fieldset + %legend= t '.neopia_offline.start_from_scratch' + = pet_attribute_select 'color', @colors, 8 + = pet_attribute_select 'species', @species + %button{:type => "submit"} + = t('.submit.primary') + + = form_tag remote_load_pet_path, method: 'GET', class: 'secondary load-pet-to-wardrobe' do + = hidden_field_tag 'impress_user', current_user.try(:id) + - localized_cache action_suffix: 'outfits#new neopia_offline main_load_pet_form_content' do + = hidden_field_tag 'redirect', "#{wardrobe_url}\#{q}" + %fieldset + %legend= t '.neopia_offline.load_pet.main_html', link: link_to(t('.neopia_offline.load_pet.link_content'), 'http://blog.openneo.net/') + = pet_name_tag class: 'main-pet-name' + %button{:type => "submit"} + = t '.submit.secondary' %ul#sections - localized_cache :action_suffix => 'your_items_module' do @@ -122,4 +143,4 @@ - content_for :javascripts do = include_javascript_libraries :jquery20, :jquery_tmpl = modeling_i18n_tag - = javascript_include_tag 'ajax_auth', 'react', 'jquery.timeago', 'pet_query', 'outfits/new', 'modeling' \ No newline at end of file + = javascript_include_tag 'ajax_auth', 'react', 'jquery.timeago', 'pet_query', 'modeling', 'outfits/new' \ No newline at end of file diff --git a/config/locales/en-MEEP.yml b/config/locales/en-MEEP.yml index 0c8a10b3..9d1a7f83 100644 --- a/config/locales/en-MEEP.yml +++ b/config/locales/en-MEEP.yml @@ -609,12 +609,12 @@ en-MEEP: pet_type_not_found: We haven't meeped a %{color_name} %{species_name}. Meep? pet_not_found: Pet not meeped. - load_pet: - legend: Enter your pet's meep - submit: Meep my outfit! - start_from_scratch: - legend: Or meep from scratch - submit: Meep + submit: + primary: Meep my outfit! + secondary: Meep + neopia_online: + load_pet: Enter your pet's meep + start_from_scratch: Or meep from scratch your_items: tagline: Meep and meep! description: diff --git a/config/locales/en.yml b/config/locales/en.yml index 0197b1a6..77eafc94 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -685,6 +685,17 @@ en: pet_type_not_found: We haven't seen a %{color_name} %{species_name}. Have you? pet_not_found: Pet not found. + submit: + primary: Plan my outfit! + secondary: Go + neopia_online: + load_pet: Enter your pet's name + start_from_scratch: Or start from scratch + neopia_offline: + start_from_scratch: Choose a pet to get started + load_pet: + main_html: Or try your pet's name %{link} + link_content: (but it looks like Neopets.com is ignoring us) load_pet: legend: Enter your pet's name submit: Plan my outfit! diff --git a/config/locales/es.yml b/config/locales/es.yml index 4c307027..c6b62fb0 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -476,12 +476,12 @@ es: preview: pet_type_not_found: No hemos encontrado aun a un %{species_name} %{color_name}. ¿Lo has hecho tú? pet_not_found: Pet no encontrado. - load_pet: - legend: Escribe el nombre de tu pet - submit: ¡Diseñar mi atuendo! - start_from_scratch: - legend: O empieza a partir de una plantilla - submit: Ir + submit: + primary: ¡Diseñar mi atuendo! + secondary: Ir + neopia_online: + load_pet: Escribe el nombre de tu pet + start_from_scratch: O empieza a partir de una plantilla your_items: tagline: ¡Añade e intercambia! description: Crea listas de los objetos que tú tienes y quieres. ¡Compártelas con el mundo! diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 283af229..cfccd326 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -474,12 +474,12 @@ pt: preview: pet_type_not_found: Nós nunca vimos um %{species_name} %{color_name} . Você viu? pet_not_found: Pet não encontrado. - load_pet: - legend: Digite o nome do seu pet - submit: Planeje minha roupa! - start_from_scratch: - legend: Ou comece do zero - submit: Vai + submit: + primary: Planeje minha roupa! + secondary: Vai + neopia_online: + load_pet: Digite o nome do seu pet + start_from_scratch: Ou comece do zero your_items: tagline: Acompanhe e troque! description: Faça listas de itens que você tem e que procura, e compartilhe com o mundo.