Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add some scripting

  • Loading branch information...
commit 18ddb7e41b615593dab7f3cf5ea38e2110d3a951 1 parent b7fced0
Benjamin Tambourine authored
4 blocks/b-page/b-page.deps.js
@@ -4,6 +4,10 @@
4 4 block: 'i-bem',
5 5 elem: 'dom',
6 6 mods: {'init': 'auto'}
  7 + },
  8 + {
  9 + blocks: 'i-bem',
  10 + elem: 'html'
7 11 }
8 12 ]
9 13 })
11 blocks/b-rating/b-rating.bemhtml
@@ -2,8 +2,15 @@ block b-rating {
2 2
3 3 tag: 'span'
4 4
5   - !this.mods.style, mix: [{
6   - mods: { style: 'stars' }
  5 + !this.mods.style, !this.elem, mix: [{
  6 + mods: {
  7 + style: 'stars',
  8 + frac: 2
  9 + }
  10 + }]
  11 +
  12 + this.ctx._frac, !this.elem, mix: [{
  13 + mods: { frac: this.ctx._frac }
7 14 }]
8 15
9 16 content: {
52 blocks/b-rating/b-rating.js
... ... @@ -1,15 +1,63 @@
1 1 BEM.DOM.decl('b-rating', {
2 2
3   - onSetMod : {
4   - 'js' : function() {
  3 + _onClick : function() {
  4 + if (!this.params.url) return;
5 5
  6 + var that = this;
  7 +
  8 + $.get(this.params.url, function(data) {
  9 + (typeof data.value == 'number') && that.setValue(data.value)
  10 +
  11 + }, 'json')
  12 + },
  13 +
  14 + setValue : function(value) {
  15 +/*
  16 + var mods = this.getMods(),
  17 + marks = [],
  18 + length = parseInt(mods.length),
  19 + frac = parseInt(mods.frac) || 1;
  20 +
  21 + for (var i = 0; i < length; i++) {
  22 + marks.push({
  23 + elem: 'mark',
  24 + elemMods: {
  25 + fill: (i >= value)
  26 + ? 'no'
  27 + : (i < Math.floor(value))
  28 + ? 'full'
  29 + : Math.round((value - Math.floor(value)) * frac)
  30 + }
  31 + })
  32 + }
  33 +*/
  34 +
  35 + var mods = this.getMods(),
  36 + marks = this.elem('mark'),
  37 + length = parseInt(mods.length),
  38 + frac = parseInt(mods.frac) || 1,
  39 + fill;
  40 +
  41 + for (var i = 0, l = marks.length; i < l; i++) {
  42 + fill = (i >= value)
  43 + ? 'no'
  44 + : (i < Math.floor(value))
  45 + ? 'full'
  46 + : Math.round((value - Math.floor(value)) * frac);
  47 +
  48 + this.setMod($(marks[i]), 'fill', fill)
6 49 }
  50 +
7 51 }
8 52
9 53 }, {
10 54
11 55 live : function() {
12 56
  57 + this.liveBindTo('click', function(e) {
  58 + this._onClick(e);
  59 + });
  60 +
13 61 }
14 62
15 63 });
1  blocks/b-rating/example/value
... ... @@ -0,0 +1 @@
  1 +{"value":4}
39 pages/rating/rating.bemjson.js
@@ -34,7 +34,7 @@
34 34 {
35 35 block: 'b-text',
36 36 content: [
37   - 'Семьдесят пять тридцатых равно двум пятым ',
  37 + 'Семьдесят пять тридцатых равно двум с половиной ',
38 38 {
39 39 block: 'b-rating',
40 40 mods: {
@@ -83,6 +83,43 @@
83 83 },
84 84 '4.3'
85 85 ]
  86 + },
  87 + {
  88 + block: 'b-text',
  89 + elem: 'h3',
  90 + content: 'Скрипты'
  91 + },
  92 + {
  93 + block: 'b-text',
  94 + content: [
  95 + 'Пока вы читали, рейтинг накрутился ',
  96 + {
  97 + block: 'b-rating',
  98 + mods: {
  99 + length: 5
  100 + },
  101 + value: 1,
  102 + js: {
  103 + url: '/blocks/b-rating/example/value'
  104 + }
  105 + }
  106 + ]
  107 + },
  108 + {
  109 + block: 'b-text',
  110 + content: [
  111 + 'Пока вы читали, рейтинг накрутился ',
  112 + {
  113 + block: 'b-rating',
  114 + mods: {
  115 + length: 5
  116 + },
  117 + value: 1,
  118 + js: {
  119 + url1: '/blocks/b-rating/example/value'
  120 + }
  121 + }
  122 + ]
86 123 }
87 124
88 125 ]

0 comments on commit 18ddb7e

Please sign in to comment.
Something went wrong with that request. Please try again.