Changeset 1042760
- Timestamp:
- 12/11/2014 03:37:34 PM (11 years ago)
- Location:
- edge-suite/trunk
- Files:
-
- 3 edited
-
edge-suite.php (modified) (1 diff)
-
includes/edge-suite-comp-builder.inc (modified) (7 diffs)
-
includes/edge-suite-comp.inc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
edge-suite/trunk/edge-suite.php
r874591 r1042760 178 178 else { 179 179 global $post; 180 if(isset($post->ID) ){180 if(isset($post->ID) && is_single()){ 181 181 $post_id = $post->ID; 182 182 $post_reference_id = get_post_meta($post_id, '_edge_composition', TRUE); -
edge-suite/trunk/includes/edge-suite-comp-builder.inc
r843602 r1042760 238 238 239 239 // Alter main JS edge file to so it calls custom JS from edge_drupal.js. 240 $ this->alterMainEdgeJs();240 $alteredMain = $this->alterMainEdgeJs(); 241 241 242 242 // Alter preload JS file so it calls custom JS from edge_drupal.js. 243 $ this->alterPreloaderJs();243 $alteredPreloader = $this->alterPreloaderJs(); 244 244 245 245 // Read in all the libraries and copy them to a shared edge library folder. 246 246 $this->readLibs($replace_libraries); 247 248 if (!$alteredMain && !$alteredPreloader && empty($this->edgeVersion)) { 249 $this->parseRuntimeVersion(); 250 } 247 251 248 252 // Move all assets (and the _edgeAction.js) … … 387 391 $this->preloaderFile = $js_file_tmp; 388 392 } 389 else {390 throw new Exception('Cannot find main JS edge file ' . $js_file_tmp . '.');391 }392 393 } 393 394 … … 401 402 */ 402 403 protected function alterMainEdgeJs() { 404 $altered = FALSE; 403 405 $file = $this->mainEdgeJS; 404 406 // Do an extensive file / permission check as this seems to fail with many server configs. … … 421 423 // The relevant JS structure (might be minified). 422 424 // (function($, Edge, compId){....})(jQuery, AdobeEdge, "MyProject");. 423 $pattern = '/}\)\(jQuery,\s?AdobeEdge,\s?\"([a-zA-Z0-9_-]*)\"/'; 425 // (function($, Edge, compId){....})(AdobeEdge.$, AdobeEdge, "MyProject"); 426 $pattern = '/}\)\((?:AdobeEdge\.\$|jQuery),\s?AdobeEdge,\s?\"([a-zA-Z0-9_-]*)\"/'; 424 427 $matches = array(); 425 428 $found = preg_match($pattern, $content, $matches); … … 434 437 $register_matches = array(); 435 438 if (preg_match($register_pattern, $content, $register_matches)) { 439 $altered = TRUE; 436 440 $opts = 'null'; 437 441 if (isset($register_matches[1])) { … … 441 445 $register_pattern_found = 0; 442 446 $content = preg_replace($register_pattern, $register_replace, $content, -1, $register_pattern_found); 443 } 444 else { 445 throw new Exception('Unable to alter register handler.'); 446 } 447 448 // Write modified file. 449 $fh = fopen($file, "w"); 450 fwrite($fh, $content); 451 fclose($fh); 447 448 // Write modified file. 449 $fh = fopen($file, "w"); 450 fwrite($fh, $content); 451 fclose($fh); 452 } 453 return $altered; 454 } 455 456 457 protected function parseRuntimeVersion(){ 458 $file = $this->tmpDir . '/' . $this->projectName . '.html'; 459 // Do an extensive file / permission check as this seems to fail with many server configs. 460 if(!file_exists($file)){ 461 throw new Exception('Main edge file ' . $file . ' does not exist.'); 462 } 463 464 if(!is_readable($file)){ 465 throw new Exception('Main edge file' . $file . ' exists but is not readable.'); 466 } 467 468 $content = file_get_contents($file); 469 if(!isset($content) || empty($content)){ 470 throw new Exception('Main edge file ' . $file . ' does exist, cleared is_readable check, but can not be read.'); 471 } 472 473 $runtime_pattern = '/animate\.adobe\.com\/runtime\/(\d\.\d\.\d)\//'; 474 $matches = array(); 475 if (preg_match($runtime_pattern, $content, $matches)) { 476 $this->edgeVersion = $matches[1]; 477 } 452 478 } 453 479 … … 555 581 */ 556 582 protected function alterPreloaderJs() { 557 $file = $this->preloaderFile; 558 $content = file_get_contents($file); 559 560 // Search for the loadResource function call. 561 $load_pattern = '/loadResources\(aLoader,\s?doDelayLoad\);/'; 562 563 // Replace original call with call to custom function, alters preload paths. 564 $load_replace = 'AdobeEdge.alterPreloadPaths(compId, aLoader, doDelayLoad, loadResources);'; 565 $content = preg_replace($load_pattern, $load_replace, $content); 566 567 // Search for the okToLaunchComposition function call. 568 $launch_pattern = '/AdobeEdge\.okToLaunchComposition\(compId\)/'; 569 570 // Replace original call with call to custom function, alters jQuery. 571 $launch_replace = 'AdobeEdge.alterOkToLaunchComposition(compId)'; 572 $content = preg_replace($launch_pattern, $launch_replace, $content); 573 574 // Find the end of the main JS function and inject to function calls to 575 // alter preContent and dlContent DOM, see JS function doc. 576 // Expected structure (might be minified). 577 // (function(compId){...})("MyProject"). 578 $dom_pattern = '/\}\)\(\s?\"' . $this->stageClass . '\"\);/'; 579 $dom_replace = 'AdobeEdge.alterDomPaths(preContent.dom, compId);' . "\n"; 580 $dom_replace .= 'AdobeEdge.alterDomPaths(dlContent.dom, compId);' . "\n"; 581 $dom_replace .= '})("' . $this->stageClass . '");'; 582 $content = preg_replace($dom_pattern, $dom_replace, $content); 583 584 // Write new file. 585 $fh = fopen($file, "w"); 586 fwrite($fh, $content); 587 fclose($fh); 583 $altered = FALSE; 584 585 if ($this->preloaderFile != NULL) { 586 $file = $this->preloaderFile; 587 $content = file_get_contents($file); 588 589 // Search for the loadResource function call. 590 $load_pattern = '/loadResources\(aLoader,\s?doDelayLoad\);/'; 591 592 if (preg_match($load_pattern, $content)) { 593 $altered = TRUE; 594 // Replace original call with call to custom function, alters preload paths. 595 $load_replace = 'AdobeEdge.alterPreloadPaths(compId, aLoader, doDelayLoad, loadResources);'; 596 $content = preg_replace($load_pattern, $load_replace, $content); 597 598 // Search for the okToLaunchComposition function call. 599 $launch_pattern = '/AdobeEdge\.okToLaunchComposition\(compId\)/'; 600 601 // Replace original call with call to custom function, alters jQuery. 602 $launch_replace = 'AdobeEdge.alterOkToLaunchComposition(compId)'; 603 $content = preg_replace($launch_pattern, $launch_replace, $content); 604 605 // Find the end of the main JS function and inject to function calls to 606 // alter preContent and dlContent DOM, see JS function doc. 607 // Expected structure (might be minified). 608 // (function(compId){...})("MyProject"). 609 $dom_pattern = '/\}\)\(\s?\"' . $this->stageClass . '\"\);/'; 610 $dom_replace = 'AdobeEdge.alterDomPaths(preContent.dom, compId);' . "\n"; 611 $dom_replace .= 'AdobeEdge.alterDomPaths(dlContent.dom, compId);' . "\n"; 612 $dom_replace .= '})("' . $this->stageClass . '");'; 613 $content = preg_replace($dom_pattern, $dom_replace, $content); 614 615 // Write new file. 616 $fh = fopen($file, "w"); 617 fwrite($fh, $content); 618 fclose($fh); 619 } 620 } 621 return $altered; 588 622 } 589 623 -
edge-suite/trunk/includes/edge-suite-comp.inc
r875934 r1042760 223 223 */ 224 224 function edge_suite_comp_render($definition_id, $styles = '', $data = array()) { 225 global $edge_suite; 225 226 $scripts = array(); 226 227 $stage = ''; … … 237 238 $preload_url = $project_path . '/' . $definition->project_name . '_edgePreload.js'; 238 239 239 $js_inline = 'window.AdobeEdge = window.AdobeEdge || {};'; 240 $js_inline .= 'window.AdobeEdge.pathPrefix = window.AdobeEdge.pathPrefix || {};'; 241 $js_inline .= "AdobeEdge.pathPrefix.libs = '" . $edge_lib_path . "';"; 242 $js_inline .= "AdobeEdge.pathPrefix.comps = AdobeEdge.pathPrefix.comps || {};"; 243 $js_inline .= "AdobeEdge.pathPrefix.comps['" . $definition->composition_id . "'] = '" . $project_path . "';"; 244 245 if(get_option('edge_suite_debug') == 1){ 246 $js_inline .= "AdobeEdge.edgesuiteDebug = 1;"; 247 } 248 249 if(get_option('edge_suite_jquery_noconflict') == 1){ 250 $js_inline .= "AdobeEdge.edgesuiteNoConflict = 1;"; 251 } 252 253 $scripts = array(); 254 $scripts[] = '<script type="text/javascript">' . $js_inline . '</script>'; 255 $scripts[] = '<script type="text/javascript" src="' . plugins_url('/edge-suite') . '/includes/edge-wordpress.js"></script>'; 256 $scripts[] = '<script type="text/javascript" src="' . $preload_url . '"></script>'; 257 258 259 $div_id = 'Stage_' . $definition->project_name_unique; 260 261 // Add dimension if it was possible to parse them. This avoids jumping of the 262 // empty divs when using multiple instances on one page. 263 $height = ''; 264 if (isset($definition->info->height) && intval($definition->info->height) > 0) { 265 $height = 'height:' . $definition->info->height . ';'; 266 } 267 268 $width = ''; 269 if (isset($definition->info->width) && intval($definition->info->width) > 0) { 270 $width = 'width:' . $definition->info->width . ';'; 271 } 272 273 // Generate JSON data for more advanced animations, if supplied. 274 $data_string = ''; 275 if (isset($data) && !empty($data)) { 276 $data_string = '<script class="data" type="text/data">' . json_encode($data) . '</script>'; 277 } 278 279 // Put everything together. 280 $stage = '<div id="' . $div_id . '" style="' . $height . $width . $styles . '" class="' . $definition->composition_id . '">' . $data_string . '</div>'; 281 240 $runtime_version = !isset($definition->info->version) || empty($definition->info->version) ? NULL : $definition->info->version; 241 if (!isset($edge_suite->runtime_version) || $runtime_version == NULL || $runtime_version == $edge_suite->runtime_version) { 242 if (!isset($edge_suite->runtime_version) && $runtime_version != NULL) { 243 $edge_suite->runtime_version = $runtime_version; 244 } 245 246 if (isset($definition->info->version) && !empty($definition->info->version) && $definition->info->version >= 5) { 247 $js_inline = ''; 248 if ($edge_suite->runtime_version == $definition->info->version) { 249 $edge_suite->runtime_version = $definition->info->version; 250 251 if (!isset($edge_suite->runtime_added)) { 252 $edge_suite->runtime_added = TRUE; 253 $runtime = "//animate.adobe.com/runtime/" . $definition->info->version . "/edge." . $definition->info->version . ".min.js"; 254 // Mainly copied from the .html file of an OAM. To make multiple 255 // compositions on one page work the runtime can only be loaded 256 // once. When the runtime has loaded, ALL compositions on the page 257 // need to be triggered to load, not just one. Therefor ES registers 258 // each comp in a special variable (EdgeSuite.compositions) and 259 // triggers all comps with their respective data. 260 $js_inline .= 'var script = document.createElement("script"); 261 script.type= "text/javascript"; 262 script.src = "' . $runtime . '"; 263 var head = document.getElementsByTagName("head")[0], done=false; 264 script.onload = script.onreadystatechange = function(){ 265 if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) { 266 done=true; 267 for(var c = 0; c < EdgeSuite.compositions.length; c++){ 268 var comp = EdgeSuite.compositions[c]; 269 var preloader = comp.hasPreloaderFile ? null : {}; 270 var dlstage = preloader; 271 AdobeEdge.loadComposition(comp.name, comp.id, {htmlRoot:comp.path, bScaleToParent:"true"}, preloader, dlstage); 272 } 273 script.onload = script.onreadystatechange = null; 274 head.removeChild(script); 275 } 276 }; 277 head.appendChild(script);'; 278 } 279 280 // Add composition data. 281 $js_inline .= 'window.EdgeSuite = window.EdgeSuite || {compositions:[]};'; 282 // If hasPreloaderFile is false then the above JS code will pass empty 283 // objects as preloader and donwlevel stage options to the 284 // loadComposition call. Otherwise EA will try to load a preloader 285 // file. 286 $comp_js_data = array( 287 'name' => $definition->project_name, 288 'id' => $definition->composition_id, 289 'path' => $project_path . '/', 290 'hasPreloaderFile' => file_exists($preload_url) 291 ); 292 $js_inline .= 'window.EdgeSuite.compositions.push(' . json_encode($comp_js_data) . ')'; 293 294 // Clean up JS code, remove linebreaks and leading line spaces. 295 $js_inline = preg_replace("/\n(\s)*/", "", $js_inline); 296 } 297 else { 298 $js_inline = 'console.log("Compositions with varying runtime versions have been detected. This would cause all compositions to fail, some have been disabled. Upgrade older compositions to the current runtime.");'; 299 } 300 $scripts[] = '<script type="text/javascript">' . $js_inline . '</script>'; 301 } 302 else { 303 $js_inline = 'window.AdobeEdge = window.AdobeEdge || {};'; 304 $js_inline .= 'window.AdobeEdge.pathPrefix = window.AdobeEdge.pathPrefix || {};'; 305 $js_inline .= "AdobeEdge.pathPrefix.libs = '" . $edge_lib_path . "';"; 306 $js_inline .= "AdobeEdge.pathPrefix.comps = AdobeEdge.pathPrefix.comps || {};"; 307 $js_inline .= "AdobeEdge.pathPrefix.comps['" . $definition->composition_id . "'] = '" . $project_path . "';"; 308 309 if (get_option('edge_suite_debug') == 1) { 310 $js_inline .= "AdobeEdge.edgesuiteDebug = 1;"; 311 } 312 313 if (get_option('edge_suite_jquery_noconflict') == 1) { 314 $js_inline .= "AdobeEdge.edgesuiteNoConflict = 1;"; 315 } 316 317 $scripts[] = '<script type="text/javascript">' . $js_inline . '</script>'; 318 $scripts[] = '<script type="text/javascript" src="' . plugins_url('/edge-suite') . '/includes/edge-wordpress.js"></script>'; 319 $scripts[] = '<script type="text/javascript" src="' . $preload_url . '"></script>'; 320 } 321 322 $div_id = 'Stage_' . $definition->project_name_unique; 323 324 // Add dimension if it was possible to parse them. This avoids jumping of the 325 // empty divs when using multiple instances on one page. 326 $height = ''; 327 if (isset($definition->info->height) && intval($definition->info->height) > 0) { 328 $height = 'height:' . $definition->info->height . ';'; 329 } 330 331 $width = ''; 332 if (isset($definition->info->width) && intval($definition->info->width) > 0) { 333 $width = 'width:' . $definition->info->width . ';'; 334 } 335 336 // Generate JSON data for more advanced animations, if supplied. 337 $data_string = ''; 338 if (isset($data) && !empty($data)) { 339 $data_string = '<script class="data" type="text/data">' . json_encode($data) . '</script>'; 340 } 341 342 // Put everything together. 343 $stage = '<div id="' . $div_id . '" style="' . $height . $width . $styles . '" class="' . $definition->composition_id . '">' . $data_string . '</div>'; 344 } 345 else { 346 $js_inline = 'console.log("Edge Suite - Compositions with varying runtime versions have been detected. This would cause all compositions to fail, therefore some animations have been disabled. Upgrade older compositions to the current runtime.");'; 347 $scripts[] = '<script type="text/javascript">' . $js_inline . '</script>'; 348 } 282 349 } 283 350
Note: See TracChangeset
for help on using the changeset viewer.