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();
|
Neopia.init();
|
||||||
this._createItems($);
|
this._createItems($);
|
||||||
var usersEl = $('#modeling-neopets-users');
|
var usersEl = $('#modeling-neopets-users');
|
||||||
|
if (usersEl.length) {
|
||||||
this._usersComponent = React.renderComponent(<NeopetsUsernamesForm />,
|
this._usersComponent = React.renderComponent(<NeopetsUsernamesForm />,
|
||||||
usersEl.get(0));
|
usersEl.get(0));
|
||||||
var usernames = ImpressUser.getNeopetsUsernames();
|
var usernames = ImpressUser.getNeopetsUsernames();
|
||||||
usernames.forEach(this._registerUsername.bind(this));
|
usernames.forEach(this._registerUsername.bind(this));
|
||||||
this._updateUsernames();
|
this._updateUsernames();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
model: function(neopiaPetId, itemId) {
|
model: function(neopiaPetId, itemId) {
|
||||||
var oldCustomization = this._customizationsByPetId[neopiaPetId];
|
var oldCustomization = this._customizationsByPetId[neopiaPetId];
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
var disqus_shortname = 'dresstoimpress';
|
|
||||||
|
|
||||||
(function () { // don't need to export anything in here
|
(function () { // don't need to export anything in here
|
||||||
|
|
||||||
var preview_el = $('#pet-preview'),
|
var preview_el = $('#pet-preview'),
|
||||||
|
@ -44,14 +42,18 @@ var Preview = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadNotable() {
|
function loadNotable() {
|
||||||
$.getJSON('http://notables.openneo.net/api/1/days/ago/1?callback=?', function (response) {
|
// TODO: add HTTPS to notables
|
||||||
var notables = response.notables;
|
// $.getJSON('http://notables.openneo.net/api/1/days/ago/1?callback=?', function (response) {
|
||||||
var i = Math.floor(Math.random() * notables.length);
|
// var notables = response.notables;
|
||||||
Preview.Job.fallback = new Preview.Job.Name(notables[i].petName);
|
// 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) {
|
if(!Preview.Job.current) {
|
||||||
Preview.Job.fallback.setAsCurrent();
|
Preview.Job.fallback.setAsCurrent();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFeature() {
|
function loadFeature() {
|
||||||
|
@ -78,6 +80,7 @@ Preview.Job = function (key, base) {
|
||||||
function getImageSrc() {
|
function getImageSrc() {
|
||||||
if (key.substr(0, 3) === 'a:-') {
|
if (key.substr(0, 3) === 'a:-') {
|
||||||
// lol lazy code for prank image :P
|
// lol lazy code for prank image :P
|
||||||
|
// TODO: HTTPS?
|
||||||
return "http://swfimages.impress.openneo.net" +
|
return "http://swfimages.impress.openneo.net" +
|
||||||
"/biology/000/000/0-2/" + key.substr(2) + "/300x300.png";
|
"/biology/000/000/0-2/" + key.substr(2) + "/300x300.png";
|
||||||
} else if (base === 'cp' || base === 'cpn') {
|
} else if (base === 'cp' || base === 'cpn') {
|
||||||
|
@ -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=([^&]+)/);
|
var neopiaError = document.location.search.match(/neopia%5Berror%5D=([^&]+)/);
|
||||||
if (neopiaError !== null) {
|
if (neopiaError !== null) {
|
||||||
|
@ -305,11 +247,6 @@ $(function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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();
|
$('#latest-contribution-created-at').timeago();
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
|
@ -216,17 +216,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def camo_image_url(image_url)
|
def camo_image_url(image_url)
|
||||||
if CAMO_KEY
|
Image.from_insecure_url(image_url).secure_url
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ module ContributionHelper
|
||||||
:item_link => link)
|
:item_link => link)
|
||||||
output = translate("contributions.contributed_description.main.#{main_key}_html",
|
output = translate("contributions.contributed_description.main.#{main_key}_html",
|
||||||
:item_description => description)
|
:item_description => description)
|
||||||
output << image_tag(item.thumbnail_url) if show_image
|
output << image_tag(item.thumbnail.secure_url) if show_image
|
||||||
output
|
output
|
||||||
else
|
else
|
||||||
translate('contributions.contributed_description.parents.item.blank')
|
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
|
modeled_body_ids.size.to_f / predicted_body_ids.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def thumbnail
|
||||||
|
@thumbnail ||= Image.from_insecure_url(thumbnail_url)
|
||||||
|
end
|
||||||
|
|
||||||
def as_json(options={})
|
def as_json(options={})
|
||||||
json = {
|
json = {
|
||||||
:description => description,
|
:description => description,
|
||||||
:id => id,
|
:id => id,
|
||||||
:name => name,
|
:name => name,
|
||||||
:thumbnail_url => thumbnail_url,
|
:thumbnail_url => thumbnail.secure_url,
|
||||||
:zones_restrict => zones_restrict,
|
:zones_restrict => zones_restrict,
|
||||||
:rarity_index => rarity_index,
|
:rarity_index => rarity_index,
|
||||||
:nc => nc?
|
:nc => nc?
|
||||||
|
|
|
@ -5,7 +5,7 @@ class Item
|
||||||
attr_reader :id
|
attr_reader :id
|
||||||
attr_writer :item, :owned, :wanted
|
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
|
def self.model_name
|
||||||
Item.model_name
|
Item.model_name
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= link_to item_path(item) do
|
= 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
|
%span.name= item.name
|
||||||
= nc_icon_for(item)
|
= nc_icon_for(item)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
- localized_cache "items/#{@item.id} header" do
|
- localized_cache "items/#{@item.id} header" do
|
||||||
%header#item-header
|
%header#item-header
|
||||||
= image_tag @item.thumbnail_url, :id => 'item-thumbnail'
|
= image_tag @item.thumbnail.secure_url, :id => 'item-thumbnail'
|
||||||
%div
|
%div
|
||||||
%h2#item-name= @item.name
|
%h2#item-name= @item.name
|
||||||
= nc_icon_for(@item)
|
= nc_icon_for(@item)
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
|
|
||||||
%li
|
%li
|
||||||
= link_to bulk_pets_path do
|
= 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
|
%h3= link_to t('modeling_hub'), bulk_pets_path
|
||||||
%div
|
%div
|
||||||
%h4= t '.modeling_hub.tagline'
|
%h4= t '.modeling_hub.tagline'
|
||||||
|
@ -108,7 +108,7 @@
|
||||||
- @newest_unmodeled_items.each do |item|
|
- @newest_unmodeled_items.each do |item|
|
||||||
- localized_cache "items/#{item.id} modeling_progress updated_at=#{item.updated_at.to_i}" do
|
- localized_cache "items/#{item.id} modeling_progress updated_at=#{item.updated_at.to_i}" do
|
||||||
%li{'data-item-id' => item.id}
|
%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
|
= link_to item, :class => 'header' do
|
||||||
%h2= item.name
|
%h2= item.name
|
||||||
%span.meter{style: "width: #{@newest_unmodeled_items_predicted_modeled_ratio[item]*100}%"}
|
%span.meter{style: "width: #{@newest_unmodeled_items_predicted_modeled_ratio[item]*100}%"}
|
||||||
|
@ -121,7 +121,7 @@
|
||||||
- @newest_modeled_items.each do |item|
|
- @newest_modeled_items.each do |item|
|
||||||
%li.object
|
%li.object
|
||||||
= link_to item, title: item.name, alt: item.name do
|
= 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)
|
= nc_icon_for(item)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue