-
Notifications
You must be signed in to change notification settings - Fork 31
/
runtime.js
195 lines (159 loc) · 4.53 KB
/
runtime.js
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// ECMAScript 5 strict mode
"use strict";
assert2(cr, "cr namespace not created");
assert2(cr.plugins_, "cr.plugins_ not created");
/////////////////////////////////////
// Plugin class
cr.plugins_.WebFont = function(runtime)
{
this.runtime = runtime;
};
(function ()
{
/////////////////////////////////////
var pluginProto = cr.plugins_.WebFont.prototype;
/////////////////////////////////////
// Object type class
pluginProto.Type = function(plugin)
{
this.plugin = plugin;
this.runtime = plugin.runtime;
};
var typeProto = pluginProto.Type.prototype;
// called on startup for each object type
typeProto.onCreate = function()
{
};
/////////////////////////////////////
// Instance class
pluginProto.Instance = function(type)
{
this.type = type;
this.runtime = type.runtime;
};
var instanceProto = pluginProto.Instance.prototype;
// called whenever an instance is created
instanceProto.onCreate = function()
{
var nameOfCSSFile;
if(typeof cr_is_preview != undefined){
//alert(this.properties[4]);
nameOfCSSFile = this.properties[4];
}else{
nameOfCSSFile = this.properties[5];
}
//this.returnValue= "";
//<link rel="stylesheet" type="text/css" href="style.css" />
/*var myWebFontTag=document.createElement('link');
myWebFontTag.setAttribute("type","text/css");
myWebFontTag.setAttribute("rel", "stylesheet");
myWebFontTag.setAttribute("href", "nameOfCSSFile");*/
var linkTag = "<link rel='stylesheet' type='text/css' href='"+nameOfCSSFile+"' />";
jQuery('head').append(linkTag);
/*if (typeof myWebFontTag != "undefined")
document.getElementsByTagName("head")[0].appendChild(myWebFontTag);*/
//jQuery(this.elem).appendTo("head");
var myDiv = document.createElement(this.properties[6]);
myDiv.setAttribute("id",this.properties[7]);
this.elem = myDiv
//this.elem.type = "button";
jQuery(this.elem).appendTo("body");
//this.elem.value = this.properties[0];
this.elem.innerHTML = this.properties[0];
this.elem.title = this.properties[1];
this.elem.disabled = (this.properties[3] === 0);
/*var tmpt = this.properties[7];
jQuery(window).bind("load", function() {
jQuery('myp').addClass('shown');
});*/
if (this.properties[2] === 0)
{
jQuery(this.elem).hide();
this.visible = false;
}
this.elem.onclick = (function (self) {
return function() {
self.runtime.trigger(cr.plugins_.Button.prototype.cnds.OnClicked, self);
};
})(this);
this.updatePosition();
this.runtime.tickMe(this);
};
instanceProto.onDestroy = function ()
{
jQuery(this.elem).remove();
this.elem = null;
};
instanceProto.tick = function ()
{
this.updatePosition();
};
instanceProto.updatePosition = function ()
{
var left = this.layer.layerToCanvas(this.x, this.y, true);
var top = this.layer.layerToCanvas(this.x, this.y, false);
var right = this.layer.layerToCanvas(this.x + this.width, this.y + this.height, true);
var bottom = this.layer.layerToCanvas(this.x + this.width, this.y + this.height, false);
// Is entirely offscreen or invisible: hide
if (!this.visible || right <= 0 || bottom <= 0 || left >= this.runtime.width || top >= this.runtime.height)
{
jQuery(this.elem).hide();
return;
}
// Truncate to canvas size
if (left < 1)
left = 1;
if (top < 1)
top = 1;
if (right >= this.runtime.width)
right = this.runtime.width - 1;
if (bottom >= this.runtime.height)
bottom = this.runtime.height - 1;
jQuery(this.elem).show();
var offx = left + jQuery(this.runtime.canvas).offset().left;
var offy = top + jQuery(this.runtime.canvas).offset().top;
jQuery(this.elem).offset({left: offx, top: offy});
jQuery(this.elem).width(right - left);
jQuery(this.elem).height(bottom - top);
};
// only called if a layout object
instanceProto.draw = function(ctx)
{
};
instanceProto.drawGL = function(glw)
{
};
//////////////////////////////////////
// Conditions
pluginProto.cnds = {};
var cnds = pluginProto.cnds;
cnds.OnClicked = function ()
{
return true;
};
//////////////////////////////////////
// Actions
pluginProto.acts = {};
var acts = pluginProto.acts;
acts.SetText = function (text)
{
//this.elem.value = text;
this.elem.innerHTML = text;
};
acts.SetTooltip = function (text)
{
this.elem.title = text;
};
acts.SetVisible = function (vis)
{
this.visible = (vis !== 0);
};
acts.SetEnabled = function (en)
{
this.elem.disabled = (en === 0);
};
//////////////////////////////////////
// Expressions
pluginProto.exps = {};
var exps = pluginProto.exps;
}());