Class: Cyberweb::JavascriptMagic
- Inherits:
-
Object
- Object
- Cyberweb::JavascriptMagic
show all
- Defined in:
- lib/cyberweb/javascript/javascript_magic.rb
Overview
Cyberweb::JavascriptMagic
Constant Summary
collapse
- ARRAY_APPLY_JAVASCRIPT_MAGIC_ON_THESE_ELEMENTS =
#
ARRAY_APPLY_JAVASCRIPT_MAGIC_ON_THESE_ELEMENTS
#
%w(
on_mouse_over_underline
popup
focus_and_select
redirect
)
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
39
40
41
42
43
44
45
46
47
|
# File 'lib/cyberweb/javascript/javascript_magic.rb', line 39
def initialize(
i = nil
)
if i
assign_to_original_input(i.dup)
assign_to_string(@original_input)
translate
end
end
|
Class Method Details
#
Cyberweb::JavascriptMagic[]
#
139
140
141
|
# File 'lib/cyberweb/javascript/javascript_magic.rb', line 139
def self.[](i)
new(i)
end
|
.is_included?(i) ⇒ Boolean
#
Cyberweb::JavascriptMagic.is_included?
Query to the above Array.
#
Instance Method Details
#_ ⇒ Object
Also known as:
translated?
111
112
113
|
# File 'lib/cyberweb/javascript/javascript_magic.rb', line 111
def _ @i
end
|
52
53
54
|
# File 'lib/cyberweb/javascript/javascript_magic.rb', line 52
def assign_to_original_input(i)
@original_input = i
end
|
#assign_to_string(i) ⇒ Object
59
60
61
|
# File 'lib/cyberweb/javascript/javascript_magic.rb', line 59
def assign_to_string(i) @i = i.dup
end
|
#test(this_string, be_verbose = false) ⇒ Object
Also known as:
test_this_string
#
test
The second argument determines whether we shall be verbose or whether we shall not.
#
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/cyberweb/javascript/javascript_magic.rb', line 121
def test(this_string, be_verbose = false)
case be_verbose
when :be_verbose
be_verbose = true
end
_ = this_string
assign_to_original_input(_)
translate(_)
if be_verbose
print "The string `#{_}` translates to: "
end
e @i
@i
end
|
#translate(this_string = @i) ⇒ Object
#
translate
This is the powerhorse of the class. It is automatically called whenever a new instance is made.
Note that all the following .include? checks in the code below, must also be synced to the main ARRAY on top of this file.
#
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
98
99
100
101
102
103
104
105
106
|
# File 'lib/cyberweb/javascript/javascript_magic.rb', line 72
def translate(
this_string = @i
) _ = this_string
assign_to_string(_)
if _.include? 'on_mouse_over_underline'
@i.gsub!(/on_mouse_over_underline/,
'onmouseover="this.style.textDecoration=\'underline\';"')
end
if _.include? 'popup'
@i.gsub!(/popup/, 'onclick="return popup(this.href)";')
end
if _.include? 'focus_and_select'
@i.gsub!(/popup/, 'onclick="this.focus();this.select()";')
end
if _.include? 'redirect' regex = /redirect_to\((.+)\)/
match_data_object = regex.match(@i)
match_data_object[1]
@i.gsub!(regex, 'window.location.href='+match_data_object[1]+';')
end
@i
end
|