Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

close #453, uploaded photo in product body_html should use absolute url.

  • Loading branch information...
commit da220b8bb593e01e7694cc0a26a947c63110e1a8 1 parent df886e0
@saberma authored
View
14 app/admin/shops.rb
@@ -49,7 +49,7 @@
collection_action :state do # 系统运行状态
begin 'libxml2' # issues#274
- html_path = Rails.root.join "spec/factories/data/themes/settings_with_class.html"
+ html_path = Rails.root.join "spec/factories/data/themes/settings/with_class.html"
settings = Nokogiri::HTML(File.open(html_path), nil, 'utf-8').inner_html
@libxml2 = !settings.blank?
end
@@ -71,18 +71,16 @@
@theme = Theme.first
end
begin 'shop' # 商店
- asset_host = ActionController::Base.asset_host # 可能为Proc对象
- asset_host_for_shop = asset_host.respond_to?(:call) ? asset_host.call : asset_host
- @shop_global_js = "#{asset_host_for_shop}/s/global/jquery/1.5.2/jquery.js"
- @shop_shopqi_js = "#{asset_host_for_shop}/s/shopqi/option_selection.js"
+ @shop_global_js = "#{asset_host}/s/global/jquery/1.5.2/jquery.js"
+ @shop_shopqi_js = "#{asset_host}/s/shopqi/option_selection.js"
@shop = Shop.where(email: 'admin@shopqi.com', :id.lt => 10).order('id asc').first
if @shop
theme = @shop.themes.where(name: '乔木林地').first
if theme
- @shop_shop_css = "#{asset_host_for_shop}#{theme.asset_url('stylesheet.css')}"
- @shop_shop_js = "#{asset_host_for_shop}#{theme.asset_url('fancybox.js')}"
+ @shop_shop_css = "#{asset_host}#{theme.asset_url('stylesheet.css')}"
+ @shop_shop_js = "#{asset_host}#{theme.asset_url('fancybox.js')}"
end
- @shop_product_photo = @shop.products.first.try(:index_photo)
+ @shop_product_photo = @shop.products.last.try(:index_photo)
end
end
begin 'server' # 服务器
View
2  app/controllers/admin/kindeditor_controller.rb
@@ -6,7 +6,7 @@ class Admin::KindeditorController < Admin::AppController
def upload_image
@image = shop.kindeditors.build(kindeditor_image: params[:imgFile])
if @image.save
- render text: {error: 0, url: @image.kindeditor_image.url}.to_json
+ render text: {error: 0, url: @image.url}.to_json
else
render text: {error: 1, message: @image.errors.full_messages.join(',')}.to_json
end
View
2  app/helpers/admin/app_helper.rb
@@ -17,7 +17,7 @@ def link_to_delete(path)
def use_kindeditor
content_for :kindeditor do
%Q(
- <script src="/javascripts/kindeditor/kindeditor.js?1" type="text/javascript"></script>
+ <script src="/javascripts/kindeditor/kindeditor-min.js?2" type="text/javascript"></script>
<script src="/javascripts/kindeditor/kindeditor_config.js?1" type="text/javascript"></script>
).html_safe
end
View
11 app/liquids/url_filter.rb
@@ -2,7 +2,7 @@ module UrlFilter
def asset_url(input)
shop = @context['shop'] #ShopDrop
- "#{asset_host_for_shop}#{shop.asset_url(input)}"
+ "#{asset_host}#{shop.asset_url(input)}"
end
def global_asset_url(input)
@@ -15,17 +15,12 @@ def shopqi_asset_url(input)
def product_img_url(photo, size)
url = photo ? photo.version(size) : "/assets/admin/no-image-#{size}.gif"
- "#{asset_host_for_shop}#{url}"
+ "#{asset_host}#{url}"
end
private
def add_mtime(input) # 加入修改时间querysting
- "#{asset_host_for_shop}/#{input}?#{File.mtime(Rails.root.join('public', input)).to_i}"
- end
-
- def asset_host_for_shop
- asset_host = ActionController::Base.asset_host # 可能为Proc对象
- asset_host.respond_to?(:call) ? asset_host.call : asset_host
+ "#{asset_host}/#{input}?#{File.mtime(Rails.root.join('public', input)).to_i}"
end
end
View
4 app/models/kindeditor.rb
@@ -14,4 +14,8 @@ class Kindeditor < ActiveRecord::Base
validates_with StorageValidator
validates_property :mime_type, of: :kindeditor_image, in: %w(image/jpeg image/jpg image/png image/gif), message: "格式不正确"
+
+ def url
+ "#{asset_host}#{kindeditor_image.url}"
+ end
end
View
6 config/environments/development.rb
@@ -23,9 +23,9 @@
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
- #config.action_controller.asset_host = Proc.new { |source|
- # "//cdn.lvh.me"
- #}
+ config.action_controller.asset_host = Proc.new { |source|
+ "//cdn.lvh.me#{Setting.domain.port}"
+ }
# Do not compress assets
config.assets.compress = false
View
6 config/initializers/add_method_to_ruby.rb
@@ -28,3 +28,9 @@ def smart_fetch(name, options = {}, &blk)
return val
end
end
+
+# cdn 域名地址
+def asset_host
+ host = ActionController::Base.asset_host # 可能为Proc对象
+ host.respond_to?(:call) ? host.call : host
+end
View
4 public/javascripts/kindeditor/kindeditor-min.js
@@ -32,7 +32,7 @@ g,d);h.setStart(n,0)}else if(n==k){n=e.wrapTextNode(n,0,l,g,d);h.setEnd(n,n.node
b);return{left:d,right:b}};this.remove=function(b){var d=this.keRange,e=d.startNode,g=d.startPos,h=d.endNode,i=d.endPos;this.keSel.focus();if(!c.util.inMarquee(d.getParentElement())){var j=d.getText().replace(/\s+/g,"")==="";if(!(j&&!c.browser.IE)){var k=[];c.each(b,function(q){q!="*"&&k.push(q)});var l=this.getTopParent(k,e),o=this.getTopParent(k,h);if(l){var p=this.splitNodeParent(l,e,g);d.setStart(p.right,0);if(e==h&&c.util.getNodeTextLength(p.right)>0){d.selectNode(p.right);e=new c.range(this.doc);
e.selectTextNode(p.left);if(g>0)i-=e.endNode.nodeValue.length;e.selectTextNode(p.right);h=e.startNode}}if(j){l=d.startNode;if(l.nodeType==1){if(l.nodeName.toLowerCase()=="br")return;d.selectNode(l)}else return}else if(o){g=this.splitNodeParent(o,h,i);d.setEnd(g.left,0);l==o&&d.setStart(g.left,0)}o=function(q,t){if(t.charAt(0)=="."){var m=c.util.getJsKey(t.substr(1));q.style[m]=""}else{if(c.browser.IE&&c.browser.VERSION<8&&t=="class")t="className";q.removeAttribute(t)}};g=d.getNodeList();d.setTextStart(d.startNode,
d.startPos);d.setTextEnd(d.endNode,d.endPos);i=0;for(j=g.length;i<j;i++){l=g[i];if(l.nodeType==1){p=l.tagName.toLowerCase();if(b[p]){p=b[p];e=0;for(h=p.length;e<h;e++)if(p[e]=="*"){c.util.removeParent(l);break}else{o(l,p[e]);var n=[];if(l.outerHTML){attrHash=c.util.getAttrList(l.outerHTML);c.each(attrHash,function(q,t){n.push({name:q,value:t})})}else n=l.attributes;if(n.length==0){c.util.removeParent(l);break}else if(n[0].name=="style"&&n[0].value===""){c.util.removeParent(l);break}}}if(b["*"]){p=
-b["*"];e=0;for(h=p.length;e<h;e++)o(l,p[e])}}}try{this.keSel.addRange(d)}catch(r){}}}}};c.format={getUrl:function(a,b,d,e){if(!b)return a;b=b.toLowerCase();if(!c.util.inArray(b,["absolute","relative","domain"]))return a;d=d||location.protocol+"//"+location.host;if(e===f){var g=location.pathname.match(/^(\/.*)\//);e=g?g[1]:""}if(g=a.match(/^(\w+:\/\/[^\/]*)/)){if(g[1]!==d)return a}else if(a.match(/^\w+:/))return a;g=function(i){i=i.split("/");paths=[];for(var j=0,k=i.length;j<k;j++){var l=i[j];if(l==
+b["*"];e=0;for(h=p.length;e<h;e++)o(l,p[e])}}}try{this.keSel.addRange(d)}catch(r){}}}}};c.format={getUrl:function(a,b,d,e){if(!b)return a;b=b.toLowerCase();if(!c.util.inArray(b,["absolute","relative","domain"]))return a;d=d||location.protocol+"//"+location.host;if(e===f){var g=location.pathname.match(/^(\/.*)\//);e=g?g[1]:""}if(g=a.match(/^((\w+:){0,1}\/\/[^\/]*)/)){if(g[1]!==d)return a}else if(a.match(/^\w+:/))return a;g=function(i){i=i.split("/");paths=[];for(var j=0,k=i.length;j<k;j++){var l=i[j];if(l==
"..")paths.length>0&&paths.pop();else l!==""&&l!="."&&paths.push(l)}return"/"+paths.join("/")};if(a.match(/^\//))a=d+g(a.substr(1));else a.match(/^\w+:\/\//)||(a=d+g(e+"/"+a));if(b=="relative"){var h=function(i,j){if(a.substr(0,i.length)===i){for(var k=[],l=0;l<j;l++)k.push("..");l=".";if(k.length>0)l+="/"+k.join("/");if(e=="/")l+="/";return l+a.substr(i.length)}else if(k=i.match(/^(.*)\//))return h(k[1],++j)};a=h(d+e,0).substr(2)}else if(b=="absolute")if(a.substr(0,d.length)===d)a=a.substr(d.length);
return a},getHtml:function(a,b,d){var e=b?true:false;a=a.replace(/(<pre[^>]*>)([\s\S]*?)(<\/pre>)/ig,function(p,n,r,q){return n+r.replace(/<br[^>]*>/ig,"\n")+q});var g={},h=["xx-small","x-small","small","medium","large","x-large","xx-large"];e&&c.each(b,function(p,n){for(var r=p.split(","),q=0,t=r.length;q<t;q++)g[r[q]]=c.util.arrayToHash(n)});var i=false,j=c.util.arrayToHash(c.setting.noEndTags);c.util.arrayToHash(c.setting.inlineTags);var k=c.util.arrayToHash(c.setting.endlineTags);a=a.replace(/((?:\r\n|\n|\r)*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:]+="[^"]*")|(?:\s+[\w\-:]+='[^']*'))*)(\/)?>((?:\r\n|\n|\r)*)/g,
function(p,n,r,q,t,m,v){n=n||"";r=r||"";var s=q.toLowerCase();q=t||"";m=m?" "+m:"";v=v||"";if(s==="script"&&r!=="")i=false;if(i)return p;if(s==="script"&&r==="")i=true;if(e&&typeof g[s]=="undefined")return"";if(m===""&&typeof j[s]!="undefined")m=" /";if(s in k){if(r||m)v="\n"}else if(v)v=" ";if(s!=="script"&&s!=="style")n="";if(s==="font"){var x={},w="";q=q.replace(/\s*([\w\-:]+)=([^\s"'<>]+|"[^"]*"|'[^']*')/g,function(A,y,u){y=y.toLowerCase();u=u||"";u=u.replace(/^["']|["']$/g,"");if(y==="color"){x.color=
@@ -108,7 +108,7 @@ p.style.display="none";c.toolbar.disable(a,["source","fullscreen"]);c.toolbar.se
return false}}},a);c.event.add(y,"mousedown",d,a);c.event.add(y,"click",e,a);c.event.input(y,e,a);c.event.bind(r,"click",d,a);c.event.add(document,"click",d,a);c.event.add(A,"focus",g);c.event.add(r,"focus",g);c.event.add(A,"blur",h);c.event.add(r,"blur",h);c.g[a].toolbarTable=q;c.g[a].textareaTable=t;c.g[a].srcTextarea=k;c.g[a].bottom=m;c.g[a].hideDiv=v;c.g[a].maskDiv=w;c.g[a].iframeWin=A;c.g[a].iframeDoc=y;c.g[a].width=l;c.g[a].height=o;c.util.drag(a,s,n,function(z,B,C,D,E,F){if(c.g[a].resizeMode==
2)c.util.resize(a,C+F+"px",D+E+"px",true);else c.g[a].resizeMode==1&&c.util.resize(a,C+"px",D+E+"px",true,false)});c.util.drag(a,x,n,function(z,B,C,D,E){c.g[a].resizeMode>0&&c.util.resize(a,C+"px",D+E+"px",true,false)});c.each(c.plugin,function(z,B){B.init&&B.init(a)});c.g[a].getHtmlHooks.push(function(z){return z.replace(/(<[^>]*)kesrc="([^"]+)"([^>]*>)/ig,function(B,C,D){B=B.replace(/(\s+(?:href|src)=")[^"]+(")/i,"$1"+D+"$2");return B=B.replace(/\s+kesrc="[^"]+"/i,"")})});c.g[a].setHtmlHooks.push(function(z){return z.replace(/(<[^>]*)(href|src)="([^"]+)"([^>]*>)/ig,
function(B,C,D,E,F){if(B.match(/\skesrc="[^"]+"/i))return B;return C+D+'="'+E+'" kesrc="'+E+'"'+F})});c.util.addContextmenuEvent(a);c.util.addNewlineEvent(a);c.util.addTabEvent(a);c.event.input(y,i,a);c.event.add(y,"mouseup",i,a);c.event.add(document,"mousedown",i,a);c.onchange(a,function(z){if(c.g[z].autoSetDataMode||c.g[z].syncType=="auto"){c.util.setData(z);c.g[z].afterSetData&&c.g[z].afterSetData(z)}c.g[z].afterChange&&c.g[z].afterChange(z);c.history.add(z,c.g[z].minChangeSize)});c.browser.IE&&
-c.readonly(a,false);c.browser.IE&&c.browser.VERSION<8&&c.blur(a);c.util.setFullHtml(a,k.value);c.history.add(a,0);b>0&&c.util.focus(a);c.g[a].afterCreate&&c.g[a].afterCreate(a)}};c.onchange=function(a,b){function d(){b(a)}var e=c.g[a];e.onchangeHandlerStack.push(d);c.event.input(e.iframeDoc,d,a);c.event.input(e.newTextarea,d,a);c.event.add(e.iframeDoc,"mouseup",function(){window.setTimeout(function(){b(a)},0)},a)};c.init=function(a){var b=c.g[a.id]=a;b.config={};b.undoStack=[];b.redoStack=[];b.dialogStack=
+c.readonly(a,false);c.util.setFullHtml(a,k.value);c.history.add(a,0);b>0&&c.util.focus(a);c.g[a].afterCreate&&c.g[a].afterCreate(a)}};c.onchange=function(a,b){function d(){b(a)}var e=c.g[a];e.onchangeHandlerStack.push(d);c.event.input(e.iframeDoc,d,a);c.event.input(e.newTextarea,d,a);c.event.add(e.iframeDoc,"mouseup",function(){window.setTimeout(function(){b(a)},0)},a)};c.init=function(a){var b=c.g[a.id]=a;b.config={};b.undoStack=[];b.redoStack=[];b.dialogStack=
[];b.contextmenuItems=[];b.getHtmlHooks=[];b.setHtmlHooks=[];b.onchangeHandlerStack=[];b.eventStack=[];c.each(c.setting,function(d,e){b[d]=typeof a[d]=="undefined"?e:a[d];b.config[d]=b[d]});b.loadStyleMode&&c.util.loadStyle(b.skinsPath+b.skinType+".css")};c.show=function(a){c.init(a);c.event.ready(function(){c.create(a.id)})};if(window.KE===f)window.KE=c;window.KindEditor=c})();
(function(f){f.langType="zh_CN";f.lang={source:"HTML\u4ee3\u7801",undo:"\u540e\u9000(Ctrl+Z)",redo:"\u524d\u8fdb(Ctrl+Y)",cut:"\u526a\u5207(Ctrl+X)",copy:"\u590d\u5236(Ctrl+C)",paste:"\u7c98\u8d34(Ctrl+V)",plainpaste:"\u7c98\u8d34\u4e3a\u65e0\u683c\u5f0f\u6587\u672c",wordpaste:"\u4eceWord\u7c98\u8d34",selectall:"\u5168\u9009",justifyleft:"\u5de6\u5bf9\u9f50",justifycenter:"\u5c45\u4e2d",justifyright:"\u53f3\u5bf9\u9f50",justifyfull:"\u4e24\u7aef\u5bf9\u9f50",insertorderedlist:"\u7f16\u53f7",insertunorderedlist:"\u9879\u76ee\u7b26\u53f7",
indent:"\u589e\u52a0\u7f29\u8fdb",outdent:"\u51cf\u5c11\u7f29\u8fdb",subscript:"\u4e0b\u6807",superscript:"\u4e0a\u6807",title:"\u6807\u9898",fontname:"\u5b57\u4f53",fontsize:"\u6587\u5b57\u5927\u5c0f",textcolor:"\u6587\u5b57\u989c\u8272",bgcolor:"\u6587\u5b57\u80cc\u666f",bold:"\u7c97\u4f53(Ctrl+B)",italic:"\u659c\u4f53(Ctrl+I)",underline:"\u4e0b\u5212\u7ebf(Ctrl+U)",strikethrough:"\u5220\u9664\u7ebf",removeformat:"\u5220\u9664\u683c\u5f0f",image:"\u56fe\u7247",flash:"\u63d2\u5165Flash",media:"\u63d2\u5165\u591a\u5a92\u4f53",
View
4 public/javascripts/kindeditor/kindeditor.js
@@ -952,7 +952,7 @@ KE.format = {
var m = location.pathname.match(/^(\/.*)\//);
pathname = m ? m[1] : '';
}
- var matches = url.match(/^(\w+:\/\/[^\/]*)/);
+ var matches = url.match(/^((\w+:){0,1}\/\/[^\/]*)/); // 要支持 //cdn.exampel.com 格式(同步kindeditor.min),issues#453
if (matches) {
if (matches[1] !== host) return url;
} else if (url.match(/^\w+:/)) {
@@ -2942,7 +2942,7 @@ KE.create = function(id, mode) {
KE.history.add(id, KE.g[id].minChangeSize);
});
if (KE.browser.IE) KE.readonly(id, false);
- //if (KE.browser.IE && KE.browser.VERSION < 8) KE.blur(id); //后台管理商品详情会提示'控件不可见',issues#294
+ //if (KE.browser.IE && KE.browser.VERSION < 8) KE.blur(id); //后台管理商品详情会提示'控件不可见'(同步kindeditor.min),issues#294
KE.util.setFullHtml(id, srcTextarea.value);
KE.history.add(id, 0);
if (mode > 0) KE.util.focus(id);
View
13 spec/models/kindeditor_spec.rb
@@ -6,11 +6,20 @@
context '#create' do
+ let(:photo) do
+ model = shop.kindeditors.build
+ model.kindeditor_image = Rails.root.join('spec/factories/data/products/iphone4.jpg')
+ model
+ end
+
+ it "should get url" do
+ photo.save
+ photo.url.should eql "http:#{asset_host}#{photo.kindeditor_image.url}"
+ end
+
context 'shop storage is not idle' do # 容量已经用完
it "should be fail" do
- photo = shop.kindeditors.build
- photo.kindeditor_image = Rails.root.join('spec/factories/data/products/iphone4.jpg')
photo.shop.stub!(:storage_idle?) { false }
photo.save
photo.errors.full_messages.join(',').should_not be_blank
Please sign in to comment.
Something went wrong with that request. Please try again.