Permalink
Browse files

Rework templates for link replacement (GH #25)

To make it easier to change the link replacement javascript,
it has been moved into overridable templates default_convertlinks.php.
The links are also now placed in a span of class 'wordbridge_link_set'
which will make it easier to CSS style the replaced links.
  • Loading branch information...
1 parent d92bb77 commit 92ab937121b0476e777b93165c8e8f61131c1ef4 Vittal Aithal committed Apr 16, 2012
@@ -156,5 +156,6 @@
<?php
if ( $this->convertLinks )
{
- include_once( JPATH_COMPONENT.DS.'views'.DS.'entries'.DS.'tmpl'.DS.'convert_links.php' );
+ JHTML::_( 'behavior.mootools' );
+ echo $this->loadTemplate( 'convertlinks' );
}
@@ -1,6 +1,3 @@
-<?php
- JHTML::_('behavior.mootools');
-?>
<script type="text/javascript">
<!--
window.addEvent('domready',function() {
@@ -11,12 +8,22 @@
var wp_link_str = 'https?://feeds.wordpress.com/1.0/(';
for (var k in wp_link_map) { wp_link_str += k + '|'; }
var wp_link_re = new RegExp(wp_link_str.substr(0, wp_link_str.length - 1) + ')/');
+ var wp_link_set_idx = 0;
$$('div.wordbridge_content img').each(function(img){
var wp_link_match = img.src.match(wp_link_re);
if (wp_link_match != null) {
var el = new Element('span', { html: wp_link_map[wp_link_match[1]] });
el.replaces(img);
- el.getParent().addClass(wp_link_class);
+ var link = el.getParent();
+ link.addClass(wp_link_class);
+ if (!link.getParent().hasClass('wordbridge_converted_links')) {
+ link.getParent().addClass('wordbridge_converted_links');
+ wp_link_set_idx++;
+ var container = new Element("span", { id: 'wordbridge_wp_link_set_' + wp_link_set_idx, class: 'wordbridge_link_set' }).inject(link, "before");
+ link.inject(container, 'bottom');
+ } else {
+ $('wordbridge_wp_link_set_' + wp_link_set_idx).grab(link, 'bottom');
+ }
}
});
});
@@ -71,5 +71,6 @@
<?php
if ( $this->convertLinks )
{
- include_once( JPATH_COMPONENT.DS.'views'.DS.'entries'.DS.'tmpl'.DS.'convert_links.php' );
+ JHTML::_( 'behavior.mootools' );
+ echo $this->loadTemplate( 'convertlinks' );
}
@@ -1,6 +1,3 @@
-<?php
- JHTML::_('behavior.mootools');
-?>
<script type="text/javascript">
<!--
window.addEvent('domready',function() {
@@ -11,12 +8,22 @@
var wp_link_str = 'https?://feeds.wordpress.com/1.0/(';
for (var k in wp_link_map) { wp_link_str += k + '|'; }
var wp_link_re = new RegExp(wp_link_str.substr(0, wp_link_str.length - 1) + ')/');
+ var wp_link_set_idx = 0;
$$('div.wordbridge_content img').each(function(img){
var wp_link_match = img.src.match(wp_link_re);
if (wp_link_match != null) {
var el = new Element('span', { html: wp_link_map[wp_link_match[1]] });
el.replaces(img);
- el.getParent().addClass(wp_link_class);
+ var link = el.getParent();
+ link.addClass(wp_link_class);
+ if (!link.getParent().hasClass('wordbridge_converted_links')) {
+ link.getParent().addClass('wordbridge_converted_links');
+ wp_link_set_idx++;
+ var container = new Element("span", { id: 'wordbridge_wp_link_set_' + wp_link_set_idx, class: 'wordbridge_link_set' }).inject(link, "before");
+ link.inject(container, 'bottom');
+ } else {
+ $('wordbridge_wp_link_set_' + wp_link_set_idx).grab(link, 'bottom');
+ }
}
});
});
@@ -157,5 +157,6 @@
<?php
if ( $this->convertLinks )
{
- include_once( JPATH_COMPONENT.DS.'views'.DS.'entries'.DS.'tmpl'.DS.'convert_links.php' );
+ JHTML::_( 'behavior.mootools' );
+ echo $this->loadTemplate( 'convertlinks' );
}
@@ -0,0 +1,31 @@
+<script type="text/javascript">
+<!--
+window.addEvent('domready',function() {
+ var wp_link_class = 'wordbridge_wp_link';
+ var wp_link_map = { 'comments' : '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_COMMENT' ); ?>', 'facebook' : '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_FACEBOOK' ); ?>',
+ 'twitter' : '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_TWEET' ); ?>', 'stumble' : '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_STUMBLE' ); ?>', 'digg' : '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_DIGG' ); ?>',
+ 'reddit': '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_REDDIT' ); ?>' };
+ var wp_link_str = 'https?://feeds.wordpress.com/1.0/(';
+ for (var k in wp_link_map) { wp_link_str += k + '|'; }
+ var wp_link_re = new RegExp(wp_link_str.substr(0, wp_link_str.length - 1) + ')/');
+ var wp_link_set_idx = 0;
+ $$('div.wordbridge_content img').each(function(img){
+ var wp_link_match = img.src.match(wp_link_re);
+ if (wp_link_match != null) {
+ var el = new Element('span', { html: wp_link_map[wp_link_match[1]] });
+ el.replaces(img);
+ var link = el.getParent();
+ link.addClass(wp_link_class);
+ if (!link.getParent().hasClass('wordbridge_converted_links')) {
+ link.getParent().addClass('wordbridge_converted_links');
+ wp_link_set_idx++;
+ var container = new Element("span", { id: 'wordbridge_wp_link_set_' + wp_link_set_idx, class: 'wordbridge_link_set' }).inject(link, "before");
+ link.inject(container, 'bottom');
+ } else {
+ $('wordbridge_wp_link_set_' + wp_link_set_idx).grab(link, 'bottom');
+ }
+ }
+ });
+});
+// -->
+</script>
@@ -71,5 +71,6 @@
<?php
if ( $this->convertLinks )
{
- include_once( JPATH_COMPONENT.DS.'views'.DS.'entries'.DS.'tmpl'.DS.'convert_links.php' );
+ JHTML::_( 'behavior.mootools' );
+ echo $this->loadTemplate( 'convertlinks' );
}
@@ -0,0 +1,31 @@
+<script type="text/javascript">
+<!--
+window.addEvent('domready',function() {
+ var wp_link_class = 'wordbridge_wp_link';
+ var wp_link_map = { 'comments' : '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_COMMENT' ); ?>', 'facebook' : '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_FACEBOOK' ); ?>',
+ 'twitter' : '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_TWEET' ); ?>', 'stumble' : '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_STUMBLE' ); ?>', 'digg' : '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_DIGG' ); ?>',
+ 'reddit': '<?php echo JText::_( 'COM_WORDBRIDGE_LINK_ADD_REDDIT' ); ?>' };
+ var wp_link_str = 'https?://feeds.wordpress.com/1.0/(';
+ for (var k in wp_link_map) { wp_link_str += k + '|'; }
+ var wp_link_re = new RegExp(wp_link_str.substr(0, wp_link_str.length - 1) + ')/');
+ var wp_link_set_idx = 0;
+ $$('div.wordbridge_content img').each(function(img){
+ var wp_link_match = img.src.match(wp_link_re);
+ if (wp_link_match != null) {
+ var el = new Element('span', { html: wp_link_map[wp_link_match[1]] });
+ el.replaces(img);
+ var link = el.getParent();
+ link.addClass(wp_link_class);
+ if (!link.getParent().hasClass('wordbridge_converted_links')) {
+ link.getParent().addClass('wordbridge_converted_links');
+ wp_link_set_idx++;
+ var container = new Element("span", { id: 'wordbridge_wp_link_set_' + wp_link_set_idx, class: 'wordbridge_link_set' }).inject(link, "before");
+ link.inject(container, 'bottom');
+ } else {
+ $('wordbridge_wp_link_set_' + wp_link_set_idx).grab(link, 'bottom');
+ }
+ }
+ });
+});
+// -->
+</script>

0 comments on commit 92ab937

Please sign in to comment.