forked from OpenNeo/impress
oh dang, did we just fix most of the mixed content?
This commit is contained in:
parent
4a18f22571
commit
b11d7a8c9c
10 changed files with 265 additions and 304 deletions
|
@ -225,11 +225,13 @@ var Neopia = (function($, I18n) {
|
|||
Neopia.init();
|
||||
this._createItems($);
|
||||
var usersEl = $('#modeling-neopets-users');
|
||||
if (usersEl.length) {
|
||||
this._usersComponent = React.renderComponent(<NeopetsUsernamesForm />,
|
||||
usersEl.get(0));
|
||||
var usernames = ImpressUser.getNeopetsUsernames();
|
||||
usernames.forEach(this._registerUsername.bind(this));
|
||||
this._updateUsernames();
|
||||
}
|
||||
},
|
||||
model: function(neopiaPetId, itemId) {
|
||||
var oldCustomization = this._customizationsByPetId[neopiaPetId];
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
var disqus_shortname = 'dresstoimpress';
|
||||
|
||||
(function () { // don't need to export anything in here
|
||||
|
||||
var preview_el = $('#pet-preview'),
|
||||
var preview_el = $('#pet-preview'),
|
||||
img_el = preview_el.find('img'),
|
||||
response_el = preview_el.find('span');
|
||||
|
||||
var defaultPreviewUrl = img_el.attr('src');
|
||||
var defaultPreviewUrl = img_el.attr('src');
|
||||
|
||||
preview_el.click(function () {
|
||||
preview_el.click(function () {
|
||||
Preview.Job.current.visit();
|
||||
});
|
||||
});
|
||||
|
||||
var Preview = {
|
||||
var Preview = {
|
||||
clear: function () {
|
||||
if(typeof Preview.Job.fallback != 'undefined') Preview.Job.fallback.setAsCurrent();
|
||||
},
|
||||
|
@ -41,20 +39,24 @@ var Preview = {
|
|||
Preview.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadNotable() {
|
||||
$.getJSON('http://notables.openneo.net/api/1/days/ago/1?callback=?', function (response) {
|
||||
var notables = response.notables;
|
||||
var i = Math.floor(Math.random() * notables.length);
|
||||
Preview.Job.fallback = new Preview.Job.Name(notables[i].petName);
|
||||
function loadNotable() {
|
||||
// TODO: add HTTPS to notables
|
||||
// $.getJSON('http://notables.openneo.net/api/1/days/ago/1?callback=?', function (response) {
|
||||
// var notables = response.notables;
|
||||
// var i = Math.floor(Math.random() * notables.length);
|
||||
// Preview.Job.fallback = new Preview.Job.Name(notables[i].petName);
|
||||
// if(!Preview.Job.current) {
|
||||
// Preview.Job.fallback.setAsCurrent();
|
||||
// }
|
||||
// });
|
||||
if(!Preview.Job.current) {
|
||||
Preview.Job.fallback.setAsCurrent();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function loadFeature() {
|
||||
function loadFeature() {
|
||||
$.getJSON('/donations/features', function(features) {
|
||||
if (features.length > 0) {
|
||||
var feature = features[Math.floor(Math.random() * features.length)];
|
||||
|
@ -66,11 +68,11 @@ function loadFeature() {
|
|||
loadNotable();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
loadFeature();
|
||||
loadFeature();
|
||||
|
||||
Preview.Job = function (key, base) {
|
||||
Preview.Job = function (key, base) {
|
||||
var job = this,
|
||||
quality = 2;
|
||||
job.loading = false;
|
||||
|
@ -78,6 +80,7 @@ Preview.Job = function (key, base) {
|
|||
function getImageSrc() {
|
||||
if (key.substr(0, 3) === 'a:-') {
|
||||
// lol lazy code for prank image :P
|
||||
// TODO: HTTPS?
|
||||
return "http://swfimages.impress.openneo.net" +
|
||||
"/biology/000/000/0-2/" + key.substr(2) + "/300x300.png";
|
||||
} else if (base === 'cp' || base === 'cpn') {
|
||||
|
@ -109,27 +112,27 @@ Preview.Job = function (key, base) {
|
|||
this.notFound = function() {
|
||||
Preview.notFound('pet-not-found');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Preview.Job.Name = function (name) {
|
||||
Preview.Job.Name = function (name) {
|
||||
this.name = name;
|
||||
Preview.Job.apply(this, [name, 'cpn']);
|
||||
|
||||
this.visit = function() {
|
||||
$('.main-pet-name').val(this.name).closest('form').submit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Preview.Job.Hash = function (hash, form) {
|
||||
Preview.Job.Hash = function (hash, form) {
|
||||
Preview.Job.apply(this, [hash, 'cp']);
|
||||
|
||||
this.visit = function() {
|
||||
window.location = "/wardrobe?color=" + form.find('.color').val() + "&species=" +
|
||||
form.find('.species').val();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Preview.Job.Feature = function(feature) {
|
||||
Preview.Job.Feature = function(feature) {
|
||||
Preview.Job.apply(this, [feature.outfit_image_url, 'url']);
|
||||
this.name = "Thanks for donating, " + feature.donor_name + "!"; // TODO: i18n
|
||||
|
||||
|
@ -146,10 +149,10 @@ Preview.Job.Feature = function(feature) {
|
|||
});
|
||||
boring.setAsCurrent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$(function () {
|
||||
$(function () {
|
||||
var previewWithNameTimeout;
|
||||
|
||||
var name_el = $('.main-pet-name');
|
||||
|
@ -213,67 +216,6 @@ $(function () {
|
|||
});
|
||||
});
|
||||
|
||||
$.getJSON('http://blog.openneo.net/api/read/json?callback=?', function (data) {
|
||||
var post = data.posts[0], el = $('#blog-preview'),
|
||||
url = post['url-with-slug'], header = "Here's the latest!", body = '',
|
||||
truncate_body_at = 500, image;
|
||||
if(post.type == 'regular') {
|
||||
header = post['regular-title'];
|
||||
body = post['regular-body'];
|
||||
} else if(post.type == 'link') {
|
||||
header = post['link-text'];
|
||||
body = post['link-description'];
|
||||
} else if(post.type == 'photo') {
|
||||
body = post['photo-caption'];
|
||||
image = post['photo-url-75'];
|
||||
}
|
||||
// No truncation on this new layout
|
||||
/*body = body.replace(/(<\/?[\S][^>]*>)/gi, '');
|
||||
if(body.length > truncate_body_at) {
|
||||
body = body.substring(0, truncate_body_at);
|
||||
body = body.replace(/\s+\w+$/, '');
|
||||
body += '…';
|
||||
}*/
|
||||
el.find('h2').text(header).wrapInner($('<a/>', {href: url}));
|
||||
var contentEl = el.find('div');
|
||||
contentEl.html(body);
|
||||
$('<a/>', {'id': 'blog-preview-comments', href: url + '#disqus_thread'}).appendTo(el);
|
||||
if(image) {
|
||||
el.find('img').attr('src', image).parent().attr('href', url);
|
||||
}
|
||||
|
||||
// Localize
|
||||
var localizedBodies = {};
|
||||
contentEl.find('.locale').each(function () {
|
||||
var localizedBody = $(this);
|
||||
var locale = localizedBody.attr('class').match(/locale-(\S+)/)[1];
|
||||
localizedBodies[locale] = localizedBody;
|
||||
});
|
||||
|
||||
var fallbacks = $('#locale option:selected').attr('data-fallbacks').split(',');
|
||||
var bestLocale = null;
|
||||
for(var i = 0; i < fallbacks.length; i++) {
|
||||
if(localizedBodies.hasOwnProperty(fallbacks[i])) {
|
||||
bestLocale = fallbacks[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(bestLocale) {
|
||||
// I feel bad doing all this in JS rather than CSS, but sometimes you
|
||||
// gotta do what you gotta do if you wanna support any number of locales.
|
||||
for(var locale in localizedBodies) {
|
||||
localizedBodies[locale].hide();
|
||||
}
|
||||
|
||||
localizedBodies[bestLocale].show();
|
||||
|
||||
contentEl.find('.no-locale').hide();
|
||||
}
|
||||
|
||||
el.fadeIn('medium');
|
||||
addDisqusCount();
|
||||
});
|
||||
|
||||
var neopiaError = document.location.search.match(/neopia%5Berror%5D=([^&]+)/);
|
||||
if (neopiaError !== null) {
|
||||
|
@ -303,13 +245,8 @@ $(function () {
|
|||
}).fail(function() {
|
||||
setNeopiaStatus(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#latest-contribution-created-at').timeago();
|
||||
|
||||
function addDisqusCount() {
|
||||
var s = document.createElement('script'); s.async = true;
|
||||
s.type = 'text/javascript';
|
||||
s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
|
||||
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);}
|
||||
})();
|
||||
|
||||
$('#latest-contribution-created-at').timeago();
|
||||
|
|
|
@ -216,17 +216,7 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def camo_image_url(image_url)
|
||||
if CAMO_KEY
|
||||
hexdigest = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), CAMO_KEY, image_url)
|
||||
uri = Addressable::URI.parse("#{CAMO_HOST}/#{hexdigest}")
|
||||
uri.query_values = { 'url' => image_url, 'repo' => '', 'path' => '' }
|
||||
uri.to_s
|
||||
else
|
||||
uri = Addressable::URI.parse(image_url)
|
||||
query_values = uri.query_values || {}
|
||||
uri.query_values = query_values.merge(NO_CAMO_CONFIG: nil)
|
||||
uri.to_s
|
||||
end
|
||||
Image.from_insecure_url(image_url).secure_url
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ module ContributionHelper
|
|||
:item_link => link)
|
||||
output = translate("contributions.contributed_description.main.#{main_key}_html",
|
||||
:item_description => description)
|
||||
output << image_tag(item.thumbnail_url) if show_image
|
||||
output << image_tag(item.thumbnail.secure_url) if show_image
|
||||
output
|
||||
else
|
||||
translate('contributions.contributed_description.parents.item.blank')
|
||||
|
|
28
app/models/image.rb
Normal file
28
app/models/image.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
class Image
|
||||
attr_reader :insecure_url, :secure_url
|
||||
|
||||
def initialize(insecure_url, secure_url)
|
||||
@insecure_url = insecure_url
|
||||
@secure_url = secure_url
|
||||
end
|
||||
|
||||
def self.from_insecure_url(insecure_url)
|
||||
Image.new insecure_url, proxy_insecure_url(insecure_url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.proxy_insecure_url(insecure_url)
|
||||
if CAMO_HOST && CAMO_KEY
|
||||
hexdigest = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), CAMO_KEY, insecure_url)
|
||||
uri = Addressable::URI.parse("#{CAMO_HOST}/#{hexdigest}")
|
||||
uri.query_values = { url: insecure_url }
|
||||
uri.to_s
|
||||
else
|
||||
uri = Addressable::URI.parse(insecure_url)
|
||||
query_values = uri.query_values || {}
|
||||
uri.query_values = query_values.merge(NO_CAMO_CONFIG: nil)
|
||||
uri.to_s
|
||||
end
|
||||
end
|
||||
end
|
|
@ -327,12 +327,16 @@ class Item < ActiveRecord::Base
|
|||
modeled_body_ids.size.to_f / predicted_body_ids.size
|
||||
end
|
||||
|
||||
def thumbnail
|
||||
@thumbnail ||= Image.from_insecure_url(thumbnail_url)
|
||||
end
|
||||
|
||||
def as_json(options={})
|
||||
json = {
|
||||
:description => description,
|
||||
:id => id,
|
||||
:name => name,
|
||||
:thumbnail_url => thumbnail_url,
|
||||
:thumbnail_url => thumbnail.secure_url,
|
||||
:zones_restrict => zones_restrict,
|
||||
:rarity_index => rarity_index,
|
||||
:nc => nc?
|
||||
|
|
|
@ -5,7 +5,7 @@ class Item
|
|||
attr_reader :id
|
||||
attr_writer :item, :owned, :wanted
|
||||
|
||||
delegate :description, :name, :nc?, :thumbnail_url, :to_param, to: :item
|
||||
delegate :description, :name, :nc?, :thumbnail_url, :thumbnail, :to_param, to: :item
|
||||
|
||||
def self.model_name
|
||||
Item.model_name
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
= link_to item_path(item) do
|
||||
= image_tag item.thumbnail_url, :alt => item.description, :title => item.description
|
||||
= image_tag item.thumbnail.secure_url, :alt => item.description, :title => item.description
|
||||
%span.name= item.name
|
||||
= nc_icon_for(item)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
- localized_cache "items/#{@item.id} header" do
|
||||
%header#item-header
|
||||
= image_tag @item.thumbnail_url, :id => 'item-thumbnail'
|
||||
= image_tag @item.thumbnail.secure_url, :id => 'item-thumbnail'
|
||||
%div
|
||||
%h2#item-name= @item.name
|
||||
= nc_icon_for(@item)
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
|
||||
%li
|
||||
= link_to bulk_pets_path do
|
||||
= image_tag 'http://images.neopets.com/items/mall_ac_garland_spotlight.gif'
|
||||
= image_tag camo_image_url('http://images.neopets.com/items/mall_ac_garland_spotlight.gif')
|
||||
%h3= link_to t('modeling_hub'), bulk_pets_path
|
||||
%div
|
||||
%h4= t '.modeling_hub.tagline'
|
||||
|
@ -108,7 +108,7 @@
|
|||
- @newest_unmodeled_items.each do |item|
|
||||
- localized_cache "items/#{item.id} modeling_progress updated_at=#{item.updated_at.to_i}" do
|
||||
%li{'data-item-id' => item.id}
|
||||
= link_to image_tag(item.thumbnail_url), item, :class => 'image-link'
|
||||
= link_to image_tag(item.thumbnail.secure_url), item, :class => 'image-link'
|
||||
= link_to item, :class => 'header' do
|
||||
%h2= item.name
|
||||
%span.meter{style: "width: #{@newest_unmodeled_items_predicted_modeled_ratio[item]*100}%"}
|
||||
|
@ -121,7 +121,7 @@
|
|||
- @newest_modeled_items.each do |item|
|
||||
%li.object
|
||||
= link_to item, title: item.name, alt: item.name do
|
||||
= image_tag item.thumbnail_url
|
||||
= image_tag item.thumbnail.secure_url
|
||||
= nc_icon_for(item)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue