| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- /* jshint onevar: false, smarttabs: true */
- /* global tb_show, tb_pathToImage, ajaxurl, tb_init, tb_remove */
- /* global myblogsResponse, publicizeConnTestStart:true, publicizeConnTestComplete:true, publicizeConnRefreshClick:true */
- var showOptionsPage;
- jQuery( function( $ ) {
- showOptionsPage = function( service, nonce, connection, blogId ) {
- tb_show( null, null, null );
- $('body').append( '<div id=\'TB_load\'><img src=\'' + tb_pathToImage + '\' /></div>' );
- $('#TB_load').show();
- var query = '';
- if ( connection ) {
- query += '&connection=' + encodeURIComponent( connection );
- }
- if ( 'undefined' !== typeof( blogId ) && blogId ) {
- query += '&blog_id=' + Number( blogId );
- }
- $.post( ajaxurl, 'action=publicize_' + service + '_options_page&_wpnonce=' + nonce + query, function( response ) {
- $('#TB_load').remove();
- try {
- var obj = jQuery.parseJSON( response );
- if ( obj && 'object' === typeof( obj ) ) {
- if ( obj.hasOwnProperty( 'fb_redirect' ) ) {
- location.href = obj.fb_redirect + '&redirect_uri=' + encodeURIComponent( location.href );
- return;
- }
- }
- } catch (err) {
- // Do nothing and move on
- }
- if ( response ) {
- var blogID = $( 'input[name=wpas_ajax_blog_id]' ).val();
- var message = $( '<div id="wpas-ajax-' + blogID + '" class="wrap"></div>' ).append( response );
- message.append( '<a href="#TB_inline?thickbox&height=420&width=555&inlineId=wpas-ajax-' + blogID + '" id="wpas-click-' + blogID + '" class="new-thickbox" style="display: none;"></a>' );
- $('#wpas-message').html( message );
- tb_init( 'a.new-thickbox' );
- $('#wpas-click-' + blogID).click();
- var tb_height = parseInt( $('#TB_ajaxContent').css('height'), 10 );
- var content_height = $('#thickbox-content').height();
- if ( content_height < tb_height ) {
- var new_height = content_height + 15;
- $('#TB_ajaxContent').css( 'height', new_height );
- var new_margin = parseInt( $('#TB_window').css( 'margin-top'), 10 ) + (tb_height - new_height) / 2 + 'px';
- $('#TB_window').css( 'margin-top', new_margin);
- }
- $('.save-options').unbind('click').click( function() {
- var sel = $( 'input[name=\'option\']:checked' );
- var global = $( 'input[name=\'global\']:checked' );
- var connection = $(this).data('connection');
- var token = encodeURIComponent( sel.val() );
- var id = encodeURIComponent( sel.attr( 'id' ) );
- var type = encodeURIComponent( sel.attr( 'data-type' ) );
- var nonce = $(this).attr('rel');
- var global_conn = 'off';
- var global_nonce = '';
- if ( global.length ) {
- global_conn = 'on';
- global_nonce = global.val();
- }
- $.post( ajaxurl, 'action=publicize_'+ service + '_options_save&connection=' + connection + '&selected_id=' + id + '&token=' + token + '&type=' + type + '&_wpnonce=' + nonce + '&global=' + global_conn + '&global_nonce=' + global_nonce, function( /*response*/ ) {
- var frameNonce;
- tb_remove();
- frameNonce = document.location.search.match( /frame-nonce=([^&]+)/ );
- if ( /inside-newdash=1/.test( document.location.search ) && frameNonce ) {
- document.location = 'options-general.php?page=sharing&inside-newdash=1&frame-nonce' + frameNonce[1];
- } else {
- top.location = 'options-general.php?page=sharing';
- }
- } );
- } );
- }
- }, 'html' );
- };
- $( 'body' ).append( '<div id="wpas-message" style="display: none"></div>' );
- $( '.wpas-posts' ).change( function() {
- var inputs = $(this).parents( 'td:first' ).find( ':input' );
- var _this = this;
- var blogID = inputs.filter( '[name=wpas_ajax_blog_id]' ).val();
- $( '#waiting_' + blogID ).show();
- $.post( ajaxurl, inputs.serialize() + '&action=wpas_post', function( response ) { myblogsResponse.call( _this, blogID, response ); }, 'html' );
- } );
- $( '.options' ).unbind('click').bind( 'click', function(e) {
- e.preventDefault();
- e.stopPropagation();
- var service = $(this).attr('class').replace( 'options ', '' );
- var blogId = null;
- if ( 'undefined' !== typeof( $(this).attr('id') ) ) {
- blogId = parseInt( $(this).attr('id').replace( 'options-', '' ), 10 );
- }
- var nonce = $(this).attr('href').replace( '#nonce=', '' );
- var connection = $(this).data( 'connection' );
- showOptionsPage.call( this, service, nonce, connection, blogId );
- });
- /**
- * Kicks off tests for all connections
- */
- publicizeConnTestStart = function() {
- $( '.pub-connection-test' )
- .addClass( 'test-in-progress' );
- $.post( ajaxurl, { action: 'test_publicize_conns' }, publicizeConnTestComplete );
- };
- publicizeConnRefreshClick = function( event ) {
- event.preventDefault();
- var popupURL = event.currentTarget.href;
- var popupTitle = event.currentTarget.title;
- // open a popup window
- // when it is closed, kick off the tests again
- var popupWin = window.open( popupURL, popupTitle, '' );
- var popupWinTimer= window.setInterval( function() {
- if ( popupWin.closed !== false ) {
- window.clearInterval( popupWinTimer );
- publicizeConnTestStart();
- }
- }, 500 );
- };
- publicizeConnTestComplete = function( response ) {
- $( '.pub-connection-test' ).removeClass( 'test-in-progress' );
- $.each( response.data, function( index, testResult ) {
- // find the li for this connection
- var testSelector = '#pub-connection-test-' + testResult.connectionID;
- if ( testResult.connectionTestPassed ) {
- $( testSelector )
- .addClass( 'test-passed' )
- .html( '' )
- .removeClass( 'test-failed' );
- } else {
- $( testSelector )
- .addClass( 'test-failed' )
- .html( '<p><span class="pub-connection-error">' + testResult.connectionTestMessage + '</span></p>' )
- .removeClass( 'test-passed' );
- if ( testResult.userCanRefresh ) {
- $( testSelector )
- .append( '<br/>' );
- $( '<a/>', {
- 'class' : 'pub-refresh-button button',
- 'title' : testResult.refreshText,
- 'href' : testResult.refreshURL,
- 'text' : testResult.refreshText,
- 'target' : '_refresh_' + testResult.serviceName
- } )
- .appendTo( testSelector )
- .click( publicizeConnRefreshClick );
- }
- }
- } );
- };
- $( document ).ready( function() {
- // If we have at least one .pub-connection-test div present, kick off the connection test
- if ( $( '.pub-connection-test' ).length ) {
- publicizeConnTestStart();
- }
- } );
- } );
|