首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使Fivestar 7.x-2.2移动友好

使Fivestar 7.x-2.2移动友好
EN

Stack Overflow用户
提问于 2017-11-01 17:20:48
回答 1查看 38关注 0票数 0

我使用的是Fivestar 2.2模块。一切都很好,但在触摸屏上投票就不行了:在一个5星的小工具上给5星是不可能的,即使它在桌面上工作得很好。不幸的是,我不被允许提供链接。

有人已经解决这个问题了吗?Drupal.org不是一个好帮手。

代码语言:javascript
复制
/**
* @file
*
* Fivestar JavaScript behaviors integration.
*/

/**
* Create a degradeable star rating interface out of a simple form structure.
*
* Originally based on the Star Rating jQuery plugin by Wil Stuckey:
* http://sandbox.wilstuckey.com/jquery-ratings/
*/
(function($){ // Create local scope.

Drupal.behaviors.fivestar = {
attach: function (context) {
$(context).find('div.fivestar-form-item').once('fivestar', function() {
  var $this = $(this);
  var $container = $('<div class="fivestar-widget clearfix"></div>');
  var $select = $('select', $this);

  // Setup the cancel button
  var $cancel = $('option[value="0"]', $this);
  if ($cancel.length) {
    $('<div class="cancel"><a href="#0" title="' + $cancel.text() + '">' + $cancel.text() + '</a></div>')
      .appendTo($container);
  }

  // Setup the rating buttons
  var $options = $('option', $this).not('[value="-"], [value="0"]');
  var index = -1;
  $options.each(function(i, element) {
    var classes = 'star-' + (i+1);
    classes += (i + 1) % 2 == 0 ? ' even' : ' odd';
    classes += i == 0 ? ' star-first' : '';
    classes += i + 1 == $options.length ? ' star-last' : '';
    $('<div class="star"><a href="#' + element.value + '" title="' + element.text + '">' + element.text + '</a></div>')
      .addClass(classes)
      .appendTo($container);
    if (element.value == $select.val()) {
      index = i + 1;
    }
  });

  if (index != -1) {
    $container.find('.star').slice(0, index).addClass('on');
  }
  $container.addClass('fivestar-widget-' + ($options.length));
  $container.find('a')
    .bind('click', $this, Drupal.behaviors.fivestar.rate)
    .bind('mouseover', $this, Drupal.behaviors.fivestar.hover);

  $container.bind('mouseover mouseout', $this, Drupal.behaviors.fivestar.hover);

  // Attach the new widget and hide the existing widget.
  $select.after($container).css('display', 'none');

  // Allow other modules to modify the widget.
  Drupal.attachBehaviors($this);
});
},
rate: function(event) {
var $this = $(this);
var $widget = event.data;
var value = this.hash.replace('#', '');
$('select', $widget).val(value).change();
var $this_star = (value == 0) ? $this.parent().parent().find('.star') : 
$this.closest('.star');
$this_star.prevAll('.star').andSelf().addClass('on');
$this_star.nextAll('.star').removeClass('on');
if(value==0){
  $this_star.removeClass('on');
}

event.preventDefault();
},
hover: function(event) {
var $this = $(this);
var $widget = event.data;
var $target = $(event.target);
var $stars = $('.star', $this);

if (event.type == 'mouseover') {
  var index = $stars.index($target.parent());
  $stars.each(function(i, element) {
    if (i <= index) {
      $(element).addClass('hover');
    } else {
      $(element).removeClass('hover');
    }
  });
} else {
  $stars.removeClass('hover');
}
}
};
})(jQuery);
EN

回答 1

Stack Overflow用户

发布于 2017-11-06 00:01:59

如果这不是您想要的,很抱歉。我会尽力帮助您的。别用五星,我也遇到过同样的情况。我建议您尝试一下费率模块(https://www.drupal.org/project/rate),我认为它是一个更完整的解决方案。

我有一个响应式的网站,当然可以与移动设备一起工作,你可以毫无问题地投票,尽管我不能保证它是移动就绪的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47051622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档