-
Notifications
You must be signed in to change notification settings - Fork 236
/
quo.element.coffee
97 lines (78 loc) · 1.94 KB
/
quo.element.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
###
Basic Quo Module
@namespace Quo
@class Element
@author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
###
"use strict"
do ($$ = Quo) ->
###
Get/Set attribute to a given instance element
@method attr
@param {string} Name of attribute
@param {string} [OPTIONAL] Value of attribute
###
$$.fn.attr = (name, value) ->
if @length > 0 and $$.toType(name) is "string"
if value
@each -> @setAttribute name, value
else
@[0].getAttribute name
###
Remove attribute to a given instance element
@method removeAttr
@param {string} Name of attribute
###
$$.fn.removeAttr = (name) ->
if @length > 0 and $$.toType(name) is "string"
@each -> @removeAttribute name
###
Get/Set data attribute to a given instance element
@method data
@param {string} Name of data attribute
@param {string} [OPTIONAL] Value of data atribbute
###
$$.fn.data = (name, value) ->
@attr "data-#{name}", value
###
Remove data attribute to a given instance element
@method removeAttr
@param {string} Name of data attribute
###
$$.fn.removeData = (name) ->
@removeAttr "data-#{name}"
###
Remove data attribute to a given instance element
@method val
@param {string} Name of data attribute
###
$$.fn.val = (value) ->
if value?
@each -> @value = value.toString()
else
if @length > 0 then @[0].value else null
###
Shows a given instance element
@method show
###
$$.fn.show = ->
@style "display", "block"
###
Hides a given instance element
@method hide
###
$$.fn.hide = ->
@style "display", "none"
###
Get a offset of a given instance element
@method offset
###
$$.fn.offset = ->
if @length > 0
bounding = @[0].getBoundingClientRect()
offset =
left : bounding.left + window.pageXOffset
top : bounding.top + window.pageYOffset
width : bounding.width
height: bounding.height
offset