Rails 3:将布局图像替换为 Flash 动画
所以我有一个助手,我用它来将我的标题图像交换为另一个似乎工作正常的图像。这是我的帮手。
def header_image_tag
@header_image ||= 'headers/image.png'
image_tag @header_image
end
def header_image(image_path)
@header_image = image_path
end
在我看来我使用。
<% header_image('headers/newimage.png') %>
现在这里是棘手的部分,我想要做的不是用我想在 Flash 横幅中交换的图片替换它。
我尝试通过交换代码而不是使用 sanitize 来做到这一点(它只是不使用对象标签)。下面首先是我的帮助者...
def text_banner_tag
@text_banner ||= 'textBanner.png'
if @text_banner != "textBanner.png"
else
image_tag @text_banner
end
end
def text_banner(object_code)
@text_banner = object_code
end
以及我认为的代码...
<% text_banner(sanitize('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="970" height="48" id="FlashID" title="textbanner" alt="text banner">
<param name="movie" value="/flash/textbanner.swf">
<param name="quality" value="high">
<param name="wmode" value="transparent">
<param name="swfversion" value="6.0.65.0">
<!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="/flash/textbanner.swf" width="970" height="48">
<!--<![endif]-->
<param name="quality" value="high">
<param name="wmode" value="transparent">
<param name="swfversion" value="6.0.65.0">
<param name="expressinstall" value="/Scripts/expressInstall.swf">
<!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
<div>
<%= image_tag("textBanner.png", :size => "970x48", :alt => "text banner", :border => "0") %>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>')) %>
任何和所有帮助将不胜感激!
So I have a helper that I'm using to swap my header image for another image that seems to work fine. This is my helper.
def header_image_tag
@header_image ||= 'headers/image.png'
image_tag @header_image
end
def header_image(image_path)
@header_image = image_path
end
And in my View I use.
<% header_image('headers/newimage.png') %>
Now here is the tricky part, what I'd like to do, is instead of replacing it with a picture I'd like to swap in a flash banner.
I tried to do it by swapping in code instead using sanitize (which works just not using object tags). Below is first my helper for this...
def text_banner_tag
@text_banner ||= 'textBanner.png'
if @text_banner != "textBanner.png"
else
image_tag @text_banner
end
end
def text_banner(object_code)
@text_banner = object_code
end
and the code in my view...
<% text_banner(sanitize('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="970" height="48" id="FlashID" title="textbanner" alt="text banner">
<param name="movie" value="/flash/textbanner.swf">
<param name="quality" value="high">
<param name="wmode" value="transparent">
<param name="swfversion" value="6.0.65.0">
<!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="/flash/textbanner.swf" width="970" height="48">
<!--<![endif]-->
<param name="quality" value="high">
<param name="wmode" value="transparent">
<param name="swfversion" value="6.0.65.0">
<param name="expressinstall" value="/Scripts/expressInstall.swf">
<!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
<div>
<%= image_tag("textBanner.png", :size => "970x48", :alt => "text banner", :border => "0") %>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>')) %>
Any and all help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在进行一些挖掘时,对于那些将来可能遇到此问题并希望在自己的网站上实现它的人来说,这就是我发现的并且效果很好。
基本上,您需要向 sanitize 添加一组标签和一组属性,因为 sanitize 仅使用基本的 html,它缺少一些东西,例如 Flash 非常需要的元素。
这是我在助手中所做的:
在布局中使用以下方式调用横幅:
在您想要显示 Flash 横幅的视图中,将其添加到视图的顶部:
请务必填写您需要的所有内容对于 Flash 对象。
您还可以使用它来实现许多其他附加功能
安全警告,如果您将此用法分发给填写允许使用代码的表单的用户,请务必小心。
In doing some digging around, for those that might come across this in the future and want to implement it on their own site, this is what I found and works great.
Basically you need to ad a set of tags and a set of attributes to the sanitize as sanitize only uses basic html its missing things like which are much needed elements for flash.
Here's what I did in the helper:
In the layout you call the banner using:
And in the view that you'd like to display the flash banner for you add this to the top of the view:
be sure to fill in everything you need for the flash object.
You can also use this to implement lots of other extras
Security Warning just be careful if your handing this usage out to users that are filling in forms that allow for code.