My Favorites Plugin not Compatible with IE ?

9 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: June 18, 2014   (RSS)

By Tom - May 14, 2014

Hello,

I've just installed the Website Favorites plugin.

and made some test with IE, Chrome, Safari and Firfox.

However, in IE8,9,10,and 11

If you click the remove Favorite link and click the Add Favorite link again,

There is no response at all.

It happens only in the IE even press ctrl+F5 or log off and login again

For example.

Click the Add Favorite link in listing 1 ---- No problem

Then click the Remove Favorite link in listing 1 ---No problem

But click the Add Favorite link in listing 1 again --- No response at all 

Is it possible to fix it?

Thanks

By gregThomas - May 16, 2014

Hi Tom,

Thanks for bringing this to our attention. I was able to replicate the issue on our test server, and we've come up with a solution that will be implemented into the next release. 

The problem is caused by IE's overzealous content caching. The first time you press the button it carries out the AJAX request, the second time you press the button it doesn't carry out the request because it's cached the content from the previous request, and so doesn't contact the server. 

The easiest solution to stop IE doing this is modify the websiteFavourites.js file, which you can find in the cmsAdmin/plugins/websiteFavourites directory. Then make the following changes highlighted in green:

//
function wsf_add(tableOrTag, recordNum, reload) {
  var $           = jQuery; // see: http://docs.jquery.com/Core/jQuery.noConflict
  var addClass    = _wsf_getClassFor(tableOrTag, recordNum, 'add');
  var removeClass = _wsf_getClassFor(tableOrTag, recordNum, 'remove');

  $.ajax({
    cache: false,
    url: '?_wsf_action=add&tableOrTag=' +escape(tableOrTag)+ '&recordNum=' + escape(recordNum),
    success: function(errorMessage){
      if (errorMessage)   { return alert("Error: " + errorMessage); }
      if (reload == true) { return window.location.reload(); }

      $(addClass).hide();
      $(removeClass).show();
      return true;
    }
  });

}

//
function wsf_remove(tableOrTag, recordNum, reload) {
  var $           = jQuery; // see: http://docs.jquery.com/Core/jQuery.noConflict
  var addClass    = _wsf_getClassFor(tableOrTag, recordNum, 'add');
  var removeClass = _wsf_getClassFor(tableOrTag, recordNum, 'remove');

  //
  $.ajax({
    cache: false,
    url: '?_wsf_action=remove&tableOrTag=' +escape(tableOrTag)+ '&recordNum=' + escape(recordNum),
    success: function(errorMessage){
      if (errorMessage)   { return alert("Error: " + errorMessage); }
      if (reload == true) { return window.location.reload(); }

      $(addClass).show();
      $(removeClass).hide();
      return true;
    }
  });
}

// var className = _wsf_getClassFor(tableOrTag, recordNum, action);
function _wsf_getClassFor(tableOrTag, recordNum, action) {
  var className = ".wsf_" + action + '_' + tableOrTag + '_' + recordNum;
  return className;

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Tom - May 17, 2014

That's perfect.

Thanks a lot Greg.

However, one more problem.

I intend to list the newly added favorite to be list first in the my favorite listing viewer.

I have add a new column in the favorite table named num with auto increment and added orderBy num DESC.

But Seems not work

Any idea?

// load matching records
list($favoriteRecords, $favoriteMetaData) = getRecords(array(
'tableName' => 'listings', // update this with your table or tag name
'perPage' => '10',
'where' => " num IN ($favoriteNumsQuery) ",
'loadCreatedBy' => false,
'allowSearch' => false,
'orderBy' => "num DESC",
));

Please advice.

Thanks a lot

By Tom - May 20, 2014

Hi Greg,

I think it's almost done.

I can see there is a new column in the table cms_website_favorites named 'createdDate'

And if I click the Add Favorite link,

the date and time of the click would be logged.

However, it seems still not work in the my_favorites.php

// load matching records
list($favoriteRecords, $favoriteMetaData) = getRecords(array(
'tableName' => 'listings', // update this with your table or tag name
'perPage' => '10',
'where' => " num IN ($favoriteNumsQuery) ",
'loadCreatedBy' => false,
'allowSearch' => false,
'orderBy' => "`createdDate` DESC",
));

The sort order sort the createdDate column in the listing table, not the website_favorites table

The listing order in the my_favorites.php now becomes the sort order of createdDate in the cms_listings table

I did try to change this line

'tableName' => 'website_favorites', // update this with your table or tag name

but got error.

Please advice how to amend the code to sort order in cms_website_favorites table, not the cms_listings table.

Actually I know it is simple but I am a php idolt and sorry for trouble again.

Thanks a lot

By Tom - June 3, 2014

Any News?

Thanks

By claire - June 13, 2014

Hi Tim

I'm following up with Greg about this, I'll get back to you soon.

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By gregThomas - June 13, 2014

Hi Tom, 

Sorry, the code I gave you would have listed the items by the createdDate of the listings as opposed to the creation date of the website favorites. Here is some alternative code that will return the users items based on the favorites creation date:

<?php
    require_once "cmsAdmin/lib/viewer_functions.php";

    // get favorite record nums
    $tableOrTag        = mysql_escape('listings');  // update this with your table or tag name
    $currentUserNum    = mysql_escape( @$CURRENT_USER['num'] );

    // load matching records
    list($favoriteRecords, $favoriteMetaData) = getRecords(array(
      'tableName'     => '_website_favorites', // update this with your table or tag name
      'perPage'       => '10',
      'where'         => "`tableOrTag` = '$tableOrTag' AND _website_favorites.`createdByUserNum` = '$currentUserNum' ",
      'loadCreatedBy' => false,
      'leftJoin'      => array('blog' => 'recordNum'),
      'allowSearch'   => false,
      'orderBy'       => '_website_favorites.`createdDate` DESC'
    ));

    showme($favoriteRecords);

So the above code uses a left join to link the contents of the website favorites to the contents of the listings table.

Then I've updated the where statement so that it will search the website favorites table. 

Finally I've updated the orderBy statement so it will order the results by the created date stored in the website favorites table.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gregThomas - June 18, 2014

Hi Tom,

We've just added the I.E. AJAX caching fix to the latest version of the website membership plugin.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com