openquestions-1.0.x-dev/js/openquestions_voting.js

js/openquestions_voting.js
/**
 * @file
 *
 */

/**
 */
(function ($, Drupal, drupalSettings) {

  'use strict';

  function rot13(text) {
    var ret = text.replace(/[A-Za-z]/g, function (c) {
      return String.fromCharCode(c.charCodeAt(0) + (c.toUpperCase() <= "M" ? 13 : -13 ));
    });
    return ret;
  }

  Drupal.behaviors.openquestions_voting = {
    attach: function (context, settings) {
      $(once('text-counter', '.js-text-counter', context)).each(function () {
        var options = {
          type: 'word',
          min: '10',
        };
        $(this).textcounter(options);
      });

      $(once('application-description', '.application-description', context)).each(function () {
        var $t = $(this);
        $t.find('span').hide();
        var btn = $('<button/>').text('Click to read').on('click', function (event) {
          var text = $(this).parent().find('.application-description').find('span').text();
          text = rot13(text);
          var $dlg = $('<div/>');
          $dlg.text(text);
          $dlg.appendTo('body');
          Drupal.dialog($dlg, {
            title: 'Application text',
            buttons: [{
              text: 'Close',
              click: function () {
                $(this).dialog('close');
              }
            }]
          }).showModal();
          event.stopPropagation();
          return false;
        });
        $t.after(btn);
      });

      $('.oq_voteable', context).on('click', function (event) {
        var $t = $(this);
        var item_id = $t.data('item_id');
        var question_id = $t.data('question_id');
        var uid = $t.data('uid');
        event.stopPropagation();
        return false;
      });
    }
  };
})(jQuery, Drupal, drupalSettings);

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc