Configuration and application
I believe I did one thing right when coding the theme. I have distinguished between javascript application and javascript configuration. Two objects are created withing WP namespace:
- Wp.bloginfo - printed by php theme configuration
- WP.theme - an application
During my read of AjaxWp instructions I have realized that all the things that Gianni Milanesi asks people to fill-in can be filled by Wordpress itself. I have created Wp.bloginfo object within header.php that is actually pronted by php.
<script> // Wp superglobals Wp.bloginfo = { url: ‘<?php bloginfo(‘url’); ?>/’, ajax_comments_url: ‘<?php bloginfo(‘template_url’); ?>/comments_ajax.php?comments_ajax’, title:’<?php bloginfo(‘title’); ?>‘, description:’<?php bloginfo(‘description’); ?>‘, template_url: ‘<?php bloginfo(‘template_url’); ?>‘, rss2_url: ‘<?php bloginfo(‘rss2_url’); ?>‘, comments_rss2_url: ‘<?php bloginfo(‘comments_rss2_url’); ?>‘, wp_query: ‘<?php _e(http_build_query($wp_query->query)); ?>’ }; </script>
The application, Wp.theme object reads Wp.bloginfo as a configuration. Here is - in short application - looks like:
<script> Ext.namespace(‘Wp’); Wp.theme = function() { return { init: function() { // application init } }; }(); </script>
As I said Wp.theme read Wp.bloginfo as a configuration. True, if you initialize application once it is configured. To put all this together I have came up with the following:
<script type="text/javascript" src="<?php bloginfo(’template_url’); ?>/js/theme.js"></script> <script type="text/javascript"> // Wp superglobals Wp.bloginfo = { url: ‘<?php bloginfo(’url‘); ?>/’, ajax_comments_url: ‘<?php bloginfo(’template_url‘); ?>/comments_ajax.php?comments_ajax’, title:‘<?php bloginfo(’title‘); ?>’, description:‘<?php bloginfo(’description‘); ?>’, template_url: ‘<?php bloginfo(’template_url‘); ?>’, rss2_url: ‘<?php bloginfo(’rss2_url‘); ?>’, comments_rss2_url: ‘<?php bloginfo(’comments_rss2_url‘); ?>’, wp_query: ‘<?php _e(http_build_query($wp_query->query)); ?>’ }; // blank image Ext.BLANK_IMAGE_URL = Wp.bloginfo.template_url +‘/ext/resources/images/default/s.gif’; // theme execution Ext.onReady(Wp.theme.init, Wp.theme); </script>
Testing theme =)
Great app
test
est
testando, m testando, m testando, m testando, m
well done