1
0
Fork 0
forked from OpenNeo/impress

get upset when we neopets.com bans us :P

This commit is contained in:
Emi Matchu 2015-07-15 00:09:17 -04:00
parent 169c587e42
commit 093ae27ae8
9 changed files with 168 additions and 103 deletions

View file

@ -1,5 +1,60 @@
/** @jsx React.DOM */ /** @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) { (function($, I18n) {
// Console-polyfill. MIT license. // Console-polyfill. MIT license.
// https://github.com/paulmillr/console-polyfill // https://github.com/paulmillr/console-polyfill
@ -18,52 +73,6 @@
return con; return con;
})(window.console || {}); })(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 ImpressUser = (function() {
var userSignedIn = ($('meta[name=user-signed-in]').attr('content') === 'true'); var userSignedIn = ($('meta[name=user-signed-in]').attr('content') === 'true');
if (userSignedIn) { if (userSignedIn) {

View file

@ -4,8 +4,7 @@ var disqus_shortname = 'dresstoimpress';
var preview_el = $('#pet-preview'), var preview_el = $('#pet-preview'),
img_el = preview_el.find('img'), img_el = preview_el.find('img'),
response_el = preview_el.find('span'), response_el = preview_el.find('span');
name_el = $('#main-pet-name');
var defaultPreviewUrl = img_el.attr('src'); var defaultPreviewUrl = img_el.attr('src');
@ -29,7 +28,7 @@ var Preview = {
response_el.empty(); response_el.empty();
$('#preview-' + key + '-template').tmpl(options).appendTo(response_el); $('#preview-' + key + '-template').tmpl(options).appendTo(response_el);
}, },
updateWithName: function () { updateWithName: function (name_el) {
var name = name_el.val(), job; var name = name_el.val(), job;
if(name) { if(name) {
currentName = name; currentName = name;
@ -117,7 +116,7 @@ Preview.Job.Name = function (name) {
Preview.Job.apply(this, [name, 'cpn']); Preview.Job.apply(this, [name, 'cpn']);
this.visit = function() { 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 () { $(function () {
var previewWithNameTimeout; var previewWithNameTimeout;
var name_el = $('.main-pet-name');
name_el.val(PetQuery.name); name_el.val(PetQuery.name);
Preview.updateWithName(); Preview.updateWithName(name_el);
name_el.keyup(function () { name_el.keyup(function () {
if(previewWithNameTimeout) { if(previewWithNameTimeout) {
clearTimeout(previewWithNameTimeout); clearTimeout(previewWithNameTimeout);
Preview.Job.current.loading = false; 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 () { img_el.load(function () {
@ -284,12 +287,22 @@ $(function () {
} }
} }
$('#load-pet-to-wardrobe').submit(function(e) { $('.load-pet-to-wardrobe').submit(function(e) {
if (name_el.val() === "" && Preview.Job.current) { if ($(this).find('.main-pet-name').val() === "" && Preview.Job.current) {
e.preventDefault(); e.preventDefault();
Preview.Job.current.visit(); 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() { function addDisqusCount() {

View file

@ -47,18 +47,29 @@ body.outfits-new
left: 16px left: 16px
legend legend
margin-left: -16px margin-left: -16px
#load-pet-to-wardrobe .primary
font-size: 175% margin:
margin: bottom: 2em
bottom: 1em top: 3em
top: 1.5em input
input font-size: 115%
font-size: 67% padding: .5em
padding: .5em width: 10em
width: 10em button
button +loud-awesome-button
+loud-awesome-button legend
font-size: 67% 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 #description, #top-contributors
float: left float: left
#description #description

View file

@ -41,7 +41,7 @@ class OutfitsController < ApplicationController
end end
def new 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 @colors = Color.funny.alphabetical
@species = Species.alphabetical @species = Species.alphabetical
end end

View file

@ -13,24 +13,45 @@
%h1= t 'app_name' %h1= t 'app_name'
%h2= t '.tagline' %h2= t '.tagline'
= form_tag remote_load_pet_path, method: 'GET', id: 'load-pet-to-wardrobe' do %div{'data-require-neopia-status' => 'online'}
= hidden_field_tag 'impress_user', current_user.try(:id) = form_tag remote_load_pet_path, method: 'GET', class: 'primary load-pet-to-wardrobe' do
- localized_cache action_suffix: 'outfits#new main_load_pet_form_content' do = hidden_field_tag 'impress_user', current_user.try(:id)
= hidden_field_tag 'redirect', "#{wardrobe_url}\#{q}" - localized_cache action_suffix: 'outfits#new neopia_online main_load_pet_form_content' do
%fieldset = hidden_field_tag 'redirect', "#{wardrobe_url}\#{q}"
%legend= t '.load_pet.legend' %fieldset
= pet_name_tag :id => 'main-pet-name' %legend= t '.neopia_online.load_pet'
%button{:type => "submit"} = pet_name_tag class: 'main-pet-name'
= t '.load_pet.submit' %button{:type => "submit"}
= t '.submit.primary'
- localized_cache "outfits#new start_from_scratch_form pranks_funny=#{Color.pranks_funny?}" do - localized_cache "outfits#new neopia_online start_from_scratch_form pranks_funny=#{Color.pranks_funny?}" do
= form_tag wardrobe_path, method: 'GET', id: 'start-from-scratch', authenticity_token: false do = form_tag wardrobe_path, method: 'GET', class: 'secondary start-from-scratch', authenticity_token: false do
%fieldset %fieldset
%legend= t '.start_from_scratch.legend' %legend= t '.neopia_online.start_from_scratch'
= pet_attribute_select 'color', @colors, 8 = pet_attribute_select 'color', @colors, 8
= pet_attribute_select 'species', @species = pet_attribute_select 'species', @species
%button{:type => "submit"} %button{:type => "submit"}
= t('.start_from_scratch.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 %ul#sections
- localized_cache :action_suffix => 'your_items_module' do - localized_cache :action_suffix => 'your_items_module' do
@ -122,4 +143,4 @@
- content_for :javascripts do - content_for :javascripts do
= include_javascript_libraries :jquery20, :jquery_tmpl = include_javascript_libraries :jquery20, :jquery_tmpl
= modeling_i18n_tag = modeling_i18n_tag
= javascript_include_tag 'ajax_auth', 'react', 'jquery.timeago', 'pet_query', 'outfits/new', 'modeling' = javascript_include_tag 'ajax_auth', 'react', 'jquery.timeago', 'pet_query', 'modeling', 'outfits/new'

View file

@ -609,12 +609,12 @@ en-MEEP:
pet_type_not_found: pet_type_not_found:
We haven't meeped a %{color_name} %{species_name}. Meep? We haven't meeped a %{color_name} %{species_name}. Meep?
pet_not_found: Pet not meeped. pet_not_found: Pet not meeped.
load_pet: submit:
legend: Enter your pet's meep primary: Meep my outfit!
submit: Meep my outfit! secondary: Meep
start_from_scratch: neopia_online:
legend: Or meep from scratch load_pet: Enter your pet's meep
submit: Meep start_from_scratch: Or meep from scratch
your_items: your_items:
tagline: Meep and meep! tagline: Meep and meep!
description: description:

View file

@ -685,6 +685,17 @@ en:
pet_type_not_found: pet_type_not_found:
We haven't seen a %{color_name} %{species_name}. Have you? We haven't seen a %{color_name} %{species_name}. Have you?
pet_not_found: Pet not found. 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: load_pet:
legend: Enter your pet's name legend: Enter your pet's name
submit: Plan my outfit! submit: Plan my outfit!

View file

@ -476,12 +476,12 @@ es:
preview: preview:
pet_type_not_found: No hemos encontrado aun a un %{species_name} %{color_name}. ¿Lo has hecho tú? pet_type_not_found: No hemos encontrado aun a un %{species_name} %{color_name}. ¿Lo has hecho tú?
pet_not_found: Pet no encontrado. pet_not_found: Pet no encontrado.
load_pet: submit:
legend: Escribe el nombre de tu pet primary: ¡Diseñar mi atuendo!
submit: ¡Diseñar mi atuendo! secondary: Ir
start_from_scratch: neopia_online:
legend: O empieza a partir de una plantilla load_pet: Escribe el nombre de tu pet
submit: Ir start_from_scratch: O empieza a partir de una plantilla
your_items: your_items:
tagline: ¡Añade e intercambia! tagline: ¡Añade e intercambia!
description: Crea listas de los objetos que tú tienes y quieres. ¡Compártelas con el mundo! description: Crea listas de los objetos que tú tienes y quieres. ¡Compártelas con el mundo!

View file

@ -474,12 +474,12 @@ pt:
preview: preview:
pet_type_not_found: Nós nunca vimos um %{species_name} %{color_name} . Você viu? pet_type_not_found: Nós nunca vimos um %{species_name} %{color_name} . Você viu?
pet_not_found: Pet não encontrado. pet_not_found: Pet não encontrado.
load_pet: submit:
legend: Digite o nome do seu pet primary: Planeje minha roupa!
submit: Planeje minha roupa! secondary: Vai
start_from_scratch: neopia_online:
legend: Ou comece do zero load_pet: Digite o nome do seu pet
submit: Vai start_from_scratch: Ou comece do zero
your_items: your_items:
tagline: Acompanhe e troque! tagline: Acompanhe e troque!
description: Faça listas de itens que você tem e que procura, e compartilhe com o mundo. description: Faça listas de itens que você tem e que procura, e compartilhe com o mundo.