forked from a64f7bb4-7358-4778-9fbe-3b882c34cc1d/v1
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
/**
|
|
* @file
|
|
* Attaches is useful rating.
|
|
*/
|
|
|
|
(function ($, Drupal) {
|
|
Drupal.behaviors.usefulRating = {
|
|
attach: function (context, settings) {
|
|
$('body').find('.useful').each(function () {
|
|
var $this = $(this);
|
|
$(this).find('select').once('processed').each(function () {
|
|
$this.find('[type=submit]').hide();
|
|
var $select = $(this);
|
|
var isPreview = $select.data('is-edit');
|
|
$select.after('<div class="useful-rating"><a href="#"><i class="fa fa-thumbs-down"></i></a><a href="#"><i class="fa fa-thumbs-up"></a></i></div>').hide();
|
|
$this.find('.useful-rating a').eq(0).each(function () {
|
|
$(this).bind('click',function (e) {
|
|
if (isPreview) {
|
|
return;
|
|
}
|
|
e.preventDefault();
|
|
$select.get(0).selectedIndex = 0;
|
|
$this.find('[type=submit]').trigger('click');
|
|
$this.find('a').addClass('disabled');
|
|
$this.find('.vote-result').html();
|
|
})
|
|
})
|
|
$this.find('.useful-rating a').eq(1).each(function () {
|
|
$(this).bind('click',function (e) {
|
|
if (isPreview) {
|
|
return;
|
|
}
|
|
e.preventDefault();
|
|
$select.get(0).selectedIndex = 1;
|
|
$this.find('[type=submit]').trigger('click');
|
|
$this.find('a').addClass('disabled');
|
|
$this.find('.vote-result').html();
|
|
})
|
|
})
|
|
})
|
|
});
|
|
}
|
|
};
|
|
})(jQuery, Drupal);
|