Committer: dpetrov
LJSUP-8151: E-mail-button is not workingU trunk/htdocs/js/share.js U trunk/templates/Browse/recent_posts.tmpl
Modified: trunk/htdocs/js/share.js =================================================================== --- trunk/htdocs/js/share.js 2011-03-17 09:01:52 UTC (rev 18612) +++ trunk/htdocs/js/share.js 2011-03-17 09:03:43 UTC (rev 18613) @@ -22,8 +22,13 @@ * "links": [ "twitter", "vkontakte", "moimir" ] //we want custom buttons there * }); * </script> +* +* You can attach single links: +* LJShare.entry( { url: "http://some.url.com/", title: "Post title", description: "Post description" } ) +* .attach( '#link_selector', 'service_name' ) +* .attach( jQuery( '#another_selector' ), 'service_name2' ) //we can pass nodes or jquery collections +* .link( '#selector', [ "twtter", "vkontakte", "moimir"] ); //also we can attach popup * -* */ function preload( srcArr ) { @@ -148,15 +153,16 @@ * @param Object opts Options object, may contain the following fields: * title, description, url - parameters of the page you want to share; * links - array of links that will be shown to the user in popup. +* @param String|Node|Jquery collection Node the popup has to be attached to. Default id a:last */ -window.LJShare.link = function( opts ) { +window.LJShare.link = function( opts, node ) { var defaults = { title: '', description: '', url: '' } - var link = jQuery( 'a:last' ), + var link = node || jQuery( 'a:last' ), url = link.attr( 'href' ), options = jQuery.extend( {}, defaults, { url: url } , opts ), dom, arrow, skipCloseEvent; @@ -285,6 +291,49 @@ skipCloseEvent = true; ev.preventDefault(); } ); + + return this; } +window.LJShare.entry = function( opts ) { + var defaults = { + title: '', + description: '', + url: '' + } + + var options = jQuery.extend( {}, defaults, opts ); + + return { + attach: function( node, service ) { + var link = jQuery( node ), + serviceObj = global_options.services[ service ]; + + if( service in global_options.services ) { + link.each( function() { + var url = supplant( serviceObj.bindLink, options ); + if( this.tagName.toLowerCase() === 'a' ) { + this.href = url; + this.target = "_blank"; + } else { + $( this ).click( function() { + window.open( url ); + } ); + } + } ); + } + + return this; + }, + + link: function( node, links ) { + var opts = jQuery.extend( {}, options, links ? { links: links } : null ); + LJShare.link( opts, ( node ) ? jQuery( node ) : null ); + + return this; + } + } + +} + } )( window, jQuery ); Modified: trunk/templates/Browse/recent_posts.tmpl =================================================================== --- trunk/templates/Browse/recent_posts.tmpl 2011-03-17 09:01:52 UTC (rev 18612) +++ trunk/templates/Browse/recent_posts.tmpl 2011-03-17 09:03:43 UTC (rev 18613) @@ -49,6 +49,17 @@ }()); </script> </tmpl_if> + <tmpl_if expr="lj_enabled('sharing')"> + <script type="text/javascript"> + (function() { + var ul = jQuery('ul:last'); + LJShare.entry( {url:'<tmpl_var url_to_post>', title: '<tmpl_var expr="ejs(subject)">'} ) + .attach( ul.find('.b-share-email a'), 'email' ) + .attach( ul.find('.b-share-fb a'), 'facebook' ) + .attach( ul.find('.b-share-twitter a'), 'twitter' ); + }()); + </script> + </tmpl_if> <p class="b-catalogue-item-comments"><span class="b-catalogue-comments-count"><a href="<tmpl_var url_to_post>#comments"><tmpl_var comments_count> comments</a> |</span> <a href="<tmpl_var url_to_post>?mode=reply">Leave comment</a></p> </li> </tmpl_loop>