javascript - 从 jquery 转换为原型(prototype)

标签 javascript jquery prototypejs

我有以下 jquery 我想转换为原型(prototype)。我在让它工作时遇到了一些真正的麻烦,因为我不知道如何在 Rails 应用程序中正确初始化它。

$(document).ready(function(){
    /*** Search label  ***/
    htmlinput = $("input#panel-search").val() /* picks the inital value of the input (in the html) */
    $("input#panel-search").css('color','#aeaeae').css('font-style','italic').css('font-weight','bold');
    $("input#panel-search").focus(function(){ /* on focus.. */
        curinput = $(this).val() /* picks the -current- value */
        if(curinput == htmlinput){ /* if the current value corrispond to the initial value (htmlinput var) */
            $(this).val(''); /* empty the input */
            $(this).css('color','black').css('font-style', 'normal').css('font-weight','normal');
        }
    });
    $("input#panel-search").blur(function(){ /* on blur */
        curinput = $(this).val();
        if(curinput == ''){ /* if the current value is null .. */
            $(this).css('color','#aeaeae').css('font-style','italic').css('font-weight','bold');
            $(this).val(htmlinput); /* sets the value with its inital value (htmlinput var) */
        }
    })    

    /* Main Navigation hover effect */
    $("ul#navigation li:not('.current'), ul#navigation li:not('highlighted')").hover(
      function () {
        $(this).addClass("hover");
      }, 
      function () {
        $(this).removeClass("hover");
      }
    );

    /* Right Menu hover effect */
    $("ul#fast-links li:not('.current')").hover(
      function () {
        $(this).addClass("current");
      }, 
      function () {
        $(this).removeClass("current");
      }
    );
});

任何帮助将不胜感激。

最佳答案

Event.observe(document, 'ready', function () {
    /* pick the inital value of the input (in the html) */
    var $htmlinput = $('input#panel-search');
    var originalValue = $htmlinput.getValue();
    /* Set styles */
    $htmlinput.setStyle({
        color: '#aeaeae',
        'font-weight': 'bold',
        'font-style': 'italic'
    });
    /* on focus.. */
    $htmlinput.observe('focus', function () {
        /* pick the -current- value */
        var $input = $(this);
        /* Clear the input element if the value hasn't changed from
           the original value */
        if($input.getValue() === originalValue) {
           $input.clear();
           $input.setStyle({
              'color': 'black',
              'font-style': 'normal',
              'font-weight','normal'
           });
        }
    });
    $htmlinput.observe('blur', function () {
       /* CHANGE THIS SIMILAR TO ABOVE */
       /* INSIDE IF-CASE */
       $(this).setValue(originalValue);
    });
}
/* Main Navigation hover effect */
/* Prototype doesn't have the fancy :not pseudo-selector, so iterate over
 * all li:s, and filter out the once that shouldn't be affected */
$('ul#navigation li').each(function (el) {
   var isCurrent = el.hasClassName('current'),
       isHighlighted = el.hasClassName('highlighted');
   if(isCurrent || isHighlighted) {
      return;
   }
   el.observe('mouseenter', function () {
      $(this).addClassName('hover');
   });
   el.observe('mouseleave', function () {
      $(this).removeClassName('hover');
   });
});
/* TRANSLATE THE RIGHT NAVIGATION IN THE SAME WAY */

关于javascript - 从 jquery 转换为原型(prototype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1836556/

相关文章:

javascript - 选中复选框后滚动时如何在页面底部粘贴一个div

Javascript,jQuery : Change a certain word of a div into a <span> with a function

jquery - 如何阻止 jQuery UI 选项卡内的 SWF 重新加载

javascript - 在 script.aculo.us 中传递动态参数

prototypejs - 压缩/缩小原型(prototype)文件

javascript - 仅定位此轮播,同一页面上有多个轮播

javascript - app.get 和 router.get 之间的区别(Express)

javascript - 使用 jQuery 查找当前可见元素并更新导航

javascript - 我使用 css zIndex 的简单 jquery 幻灯片无法正常工作

javascript - PrototypeJS 中的委托(delegate)()