Skip to content

Commit

Permalink
closure on js to prevvent conflict with other js functions of other p…
Browse files Browse the repository at this point in the history
…lugins
  • Loading branch information
lucymtc committed Sep 8, 2015
1 parent 58f14d1 commit e3458f9
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 66 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ Other plugins that you may have interest:
* Fixed issue with hover color effect on some themes
* Removed Specificfeeds.com default activation and admin notice.
* Save plugin version into database for track the current installed version.
* Changed icons defualt colors
* Fix js to prevent conflicts with other plugins

= 3.3.1 =
* CSS fix. Conflicting with some themes.
Expand Down
6 changes: 3 additions & 3 deletions assets/js/front-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
jQuery(document).ready(function($) {


var sfmsb_widget = new sfmsb();
var sfmsb_widget = new sfmsb_front();
sfmsb_widget.init_icons();

});
Expand All @@ -17,8 +17,8 @@ jQuery(document).ready(function($) {

// Closure

function sfmsb (){

function sfmsb_front (){
return {

/**
Expand Down
136 changes: 73 additions & 63 deletions assets/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,94 +5,104 @@
*/

jQuery(document).ajaxSuccess(function(e, xhr, settings) {

init();

var sfmsb_form = new sfmsb();
sfmsb_form.init();

});

jQuery(document).ready(function($) {

init();
var sfmsb_form = new sfmsb();
sfmsb_form.init();

});

// Closure



function init (){

jQuery( '.sfmsb-color-picker' ).wpColorPicker();
function sfmsb (){

//** Icon events
jQuery( '.sfmsb-icons-container a.sfmsb-disable, .sfmsb-icons-container a.sfmsb-enable' ).on( 'click', function( event, ui ){

jQuery('.sfmsb-icons-container').removeClass('extra-message');
jQuery('p#sfmsb-specififeeds-message').css('display', 'none');
function get_random_id(){

var tmp = jQuery( this ).find( 'span' ).attr( 'class' ).split( ' ' );
tmp = tmp[0].split( '-' );
var num = Math.floor((Math.random() * 999) + 1);
var id = 'sfmsb-' + num;

var icon_name = tmp[2];
return id;

// get the id of the widget on the widgets page
var widget = '#' + jQuery( this ).closest( '.widget' ).attr( 'id' );
}

/* if undefined probably not the widgets page, for example could com from a page builder
so set id to the icons container to work with that element*/
// public methods
return {

if( widget == '#undefined') {
/**
* init_icons
* inits hover color effect
*/

widget = '#' + jQuery( this ).closest( '.sfmsb-icons-container ' ).attr( 'id' );
init : function () {

if( widget == '#undefined') {
jQuery( '.sfmsb-color-picker' ).wpColorPicker();

//** Icon events
jQuery( '.sfmsb-icons-container a.sfmsb-disable, .sfmsb-icons-container a.sfmsb-enable' ).on( 'click', function( event, ui ){

widget = get_random_id();
jQuery( this ).closest( '.sfmsb-icons-container ' ).attr('id', widget);
jQuery('.sfmsb-icons-container').removeClass('extra-message');
jQuery('p#sfmsb-specififeeds-message').css('display', 'none');

var tmp = jQuery( this ).find( 'span' ).attr( 'class' ).split( ' ' );
tmp = tmp[0].split( '-' );

var icon_name = tmp[2];

// get the id of the widget on the widgets page
var widget = '#' + jQuery( this ).closest( '.widget' ).attr( 'id' );

// if undefined probably not the widgets page, for example could com from a page builder
// so set id to the icons container to work with that element

if( widget == '#undefined') {

widget = '#' + jQuery( this ).closest( '.sfmsb-icons-container ' ).attr( 'id' );

if( widget == '#undefined') {

widget = get_random_id();
jQuery( this ).closest( '.sfmsb-icons-container ' ).attr('id', widget);

widget = '#' + widget;
}

widget = '#' + widget;
}

}

jQuery( widget + ' .sfmsb-initial-message' ).css( 'display', 'none' );
jQuery( widget + ' .sfmsb-input-block' ).css( 'display', 'none' );
jQuery( widget + ' .sfmsb-input-block.sfmsb-' + icon_name ).css( 'display', 'block' );


jQuery( widget + ' .sfmsb-initial-message' ).css( 'display', 'none' );
jQuery( widget + ' .sfmsb-input-block' ).css( 'display', 'none' );
jQuery( widget + ' .sfmsb-input-block.sfmsb-' + icon_name ).css( 'display', 'block' );
});

});

//** Input events
jQuery( '.sfmsb-icons-container input[type=text]' ).keyup( function() {

var tmp = jQuery( this ).attr( 'id' ).split( '-' );
tmp = tmp[3].split( '_' );

var icon_name = tmp[1];
var widget = '#' + jQuery( this ).closest( '.widget' ).attr( 'id' );
var aTag = jQuery( widget + ' .sfmsb-icon-' + icon_name ).closest( 'a' );

if( jQuery(this).val() == '' ){

aTag.attr( 'class', 'sfmsb-disable' );

}else{

aTag.attr( 'class', 'sfmsb-pending' );
}
});

}
//** Input events
jQuery( '.sfmsb-icons-container input[type=text]' ).keyup( function() {

var tmp = jQuery( this ).attr( 'id' ).split( '-' );
tmp = tmp[3].split( '_' );

var icon_name = tmp[1];
var widget = '#' + jQuery( this ).closest( '.widget' ).attr( 'id' );
var aTag = jQuery( widget + ' .sfmsb-icon-' + icon_name ).closest( 'a' );

if( jQuery(this).val() == '' ){

/**
* get_random_id
* @since 2.6
*/
aTag.attr( 'class', 'sfmsb-disable' );

function get_random_id(){
}else{

var num = Math.floor((Math.random() * 999) + 1);
var id = 'sfmsb-' + num;
aTag.attr( 'class', 'sfmsb-pending' );
}
});

return id;
}

}
} //

}

0 comments on commit e3458f9

Please sign in to comment.