SHOW:
|
|
- or go back to the newest paste.
| 1 | <?PHP | |
| 2 | require_once './illi.class.hlp.php'; | |
| 3 | $JS = new JS(); | |
| 4 | $JS->load(array( | |
| 5 | 'javascript/jquery/jquery-1.5.1.min.js', | |
| 6 | 'javascript/jquery/jquery-ui-1.8.11.custom.min.js', | |
| 7 | 'javascript/jquery/jquery-1.5.1.ext.js', | |
| 8 | //'javascript/thickbox.js' | |
| 9 | )); | |
| 10 | print $JS->render();?> | |
| 11 | ||
| 12 | (function( $ ){
| |
| 13 | $.xtcmApp = {version: '0.0.2', vision: 'idle in roflcopter', jquery: '1.5.1', author: '~lvm', web: 'http://illi.be'};
| |
| 14 | ||
| 15 | $.xtcmApp.global = | |
| 16 | {
| |
| 17 | /** | |
| 18 | * not in use | |
| 19 | * @see $.xtcmApp.initProto() | |
| 20 | */ | |
| 21 | __SUPER__ : | |
| 22 | {
| |
| 23 | __METHOD__ : | |
| 24 | {
| |
| 25 | __QUEUE__ : { initialize : function(){} },
| |
| 26 | __REGISTRY__ : { initialize : function(){} }
| |
| 27 | }, | |
| 28 | __VARIABLE__ : | |
| 29 | {
| |
| 30 | __VALUE__ : { initialize : function(){} },
| |
| 31 | __REGISTRY__ : { initialize : function(){} }
| |
| 32 | } | |
| 33 | }, | |
| 34 | /** | |
| 35 | * CLASS LIB | |
| 36 | * | |
| 37 | * @see $.xtcmApp.initProto() | |
| 38 | */ | |
| 39 | __CLASS__ : | |
| 40 | {
| |
| 41 | __METHOD__ : | |
| 42 | {
| |
| 43 | /** | |
| 44 | * method queue | |
| 45 | * | |
| 46 | * @param runonce bool true: terminate queue on exec | |
| 47 | * | |
| 48 | * // some stuff | |
| 49 | * var test11 = function(){alert('test1.1')};
| |
| 50 | * var test12 = function(){alert('test1.2')};
| |
| 51 | * | |
| 52 | * // default queue | |
| 53 | * var bar = new $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__(); | |
| 54 | * bar.push(test11).push(test12) | |
| 55 | * .execute() // test1.1 test1.2 | |
| 56 | * .execute(); // test1.1 test1.2 | |
| 57 | * | |
| 58 | * // run-once queue | |
| 59 | * var baz = new $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__(true); | |
| 60 | * baz.push(test11).push(test12) | |
| 61 | * .execute() // test1.1 test1.2 | |
| 62 | * .execute(); // nothing | |
| 63 | */ | |
| 64 | __QUEUE__ : function(runonce) | |
| 65 | {
| |
| 66 | var __queue = new Array(); | |
| 67 | var __runonce = (runonce !== true) ? false : true; | |
| 68 | ||
| 69 | /** | |
| 70 | * add function to queue | |
| 71 | * | |
| 72 | * @param fn function | |
| 73 | * @return $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__(); | |
| 74 | */ | |
| 75 | this.push = function(fn) | |
| 76 | {
| |
| 77 | __queue.push(fn); | |
| 78 | return this; | |
| 79 | } | |
| 80 | ||
| 81 | /** | |
| 82 | * execute queue | |
| 83 | * | |
| 84 | * @return $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__(); | |
| 85 | */ | |
| 86 | this.execute = function() | |
| 87 | {
| |
| 88 | if(__queue.length === 0) | |
| 89 | return this; | |
| 90 | ||
| 91 | if(__runonce === false) | |
| 92 | for(i in __queue) __queue[i](); | |
| 93 | else | |
| 94 | while(__queue.length > 0) (__queue.shift())(); | |
| 95 | ||
| 96 | return this; | |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * terminate queue | |
| 101 | * | |
| 102 | * @return $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__(); | |
| 103 | */ | |
| 104 | this.reset = function() | |
| 105 | {
| |
| 106 | __queue = new Array(); | |
| 107 | return this; | |
| 108 | } | |
| 109 | }, | |
| 110 | /** | |
| 111 | * method queue registry | |
| 112 | * | |
| 113 | * // some stuff | |
| 114 | * var test11 = function(){alert('test1.1')};
| |
| 115 | * var test12 = function(){alert('test1.2')};
| |
| 116 | * var test21 = function(){alert('test2.1')};
| |
| 117 | * var test22 = function(){alert('test2.2')};
| |
| 118 | * | |
| 119 | * // create registry queue | |
| 120 | * var foo = new $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__(); | |
| 121 | * | |
| 122 | * // default queue | |
| 123 | * foo.register('test1').push('test1', test11).push('test1', test12)
| |
| 124 | * .execute('test1') // test1.1 test1.2
| |
| 125 | * .execute('test1'); // test1.1 test1.2
| |
| 126 | * | |
| 127 | * // run-once queue | |
| 128 | * foo.register('test2', true).push('test2', test11).push('test2', test12)
| |
| 129 | * .execute('test2') // test1.1 test1.2
| |
| 130 | * .execute('test2'); // nothing
| |
| 131 | * | |
| 132 | * | |
| 133 | * // shorthand: | |
| 134 | * // default queue | |
| 135 | * foo.get('test3').push(test21).push(test22)
| |
| 136 | * .execute() // test2.1 test2.2 | |
| 137 | * .execute(); // test2.1 test2.2 | |
| 138 | * | |
| 139 | * // run-once queue | |
| 140 | * foo.get('test4', true).push(test21).push(test22)
| |
| 141 | * .execute() // test2.1 test2.2 | |
| 142 | * .execute(); // nothing | |
| 143 | * | |
| 144 | */ | |
| 145 | __REGISTRY__ : function() | |
| 146 | {
| |
| 147 | var __queue = new $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__(); | |
| 148 | ||
| 149 | /** | |
| 150 | * register queue instance | |
| 151 | * | |
| 152 | * @param name string instance-name | |
| 153 | * @param runonce bool | |
| 154 | * @see $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__() | |
| 155 | * @see $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__.register() | |
| 156 | * @return $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__() | |
| 157 | */ | |
| 158 | this.register = function(name, runonce) | |
| 159 | {
| |
| 160 | __queue.register(name, new $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__(runonce), true); | |
| 161 | return this; | |
| 162 | } | |
| 163 | ||
| 164 | /** | |
| 165 | * isset instance | |
| 166 | * | |
| 167 | * @param name string instance-name | |
| 168 | * @see $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__.isset() | |
| 169 | * @return bool $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__.isset() | |
| 170 | */ | |
| 171 | this.isset = function(name) | |
| 172 | {
| |
| 173 | return __queue.isset(name); | |
| 174 | } | |
| 175 | ||
| 176 | /** | |
| 177 | * get/create queue instance | |
| 178 | * | |
| 179 | * @param name string instance-name | |
| 180 | * @param runonce bool | |
| 181 | * @see $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__.get() | |
| 182 | * @return mixed $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__.get() | |
| 183 | */ | |
| 184 | this.get = function(name, runonce) | |
| 185 | {
| |
| 186 | if(this.isset(name) === false) | |
| 187 | this.register(name, runonce); | |
| 188 | return __queue.get(name); | |
| 189 | } | |
| 190 | ||
| 191 | /** | |
| 192 | * execute queue of instance | |
| 193 | * | |
| 194 | * @param name string instance-name | |
| 195 | * @see $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__.execute() | |
| 196 | * @return $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__(); | |
| 197 | */ | |
| 198 | this.execute = function(name) | |
| 199 | {
| |
| 200 | if(this.isset(name) === true) | |
| 201 | this.get(name).execute(); | |
| 202 | return this; | |
| 203 | } | |
| 204 | ||
| 205 | /** | |
| 206 | * terminate queue | |
| 207 | * | |
| 208 | * @see $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__.reset() | |
| 209 | * @return $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__(); | |
| 210 | */ | |
| 211 | this.reset = function(name) | |
| 212 | {
| |
| 213 | if(this.isset(name) === true) | |
| 214 | this.get(name).reset(); | |
| 215 | return this; | |
| 216 | } | |
| 217 | ||
| 218 | /** | |
| 219 | * add function to queue of instance | |
| 220 | * | |
| 221 | * @param name string instance-name | |
| 222 | * @param fn function | |
| 223 | * @see $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__.push() | |
| 224 | * @return $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__(); | |
| 225 | */ | |
| 226 | this.push = function(name, fn) | |
| 227 | {
| |
| 228 | if(this.isset(name) === true) | |
| 229 | this.get(name).push(fn); | |
| 230 | return this; | |
| 231 | } | |
| 232 | } | |
| 233 | }, | |
| 234 | __VARIABLE__ : | |
| 235 | {
| |
| 236 | /** | |
| 237 | * value for value-queue | |
| 238 | * | |
| 239 | * overwrite is allowed or not | |
| 240 | * | |
| 241 | * @param value mixed | |
| 242 | * @param protect bool true: can not overwrite existing value | |
| 243 | */ | |
| 244 | __VALUE__ : function(value, protect) | |
| 245 | {
| |
| 246 | var __value = value || null; | |
| 247 | var __protect = (protect === true) ? true : false; | |
| 248 | ||
| 249 | /** | |
| 250 | * get value | |
| 251 | * @return mixed | |
| 252 | */ | |
| 253 | this.get = function(){ return __value; }
| |
| 254 | /** | |
| 255 | * set value | |
| 256 | * | |
| 257 | * this has no effect, if __protect is true | |
| 258 | * @return $.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__(); | |
| 259 | */ | |
| 260 | this.set = function(value){ if(__protect === true) return this; __value = value; return this; }
| |
| 261 | }, | |
| 262 | /** | |
| 263 | * value-queue | |
| 264 | * | |
| 265 | * store vars with values | |
| 266 | * | |
| 267 | * // new value-queue | |
| 268 | * var foo = new $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__(); | |
| 269 | * | |
| 270 | * // var "baz" | |
| 271 | * foo.register('baz', 'baz: bar'); alert(foo.get('baz')); // baz: bar
| |
| 272 | * foo.set('baz', 'baz: bar -> foo'); alert(foo.get('baz')); // baz: foo
| |
| 273 | * | |
| 274 | * // protected var "foo" | |
| 275 | * foo.register('foo', 'foo: lol', true); alert(foo.get('foo')); // foo: lol
| |
| 276 | * foo.set('foo', 'foo: lol -> rofl'); alert(foo.get('foo')); // foo: lol
| |
| 277 | */ | |
| 278 | __REGISTRY__ : function() | |
| 279 | {
| |
| 280 | var __queue = new Object(); | |
| 281 | ||
| 282 | /** | |
| 283 | * register value-instance | |
| 284 | * | |
| 285 | * @param name string instance-name | |
| 286 | * @param value mixed | |
| 287 | * @param protect bool true: can not overwrite existing value | |
| 288 | * @see $.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__(); | |
| 289 | * @return $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__(); | |
| 290 | */ | |
| 291 | this.register = function(name, value, protect) | |
| 292 | {
| |
| 293 | if(this.isset(name) === false) | |
| 294 | __queue[name] = new $.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__(value, protect); | |
| 295 | ||
| 296 | return this; | |
| 297 | } | |
| 298 | ||
| 299 | /** | |
| 300 | * isset instance | |
| 301 | * | |
| 302 | * @param name string instance-name | |
| 303 | * @return bool | |
| 304 | */ | |
| 305 | this.isset = function(name) | |
| 306 | {
| |
| 307 | return (!__queue[name]) ? false : true; | |
| 308 | } | |
| 309 | ||
| 310 | /** | |
| 311 | * get value of instance | |
| 312 | * | |
| 313 | * @param name string instance-name | |
| 314 | * @see $.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__.get() | |
| 315 | * @return $.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__.get() || NULL | |
| 316 | */ | |
| 317 | this.get = function(name) | |
| 318 | {
| |
| 319 | return ((this.isset(name) === true) ? __queue[name].get() : null); | |
| 320 | } | |
| 321 | ||
| 322 | /** | |
| 323 | * set value of instance | |
| 324 | * | |
| 325 | * @param name string instance-name | |
| 326 | * @param value mixed | |
| 327 | * @see $.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__.set() | |
| 328 | * @return $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__() | |
| 329 | */ | |
| 330 | this.set = function(name, value) | |
| 331 | {
| |
| 332 | - | if(this.isset(name) === true)) |
| 332 | + | |
| 333 | this.set(value); | |
| 334 | return this; | |
| 335 | } | |
| 336 | ||
| 337 | } | |
| 338 | } | |
| 339 | } | |
| 340 | } | |
| 341 | ||
| 342 | $.fn.xtcmApp = function(SETTINGS) | |
| 343 | {
| |
| 344 | ||
| 345 | var initProto = function() | |
| 346 | {
| |
| 347 | $.extend($.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__.prototype, $.xtcmApp.global.__SUPER__.__METHOD__.__QUEUE__); | |
| 348 | $.extend($.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__.prototype, $.xtcmApp.global.__SUPER__.__METHOD__.__REGISTRY__); | |
| 349 | $.extend($.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__.prototype, $.xtcmApp.global.__SUPER__.__VARIABLE__.__VALUE__); | |
| 350 | $.extend($.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__.prototype, $.xtcmApp.global.__SUPER__.__VARIABLE__.__REGISTRY__); | |
| 351 | }; | |
| 352 | ||
| 353 | var test = | |
| 354 | {
| |
| 355 | methodqueue : function() | |
| 356 | {
| |
| 357 | var test11 = function(){alert('test1.1')};
| |
| 358 | var test12 = function(){alert('test1.2')};
| |
| 359 | var test21 = function(){alert('test2.1')};
| |
| 360 | var test22 = function(){alert('test2.2')};
| |
| 361 | ||
| 362 | var foo = new $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__(); | |
| 363 | foo.get('test3').push(test11).push(test12)
| |
| 364 | .execute() // test2.1 test2.2 | |
| 365 | .execute(); // test2.1 test2.2 | |
| 366 | ||
| 367 | foo.get('test4', true).push(test21).push(test22)
| |
| 368 | .execute() // test2.1 test2.2 | |
| 369 | .execute(); // nothing | |
| 370 | } | |
| 371 | }; | |
| 372 | ||
| 373 | $.xtcmApp.initialize = function() | |
| 374 | {
| |
| 375 | test.methodqueue(); | |
| 376 | }; | |
| 377 | ||
| 378 | ||
| 379 | $.xtcmApp.initialize(); | |
| 380 | }; | |
| 381 | ||
| 382 | ||
| 383 | })( jQuery ); | |
| 384 | ||
| 385 | ||
| 386 | jQuery(document).ready(function($) | |
| 387 | {
| |
| 388 | $('body').xtcmApp();
| |
| 389 | }); |