Rails 3:将布局图像替换为 Flash 动画

发布于 2024-10-17 01:54:47 字数 2029 浏览 6 评论 0原文

所以我有一个助手,我用它来将我的标题图像交换为另一个似乎工作正常的图像。这是我的帮手。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朮生 2024-10-24 01:54:47

在进行一些挖掘时,对于那些将来可能遇到此问题并希望在自己的网站上实现它的人来说,这就是我发现的并且效果很好。

基本上,您需要向 sanitize 添加一组标签和一组属性,因为 sanitize 仅使用基本的 html,它缺少一些东西,例如 Flash 非常需要的元素。

这是我在助手中所做的:

  def text_banner_tag
    @text_banner ||= '<img src="/images/textBanner.png">'
      tags = %w(a acronym b strong i img em li ul ol h1 h2 h3 h4 h5 h6 object param div blockquote br cite sub sup ins p)
      sanitize(@text_banner, :tags => tags, :attributes => %w(href classid title width height id alt data name value src))
  end

  def text_banner(object_code)
    @text_banner = object_code
  end

在布局中使用以下方式调用横幅:

<%= text_banner_tag %>

在您想要显示 Flash 横幅的视图中,将其添加到视图的顶部:

<% text_banner('<object> <param> <div>text for no flash</div> </object>') %>

请务必填写您需要的所有内容对于 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:

  def text_banner_tag
    @text_banner ||= '<img src="/images/textBanner.png">'
      tags = %w(a acronym b strong i img em li ul ol h1 h2 h3 h4 h5 h6 object param div blockquote br cite sub sup ins p)
      sanitize(@text_banner, :tags => tags, :attributes => %w(href classid title width height id alt data name value src))
  end

  def text_banner(object_code)
    @text_banner = object_code
  end

In the layout you call the banner using:

<%= text_banner_tag %>

And in the view that you'd like to display the flash banner for you add this to the top of the view:

<% text_banner('<object> <param> <div>text for no flash</div> </object>') %>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文