Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Commit

Permalink
Rework templates for link replacement (GH #25)
Browse files Browse the repository at this point in the history
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
Vittal Aithal committed Apr 16, 2012
1 parent d92bb77 commit 92ab937
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 12 deletions.
Expand Up @@ -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() {
Expand All @@ -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');
}
}
});
});
Expand Down
3 changes: 2 additions & 1 deletion joomla_1.5/com_wordbridge/site/views/entry/tmpl/default.php
Expand Up @@ -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() {
Expand All @@ -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');
}
}
});
});
Expand Down
Expand Up @@ -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>
3 changes: 2 additions & 1 deletion joomla_1.6/com_wordbridge/site/views/entry/tmpl/default.php
Expand Up @@ -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.