Commit 0d0e9621 0d0e962148663dd34fc54a8b27d1b481bc3d4c62 by Nicolas Perriault

added events where applicable in Casper methods

1 parent 582f1f9a
...@@ -11,7 +11,7 @@ def resolve(path): ...@@ -11,7 +11,7 @@ def resolve(path):
11 return path 11 return path
12 12
13 CASPER_PATH = os.path.abspath(os.path.join(os.path.dirname(resolve(__file__)), '..')) 13 CASPER_PATH = os.path.abspath(os.path.join(os.path.dirname(resolve(__file__)), '..'))
14 CASPER_ARGS = ['phantomjs', os.path.join(CASPER_PATH, 'bin', 'bootstrap.js'), '--casper-path=%s' % CASPER_PATH, '--cli'] 14 CASPER_ARGS = ['phantomjs14', os.path.join(CASPER_PATH, 'bin', 'bootstrap.js'), '--casper-path=%s' % CASPER_PATH, '--cli']
15 CASPER_ARGS.extend(sys.argv[1:]) 15 CASPER_ARGS.extend(sys.argv[1:])
16 16
17 try: 17 try:
......
...@@ -70,7 +70,7 @@ function fileExt(file) { ...@@ -70,7 +70,7 @@ function fileExt(file) {
70 exports.fileExt = fileExt; 70 exports.fileExt = fileExt;
71 71
72 /** 72 /**
73 * Takes a string and append blank until the pad value is reached. 73 * Takes a string and append blanks until the pad value is reached.
74 * 74 *
75 * @param String text 75 * @param String text
76 * @param Number pad Pad value (optional; default: 80) 76 * @param Number pad Pad value (optional; default: 80)
...@@ -85,8 +85,14 @@ function fillBlanks(text, pad) { ...@@ -85,8 +85,14 @@ function fillBlanks(text, pad) {
85 } 85 }
86 exports.fillBlanks = fillBlanks; 86 exports.fillBlanks = fillBlanks;
87 87
88 /**
89 * Checks if value is a javascript Array
90 *
91 * @param mixed value
92 * @return Boolean
93 */
88 function isArray(value) { 94 function isArray(value) {
89 return isType(value, "array"); 95 return Array.isArray(value) || isType(value, "array");
90 } 96 }
91 exports.isArray = isArray; 97 exports.isArray = isArray;
92 98
...@@ -101,17 +107,27 @@ function isCasperObject(value) { ...@@ -101,17 +107,27 @@ function isCasperObject(value) {
101 } 107 }
102 exports.isCasperObject = isCasperObject; 108 exports.isCasperObject = isCasperObject;
103 109
110 /**
111 * Checks if value is a phantomjs clipRect-compatible object
112 *
113 * @param mixed value
114 * @return Boolean
115 */
104 function isClipRect(value) { 116 function isClipRect(value) {
105 return isType(value, "cliprect") || ( 117 return isType(value, "cliprect") || (
106 isType(value, "object") && 118 isObject(value) &&
107 isType(value.top, "number") && 119 isNumber(value.top) && isNumber(value.left) &&
108 isType(value.left, "number") && 120 isNumber(value.width) && isNumber(value.height)
109 isType(value.width, "number") &&
110 isType(value.height, "number")
111 ); 121 );
112 } 122 }
113 exports.isClipRect = isClipRect; 123 exports.isClipRect = isClipRect;
114 124
125 /**
126 * Checks if value is a javascript Function
127 *
128 * @param mixed value
129 * @return Boolean
130 */
115 function isFunction(value) { 131 function isFunction(value) {
116 return isType(value, "function"); 132 return isType(value, "function");
117 } 133 }
...@@ -125,15 +141,38 @@ exports.isFunction = isFunction; ...@@ -125,15 +141,38 @@ exports.isFunction = isFunction;
125 */ 141 */
126 function isJsFile(file) { 142 function isJsFile(file) {
127 var ext = fileExt(file); 143 var ext = fileExt(file);
128 return isType(ext, "string") && ['js', 'coffee'].indexOf(ext) !== -1; 144 return isString(ext, "string") && ['js', 'coffee'].indexOf(ext) !== -1;
129 } 145 }
130 exports.isJsFile = isJsFile; 146 exports.isJsFile = isJsFile;
131 147
148 /**
149 * Checks if value is a javascript Number
150 *
151 * @param mixed value
152 * @return Boolean
153 */
154 function isNumber(value) {
155 return isType(value, "number");
156 }
157 exports.isNumber = isNumber;
158
159 /**
160 * Checks if value is a javascript Object
161 *
162 * @param mixed value
163 * @return Boolean
164 */
132 function isObject(value) { 165 function isObject(value) {
133 return isType(value, "object"); 166 return isType(value, "object");
134 } 167 }
135 exports.isObject = isObject; 168 exports.isObject = isObject;
136 169
170 /**
171 * Checks if value is a javascript String
172 *
173 * @param mixed value
174 * @return Boolean
175 */
137 function isString(value) { 176 function isString(value) {
138 return isType(value, "string"); 177 return isType(value, "string");
139 } 178 }
...@@ -148,7 +187,10 @@ exports.isString = isString; ...@@ -148,7 +187,10 @@ exports.isString = isString;
148 * @return Boolean 187 * @return Boolean
149 */ 188 */
150 function isType(what, typeName) { 189 function isType(what, typeName) {
151 return betterTypeOf(what) === typeName; 190 if (typeof typeName !== "string" || !typeName) {
191 throw new Error("You must pass isType() a typeName string");
192 }
193 return betterTypeOf(what).toLowerCase() === typeName.toLowerCase();
152 } 194 }
153 exports.isType = isType; 195 exports.isType = isType;
154 196
...@@ -159,10 +201,10 @@ exports.isType = isType; ...@@ -159,10 +201,10 @@ exports.isType = isType;
159 * @return Boolean 201 * @return Boolean
160 */ 202 */
161 function isWebPage(what) { 203 function isWebPage(what) {
162 if (!what || !isType(what, "object")) { 204 if (!what || !isObject(what)) {
163 return false; 205 return false;
164 } 206 }
165 if (phantom.version.major <= 1 && phantom.version.minor < 3 && isType(require, "function")) { 207 if (phantom.version.major <= 1 && phantom.version.minor < 3 && isFunction(require)) {
166 return what instanceof WebPage; 208 return what instanceof WebPage;
167 } else { 209 } else {
168 return what.toString().indexOf('WebPage(') === 0; 210 return what.toString().indexOf('WebPage(') === 0;
...@@ -202,9 +244,34 @@ exports.mergeObjects = mergeObjects; ...@@ -202,9 +244,34 @@ exports.mergeObjects = mergeObjects;
202 function serialize(value) { 244 function serialize(value) {
203 if (isType(value, "array")) { 245 if (isType(value, "array")) {
204 value = value.map(function(prop) { 246 value = value.map(function(prop) {
205 return isType(prop, "function") ? prop.toString().replace(/\s{2,}/, '') : prop; 247 return isFunction(prop) ? prop.toString().replace(/\s{2,}/, '') : prop;
206 }); 248 });
207 } 249 }
208 return JSON.stringify(value, null, 4); 250 return JSON.stringify(value, null, 4);
209 } 251 }
210 exports.serialize = serialize; 252 exports.serialize = serialize;
253
254 /**
255 * Inherit the prototype methods from one constructor into another.
256 *
257 * The Function.prototype.inherits from lang.js rewritten as a standalone
258 * function (not on Function.prototype). NOTE: If this file is to be loaded
259 * during bootstrapping this function needs to be revritten using some native
260 * functions as prototype setup using normal JavaScript does not work as
261 * expected during bootstrapping (see mirror.js in r114903).
262 *
263 * @param {function} ctor Constructor function which needs to inherit the
264 * prototype.
265 * @param {function} superCtor Constructor function to inherit prototype from.
266 */
267 exports.inherits = function(ctor, superCtor) {
268 ctor.super_ = superCtor;
269 ctor.prototype = Object.create(superCtor.prototype, {
270 constructor: {
271 value: ctor,
272 enumerable: false,
273 writable: true,
274 configurable: true
275 }
276 });
277 };
......