rails_blocks 0.7.10 → 0.7.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 98997bf17ad7da0d3352b7e34d658bcc93fe9354a3fa2d6a9b9e2f098fdec175
|
4
|
+
data.tar.gz: a85a23ac0a5238468e3c65cf027f3be4acf603b1339a84e2ebcb0251c6b915ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 816b8b7aec4a7b6f6cb16f1101affb821c2889de7d6f09d87f7c7cb144fae874537ab8a5ae1feeaac8765bc2238b0b4e9d2a8d45f3bd4dbea379baf36e70afce
|
7
|
+
data.tar.gz: 1cc959e2530a6a10150e0e1e6d1c5543dbacb4704884dfa8fe01cce060aeb926a68970953f720001d83504ec6664764098b0e22aa221543ff075c3dd54c2a7e9
|
@@ -5,6 +5,9 @@ window.$$ =
|
|
5
5
|
bem_class_selector: ".js-bem"
|
6
6
|
bemDataKey: 'bem'
|
7
7
|
|
8
|
+
blockInitializationErrorHandler: (e) ->
|
9
|
+
console.error "Can't initialize block #{name}, check declaration. #{e.name} : #{e.message}"
|
10
|
+
|
8
11
|
processOptions: ($dom, item_name, b_name, o) ->
|
9
12
|
if o.attrs
|
10
13
|
for attr, attr_value of o.attrs
|
@@ -63,14 +66,13 @@ window.$$ =
|
|
63
66
|
return $$.cache[bid]
|
64
67
|
try
|
65
68
|
block = new $$.decls[$$.utils.camelCase(name)]($b, params, name)
|
69
|
+
bid = block.id
|
70
|
+
$b.data cacheKey, bid
|
71
|
+
$$.cache[bid] = block
|
72
|
+
block
|
66
73
|
catch e
|
67
|
-
|
68
|
-
|
69
|
-
bid = block.id
|
70
|
-
$b.data cacheKey, bid
|
71
|
-
$$.cache[bid] = block
|
72
|
-
block
|
73
|
-
|
74
|
+
$$.blockInitializationErrorHandler(e) if $$.blockInitializationErrorHandler
|
75
|
+
|
74
76
|
makeMod: (name, value) ->
|
75
77
|
mod = name
|
76
78
|
mod += "_#{value}" if value
|
data/lib/rails_blocks/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_blocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Potetiurin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -153,10 +153,7 @@ files:
|
|
153
153
|
- Rakefile
|
154
154
|
- app/assets/javascripts/bem_blocks.coffee
|
155
155
|
- app/assets/javascripts/block.coffee
|
156
|
-
- app/assets/javascripts/jblocks.coffee
|
157
156
|
- app/assets/javascripts/jquery.bem_exts.coffee
|
158
|
-
- app/assets/javascripts/jquery_bem.coffee
|
159
|
-
- app/assets/javascripts/jquery_bem_copy.coffee
|
160
157
|
- app/assets/javascripts/rails_blocks.js
|
161
158
|
- app/assets/javascripts/utils.coffee
|
162
159
|
- app/assets/stylesheets/rails_blocks.sass
|
@@ -228,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
225
|
version: '0'
|
229
226
|
requirements: []
|
230
227
|
rubyforge_project:
|
231
|
-
rubygems_version: 2.
|
228
|
+
rubygems_version: 2.7.7
|
232
229
|
signing_key:
|
233
230
|
specification_version: 4
|
234
231
|
summary: Rails plugin for work with some modification of BEM methodology
|
@@ -1,95 +0,0 @@
|
|
1
|
-
camelCase = (input) ->
|
2
|
-
input.toLowerCase().replace /(^|-)(.)/g, (match, $1, $2) ->
|
3
|
-
$2.toUpperCase()
|
4
|
-
|
5
|
-
window.$$ =
|
6
|
-
decls: {}
|
7
|
-
cache: {}
|
8
|
-
utils: {}
|
9
|
-
_id: 0
|
10
|
-
bem_class: 'js_bem'
|
11
|
-
bem_class_selector: '.js_bem'
|
12
|
-
guid: () ->
|
13
|
-
return @_id++
|
14
|
-
|
15
|
-
processOptions: ($dom, b_name, o) ->
|
16
|
-
if o.attrs
|
17
|
-
for attr, attr_value of o.attrs
|
18
|
-
$dom.prop(attr, attr_value)
|
19
|
-
if o.content
|
20
|
-
$dom.html(o.content)
|
21
|
-
if o.mix
|
22
|
-
$dom.addClass($$.mixClass(o.mix))
|
23
|
-
if o.elements
|
24
|
-
for e_name, e_o of o.elements
|
25
|
-
$$.makeElement($dom, b_name, e_name, e_o)
|
26
|
-
|
27
|
-
makeElement: ($parent, b_name, e_name, o) ->
|
28
|
-
tag = o.tag || 'div'
|
29
|
-
$e = $("<#{tag} class='b-#{b_name}__#{e_name}'>")
|
30
|
-
$$.processOptions($e, b_name, o)
|
31
|
-
if o.prepend
|
32
|
-
$parent.prepend $e
|
33
|
-
else
|
34
|
-
$parent.append $e
|
35
|
-
$e
|
36
|
-
|
37
|
-
makeBlock: (b_name, o) ->
|
38
|
-
o ||= {}
|
39
|
-
tag = o.tag || 'div'
|
40
|
-
$b = $("<#{tag} class='b-#{b_name}'>")
|
41
|
-
$$.processOptions($b, b_name, o)
|
42
|
-
$b
|
43
|
-
|
44
|
-
init: ($context) ->
|
45
|
-
$$.getBlocks($context.find($$.bem_class_selector))
|
46
|
-
$$.getBlocks($context) if $context.hasClass $$.bem_class
|
47
|
-
|
48
|
-
getBlocks: ($context, options) ->
|
49
|
-
$context.map ->
|
50
|
-
$$.getBlock($(this), options)
|
51
|
-
|
52
|
-
getBlock: ($b, options)->
|
53
|
-
bid = $b.data('_bid')
|
54
|
-
if bid
|
55
|
-
return $$.cache[bid]
|
56
|
-
block = new $$.decls[camelCase($$.getBlockName($b))]($b, options)
|
57
|
-
bid = block.id
|
58
|
-
$b.data '_bid', bid
|
59
|
-
$$.cache[bid] = block
|
60
|
-
block
|
61
|
-
|
62
|
-
getBlockName: ($b) ->
|
63
|
-
regexp = /^b(-[a-zA-Z0-9]+)+$/
|
64
|
-
for klass in $b.attr('class').split(/\s+/)
|
65
|
-
return klass.replace('b-', '') if regexp.test(klass)
|
66
|
-
|
67
|
-
makeMod: (name, value) ->
|
68
|
-
mod = name
|
69
|
-
mod += "_#{value}" if value
|
70
|
-
mod
|
71
|
-
|
72
|
-
mixClass: (mix) ->
|
73
|
-
"b-#{mix.b}__#{mix.e}"
|
74
|
-
|
75
|
-
$.fn.destroyBlocks = ->
|
76
|
-
@find($$.bem_class_selector).getBlocks().each ->
|
77
|
-
@destroy()
|
78
|
-
|
79
|
-
$.fn.addMod = (name, value) ->
|
80
|
-
mod = $$.makeMod(name, value)
|
81
|
-
if @e_name
|
82
|
-
@addClass("b-#{@b_name}__#{@e_name}--#{mod}")
|
83
|
-
else
|
84
|
-
@addClass("b-#{@b_name}--#{mod}")
|
85
|
-
|
86
|
-
$.fn.delMod = (name, value) ->
|
87
|
-
mod = $$.makeMod(name, value)
|
88
|
-
if @e_name
|
89
|
-
@removeClass("b-#{@b_name}__#{@e_name}--#{mod}")
|
90
|
-
else
|
91
|
-
@removeClass("b-#{@b_name}--#{mod}")
|
92
|
-
|
93
|
-
$.fn.asBlock = (name, o) ->
|
94
|
-
@addClass("b-#{name}")
|
95
|
-
$$.getBlock(@, o)
|
@@ -1,486 +0,0 @@
|
|
1
|
-
### @required jQuery ###
|
2
|
-
|
3
|
-
(($) ->
|
4
|
-
|
5
|
-
###*
|
6
|
-
# Base BEM class.
|
7
|
-
# @constructor
|
8
|
-
###
|
9
|
-
|
10
|
-
BEM = (config) ->
|
11
|
-
|
12
|
-
###*
|
13
|
-
# Default configuration.
|
14
|
-
# @type {Object}
|
15
|
-
###
|
16
|
-
|
17
|
-
@config = config or {}
|
18
|
-
@blockClassRe = @buildBlockClassRe()
|
19
|
-
@elemClassRe = @buildElemClassRe()
|
20
|
-
@modClassRe = @buildModClassRe()
|
21
|
-
return
|
22
|
-
|
23
|
-
###*
|
24
|
-
# Get parent block of element.
|
25
|
-
# @public
|
26
|
-
#
|
27
|
-
# @param {Object} $this
|
28
|
-
# @return {Object}
|
29
|
-
###
|
30
|
-
|
31
|
-
BEM::getBlock = ($this) ->
|
32
|
-
blockClass = @getBlockClass($this)
|
33
|
-
block = $this.closest('.' + blockClass)
|
34
|
-
block.selector = blockClass
|
35
|
-
block
|
36
|
-
|
37
|
-
###*
|
38
|
-
# Switch block context.
|
39
|
-
# @public
|
40
|
-
#
|
41
|
-
# @param {Object} $this
|
42
|
-
# @param {String} block
|
43
|
-
# @param {String} [elem]
|
44
|
-
# @return {Object}
|
45
|
-
###
|
46
|
-
|
47
|
-
BEM::switchBlock = ($this, block, elem) ->
|
48
|
-
`var elem`
|
49
|
-
elem = elem or null
|
50
|
-
if elem then ($this.selector = @buildSelector(
|
51
|
-
block: block
|
52
|
-
elem: elem)) else ($this.selector = @buildSelector(block: block))
|
53
|
-
$this
|
54
|
-
|
55
|
-
###*
|
56
|
-
# Find element in block.
|
57
|
-
# @public
|
58
|
-
#
|
59
|
-
# @param {Object} $this DOM element
|
60
|
-
# @param {String} elemKey Element name
|
61
|
-
# @return {Object}
|
62
|
-
###
|
63
|
-
|
64
|
-
BEM::findElem = ($this, elemKey) ->
|
65
|
-
blockClass = @getBlockClass($this)
|
66
|
-
elemName = @buildElemClass(blockClass, elemKey)
|
67
|
-
elem = $this.find('.' + elemName)
|
68
|
-
elem
|
69
|
-
|
70
|
-
###*
|
71
|
-
# Get value of modifier.
|
72
|
-
# @public
|
73
|
-
#
|
74
|
-
# @param {Object} $this
|
75
|
-
# @param {String} modKey
|
76
|
-
# @return {String}
|
77
|
-
###
|
78
|
-
|
79
|
-
BEM::getMod = ($this, modKey) ->
|
80
|
-
mods = @extractMods($this.first())
|
81
|
-
if mods[modKey] != undefined
|
82
|
-
return mods[modKey]
|
83
|
-
null
|
84
|
-
|
85
|
-
###*
|
86
|
-
# Check modifier of element.
|
87
|
-
# @public
|
88
|
-
#
|
89
|
-
# @param {Object} $this
|
90
|
-
# @param {String} modKey
|
91
|
-
# @param {String} [modVal]
|
92
|
-
# @return {Boolean}
|
93
|
-
###
|
94
|
-
|
95
|
-
BEM::hasMod = ($this, modKey, modVal) ->
|
96
|
-
mods = @extractMods($this.first())
|
97
|
-
if modVal
|
98
|
-
if mods[modKey] == modVal
|
99
|
-
return true
|
100
|
-
else
|
101
|
-
if mods[modKey]
|
102
|
-
return true
|
103
|
-
false
|
104
|
-
|
105
|
-
###*
|
106
|
-
# Set modifier on element.
|
107
|
-
# @public
|
108
|
-
#
|
109
|
-
# @param {Object} $this
|
110
|
-
# @param {String} modKey
|
111
|
-
# @param {String} [modVal]
|
112
|
-
# @param {Object}
|
113
|
-
###
|
114
|
-
|
115
|
-
BEM::setMod = ($this, modKey, modVal) ->
|
116
|
-
self = this
|
117
|
-
selector = $this.selector
|
118
|
-
$this.each ->
|
119
|
-
current = $(this)
|
120
|
-
current.selector = selector
|
121
|
-
mods = self.extractMods(current)
|
122
|
-
baseName = self.getBaseClass(current)
|
123
|
-
if mods[modKey] != undefined
|
124
|
-
oldModName = self.buildModClass(baseName, modKey, mods[modKey])
|
125
|
-
current.removeClass oldModName
|
126
|
-
if modVal != false
|
127
|
-
newModName = self.buildModClass(baseName, modKey, modVal)
|
128
|
-
current.addClass(newModName).trigger 'setmod', [
|
129
|
-
modKey
|
130
|
-
modVal
|
131
|
-
]
|
132
|
-
return
|
133
|
-
$this
|
134
|
-
|
135
|
-
###*
|
136
|
-
# Delete modifier on element.
|
137
|
-
# @public
|
138
|
-
#
|
139
|
-
# @param {Object} $this
|
140
|
-
# @param {String} modKey
|
141
|
-
# @param {String} [modVal]
|
142
|
-
# @param {Object}
|
143
|
-
###
|
144
|
-
|
145
|
-
BEM::delMod = ($this, modKey, modVal) ->
|
146
|
-
self = this
|
147
|
-
selector = $this.selector
|
148
|
-
$this.each ->
|
149
|
-
`var modName`
|
150
|
-
current = $(this)
|
151
|
-
current.selector = selector
|
152
|
-
mods = self.extractMods(current)
|
153
|
-
baseName = self.getBaseClass(current)
|
154
|
-
if modVal
|
155
|
-
if mods[modKey] == modVal
|
156
|
-
modName = self.buildModClass(baseName, modKey, mods[modKey])
|
157
|
-
else
|
158
|
-
modName = self.buildModClass(baseName, modKey, mods[modKey])
|
159
|
-
current.removeClass(modName).trigger 'delmod', [
|
160
|
-
modKey
|
161
|
-
modVal
|
162
|
-
]
|
163
|
-
return
|
164
|
-
$this
|
165
|
-
|
166
|
-
###*
|
167
|
-
# Filtering elements by modifier.
|
168
|
-
# @public
|
169
|
-
#
|
170
|
-
# @param {Object} $this
|
171
|
-
# @param {String} modKey
|
172
|
-
# @param {String} [modVal]
|
173
|
-
# @param {Boolean} [inverse]
|
174
|
-
# @return {Object}
|
175
|
-
###
|
176
|
-
|
177
|
-
BEM::byMod = ($this, modKey, modVal, inverse) ->
|
178
|
-
`var inverse`
|
179
|
-
`var modVal`
|
180
|
-
self = this
|
181
|
-
modVal = modVal or null
|
182
|
-
inverse = inverse or false
|
183
|
-
selector = $this.selector
|
184
|
-
result = $()
|
185
|
-
$this.each ->
|
186
|
-
`var modName`
|
187
|
-
current = $(this)
|
188
|
-
current.selector = selector
|
189
|
-
mods = self.extractMods(current)
|
190
|
-
baseName = self.getBaseClass(current)
|
191
|
-
if modVal
|
192
|
-
if mods[modKey] == modVal
|
193
|
-
modName = self.buildModClass(baseName, modKey, mods[modKey])
|
194
|
-
else
|
195
|
-
if mods[modKey] != undefined
|
196
|
-
modName = self.buildModClass(baseName, modKey, mods[modKey])
|
197
|
-
result = result.add(if inverse then current.not('.' + modName) else current.filter('.' + modName))
|
198
|
-
return
|
199
|
-
result.selector = selector
|
200
|
-
result
|
201
|
-
|
202
|
-
###*
|
203
|
-
# Get block names from element.
|
204
|
-
# @protected
|
205
|
-
#
|
206
|
-
# @param {Object|String} $this
|
207
|
-
# @return {Object}
|
208
|
-
###
|
209
|
-
|
210
|
-
BEM::extractBlocks = ($this) ->
|
211
|
-
self = this
|
212
|
-
result = []
|
213
|
-
selectors = @getClasses($this)
|
214
|
-
$.each selectors, (i, sel) ->
|
215
|
-
type = self.getClassType(sel)
|
216
|
-
if type == 'block'
|
217
|
-
result.push sel
|
218
|
-
else if type == 'elem'
|
219
|
-
elem = sel.split(self.config.elemPrefix)
|
220
|
-
result.push elem[0]
|
221
|
-
return
|
222
|
-
result
|
223
|
-
|
224
|
-
###*
|
225
|
-
# Get element names from element.
|
226
|
-
# @protected
|
227
|
-
#
|
228
|
-
# @param {Object} $this
|
229
|
-
# @return {Object}
|
230
|
-
###
|
231
|
-
|
232
|
-
BEM::extractElems = ($this) ->
|
233
|
-
self = this
|
234
|
-
result = []
|
235
|
-
$.each self.getClasses($this), (i, className) ->
|
236
|
-
if self.getClassType(className) == 'elem'
|
237
|
-
elemName = className.split(self.config.elemPrefix)
|
238
|
-
result.push elemName[1]
|
239
|
-
return
|
240
|
-
result
|
241
|
-
|
242
|
-
###*
|
243
|
-
# Get modifiers from element.
|
244
|
-
# @protected
|
245
|
-
#
|
246
|
-
# @param {Object} $this
|
247
|
-
# @return {Object}
|
248
|
-
###
|
249
|
-
|
250
|
-
BEM::extractMods = ($this) ->
|
251
|
-
self = this
|
252
|
-
result = {}
|
253
|
-
$this.each ->
|
254
|
-
`var $this`
|
255
|
-
$this = $(this)
|
256
|
-
$.each self.getClasses($this), (i, className) ->
|
257
|
-
`var modVal`
|
258
|
-
if self.getClassType(className) == 'mod'
|
259
|
-
re = self.buildModClassRe().exec(className)
|
260
|
-
modName = re[1].split(self.config.modDlmtr)
|
261
|
-
if modName[1] != undefined and modName[1] != false
|
262
|
-
modVal = modName[1]
|
263
|
-
else
|
264
|
-
modVal = true
|
265
|
-
result[modName[0]] = modVal
|
266
|
-
return
|
267
|
-
return
|
268
|
-
result
|
269
|
-
|
270
|
-
###*
|
271
|
-
# Get classes names from element.
|
272
|
-
# @protected
|
273
|
-
#
|
274
|
-
# @param {Object} $this
|
275
|
-
# @return {Object}
|
276
|
-
###
|
277
|
-
|
278
|
-
BEM::getClasses = ($this) ->
|
279
|
-
classes = undefined
|
280
|
-
result = []
|
281
|
-
if typeof $this == 'object'
|
282
|
-
if $this.selector.indexOf('.') == 0
|
283
|
-
classes = $this.selector.split('.')
|
284
|
-
else if $this.attr('class') != undefined
|
285
|
-
classes = $this.attr('class').split(' ')
|
286
|
-
else
|
287
|
-
return null
|
288
|
-
else
|
289
|
-
classes = $this.split('.')
|
290
|
-
$.each classes, (i, className) ->
|
291
|
-
if className != ''
|
292
|
-
result.push $.trim(className)
|
293
|
-
return
|
294
|
-
result
|
295
|
-
|
296
|
-
###*
|
297
|
-
# Build regexp for blocks.
|
298
|
-
# @protected
|
299
|
-
#
|
300
|
-
# @return {RegExp}
|
301
|
-
###
|
302
|
-
|
303
|
-
BEM::buildBlockClassRe = ->
|
304
|
-
new RegExp('^(' + @config.namePattern + ')$')
|
305
|
-
|
306
|
-
###*
|
307
|
-
# Build regexp for elements.
|
308
|
-
# @protected
|
309
|
-
#
|
310
|
-
# @return {RegExp}
|
311
|
-
###
|
312
|
-
|
313
|
-
BEM::buildElemClassRe = ->
|
314
|
-
new RegExp('^' + @config.namePattern + @config.elemPrefix + '(' + @config.namePattern + ')$')
|
315
|
-
|
316
|
-
###*
|
317
|
-
# Build regexp for modifiers.
|
318
|
-
# @protected
|
319
|
-
#
|
320
|
-
# @return {RegExp}
|
321
|
-
###
|
322
|
-
|
323
|
-
BEM::buildModClassRe = ->
|
324
|
-
new RegExp('^(?:' + @config.namePattern + '|' + @config.namePattern + @config.elemPrefix + @config.namePattern + ')' + @config.modPrefix + '(' + @config.namePattern + '((' + @config.modDlmtr + @config.namePattern + ')$|$))')
|
325
|
-
|
326
|
-
###*
|
327
|
-
# Build class name for block.
|
328
|
-
# @protected
|
329
|
-
#
|
330
|
-
# @param {String} blockName
|
331
|
-
# @return {String}
|
332
|
-
###
|
333
|
-
|
334
|
-
BEM::buildBlockClass = (blockName) ->
|
335
|
-
@config.blockPrefix + blockName
|
336
|
-
|
337
|
-
###*
|
338
|
-
# Build class name for element.
|
339
|
-
# @protected
|
340
|
-
#
|
341
|
-
# @param {String} blockName
|
342
|
-
# @param {String} elemKey
|
343
|
-
# @return {String}
|
344
|
-
###
|
345
|
-
|
346
|
-
BEM::buildElemClass = (blockName, elemKey) ->
|
347
|
-
blockName + @config.elemPrefix + elemKey
|
348
|
-
|
349
|
-
###*
|
350
|
-
# Build class name for modifier.
|
351
|
-
# @protected
|
352
|
-
#
|
353
|
-
# @param {String} blockName
|
354
|
-
# @param {String} modKey
|
355
|
-
# @param {String} modVal
|
356
|
-
# @return {String}
|
357
|
-
###
|
358
|
-
|
359
|
-
BEM::buildModClass = (baseClass, modKey, modVal) ->
|
360
|
-
if modVal != undefined and modVal != true
|
361
|
-
baseClass + @config.modPrefix + modKey + @config.modDlmtr + modVal
|
362
|
-
else
|
363
|
-
baseClass + @config.modPrefix + modKey
|
364
|
-
|
365
|
-
###*
|
366
|
-
# Build selector from object or string.
|
367
|
-
# @private
|
368
|
-
#
|
369
|
-
# @param {String|Object}
|
370
|
-
# @param {String}
|
371
|
-
# @return {String}
|
372
|
-
###
|
373
|
-
|
374
|
-
BEM::buildSelector = (selector, prefix) ->
|
375
|
-
`var prefix`
|
376
|
-
if prefix != ''
|
377
|
-
prefix = prefix or '.'
|
378
|
-
if typeof selector == 'object'
|
379
|
-
if selector.block != undefined
|
380
|
-
buildSelector = @buildBlockClass(selector.block)
|
381
|
-
if selector.elem != undefined
|
382
|
-
buildSelector = @buildElemClass(buildSelector, selector.elem)
|
383
|
-
if selector.mod != undefined
|
384
|
-
mod = selector.mod.split(':')
|
385
|
-
buildSelector = @buildModClass(buildSelector, mod[0], mod[1])
|
386
|
-
if buildSelector != undefined then prefix + buildSelector else prefix + selector
|
387
|
-
|
388
|
-
###*
|
389
|
-
# Build class name for block.
|
390
|
-
# @protected
|
391
|
-
#
|
392
|
-
# @param {Object|String} $this
|
393
|
-
# @param {Number} [index]
|
394
|
-
# @return {String}
|
395
|
-
###
|
396
|
-
|
397
|
-
BEM::getBlockClass = ($this, index) ->
|
398
|
-
`var index`
|
399
|
-
blockClasses = @extractBlocks($this)
|
400
|
-
index = index or 0
|
401
|
-
if index <= blockClasses.length - 1 then blockClasses[index] else null
|
402
|
-
|
403
|
-
###*
|
404
|
-
# Get base class from element.
|
405
|
-
# @protected
|
406
|
-
#
|
407
|
-
# @param {Object} $this
|
408
|
-
# @return {String}
|
409
|
-
###
|
410
|
-
|
411
|
-
BEM::getBaseClass = ($this) ->
|
412
|
-
self = this
|
413
|
-
baseClass = null
|
414
|
-
selectors = @getClasses($this)
|
415
|
-
$.each selectors, (i, sel) ->
|
416
|
-
classType = self.getClassType(sel)
|
417
|
-
if classType and classType != 'mod'
|
418
|
-
baseClass = sel
|
419
|
-
return
|
420
|
-
baseClass
|
421
|
-
|
422
|
-
###*
|
423
|
-
# Get class type.
|
424
|
-
# @protected
|
425
|
-
#
|
426
|
-
# @param {String} className
|
427
|
-
# @return {String}
|
428
|
-
###
|
429
|
-
|
430
|
-
BEM::getClassType = (className) ->
|
431
|
-
if @modClassRe.test(className)
|
432
|
-
return 'mod'
|
433
|
-
else if @elemClassRe.test(className)
|
434
|
-
return 'elem'
|
435
|
-
else if @blockClassRe.test(className)
|
436
|
-
return 'block'
|
437
|
-
null
|
438
|
-
|
439
|
-
###*
|
440
|
-
# Create BEM instance.
|
441
|
-
###
|
442
|
-
|
443
|
-
$.BEM = new BEM(
|
444
|
-
namePattern: '[a-zA-Z0-9-]+'
|
445
|
-
blockPrefix: ''
|
446
|
-
elemPrefix: '__'
|
447
|
-
modPrefix: '--'
|
448
|
-
modDlmtr: '_')
|
449
|
-
|
450
|
-
###*
|
451
|
-
# Extend jQuery object.
|
452
|
-
###
|
453
|
-
|
454
|
-
$.fn.extend
|
455
|
-
block: ->
|
456
|
-
$.BEM.getBlock this
|
457
|
-
elem: (elemKey) ->
|
458
|
-
$.BEM.findElem this, elemKey
|
459
|
-
ctx: (block, elem) ->
|
460
|
-
$.BEM.switchBlock this, block, elem
|
461
|
-
mod: (modKey, modVal) ->
|
462
|
-
if typeof modVal == 'undefined'
|
463
|
-
modVal = null
|
464
|
-
if modVal == false
|
465
|
-
return $.BEM.delMod(this, modKey)
|
466
|
-
if modVal != null
|
467
|
-
$.BEM.setMod(this, modKey, modVal)
|
468
|
-
else
|
469
|
-
$.BEM.getMod(this, modKey)
|
470
|
-
setMod: (modKey, modVal) ->
|
471
|
-
$.BEM.setMod this, modKey, modVal
|
472
|
-
delMod: (modKey, modVal) ->
|
473
|
-
$.BEM.delMod this, modKey, modVal
|
474
|
-
hasMod: (modKey, modVal) ->
|
475
|
-
$.BEM.hasMod this, modKey, modVal
|
476
|
-
byMod: (modKey, modVal) ->
|
477
|
-
$.BEM.byMod this, modKey, modVal
|
478
|
-
byNotMod: (modKey, modVal) ->
|
479
|
-
$.BEM.byMod this, modKey, modVal, 'inverse'
|
480
|
-
toggleMod: (modKey, modVal1, modVal2) ->
|
481
|
-
if @hasMod(modKey, modVal1)
|
482
|
-
@delMod(modKey, modVal1).setMod modKey, modVal2
|
483
|
-
else
|
484
|
-
@delMod(modKey, modVal2).setMod modKey, modVal1
|
485
|
-
return
|
486
|
-
) jQuery
|