nageeb2016 / swfobject

Automatically exported from code.google.com/p/swfobject
0 stars 0 forks source link

Add version string #582

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice to have a version string available so third party code can 
make decisions based on it, like giving a user feedback or dynamically 
including the library if the required version isn't loaded to name a few.

swfobject.version; //--> '2.2.1'

Original issue reported on code.google.com by nickstak...@gmail.com on 27 Jul 2011 at 6:47

GoogleCodeExporter commented 9 years ago
Noted, and changed this to an enhancement request rather than a bug.

Original comment by aran.rhee@gmail.com on 28 Jul 2011 at 4:15

GoogleCodeExporter commented 9 years ago
This request seems logical, but upon reflection would cause many problems. If 
we were to add a version string to SWFObject 2.3, querying for a version string 
in older versions of SWFObject would throw an error since they don't have a 
version string to report. I suggest sticking to feature detection.

SWFObject 2.1 added swfobject.removeSWF
SWFObject 2.2 added swfobject.ua

var is20 = (typeof swfobject.removeSWF === "undefined");
var is21 = (typeof swfobject.removeSWF !== "undefined" && typeof swfobject.ua 
=== "undefined");
var is22 = (typeof swfobject.removeSWF !== "undefined" && typeof swfobject.ua 
!== "undefined");

Original comment by platelu...@gmail.com on 30 Jul 2011 at 5:10

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
There are a gazillion ways to put this in function form, but here's a quickie 
for you.

-----

function getSWFObjectVersion(){

   //Require swfobject before continuing
   if(!swfobject){ return false; }

   var hasRemoveSWF = (typeof swfobject.removeSWF !== "undefined"),
       hasUA = (typeof swfobject.ua !== "undefined");

   if(!hasRemoveSWF){ return "2.0" }
   if(hasRemoveSWF && !hasUA){ return "2.1"; }
   if(hasRemoveSWF && hasUA){ return "2.2"; }

   //If version unknown, return empty string
   return "";

}

Original comment by platelu...@gmail.com on 30 Jul 2011 at 5:25

GoogleCodeExporter commented 9 years ago
Have to disagree with you there, you are basically saying a version string can 
never be introducing, you could simply do (swfobject.version && restofcheck).

The examples you give are also not feature checks, just properties that are 
currently available but could be deprecated or changed in the future. A version 
sting is more reliable, writing a backwards compatible check is no problem and 
much easier then the suggested code.

Original comment by nickstak...@gmail.com on 30 Jul 2011 at 5:56

GoogleCodeExporter commented 9 years ago
A version string also allows for checks that don't rely on newly introduced 
methods, bugfix releases for example. The only way to require those without a 
version string would be throwing feature tests at it that check for bugs in 
swfobject. Nobody will want to do that.

With a version string simple checks could take care of everything:

var hasRequiredVersion = (function() {
  var VERSION_STRING = /^(\d+(\.?\d+){0,3})([_-]+[A-Za-z0-9]+)?/;

  function convertVersionString(versionString) {
    var vA = versionString.match(VERSION_STRING),
        nA = vA && vA[1] && vA[1].split('.') || [],
        v  = 0;

    for (var i = 0,l = nA.length;i<l;i++)
      v += parseInt(nA[i] * Math.pow(10,6-i*2));
    return vA && vA[3] ? v - 1 : v;
  }

    return function (available, required) {
      return !!(available && convertVersionString(available) >= convertVersionString(required));
    }
})();

hasRequiredVersion(swfobject && swfobject.version, '2.3'); //--> false

// let's say you have a version string on 2.3
hasRequiredVersion(swfobject && swfobject.version, '2.3'); //--> true

// or some alpha/beta
hasRequiredVersion('2.3.10.1_alpha', '2.3.10.1'); //--> false

Original comment by nickstak...@gmail.com on 30 Jul 2011 at 6:23

GoogleCodeExporter commented 9 years ago
The code you just supplied is much more complex (and longer) than the example I 
provided. Not sure how it's an improvement.

How often will a developer have to use JavaScript to detect what version of 
SWFObject is being used?  Not very. It's an edge case. Most developers include 
the SWFObject file themselves and know exactly what version it is.  If 
anything, the biggest issue we see in the forums is people using the SWFObject 
1.x JS file with SWFObject 2.x syntax.

If you're receiving your SWFObject file via a CDN like Google API library, 
you'll know exactly what version you're getting because you have to specify it.

In any event, I understand what you're asking for (I've considered the concept 
for a few years), and having a version string makes sense in some situations. 
However, it is not on the roadmap for version 2.3. We'll keep it in mind for 
future releases.

Original comment by platelu...@gmail.com on 30 Jul 2011 at 5:47

GoogleCodeExporter commented 9 years ago
It's an improvement in the sense that it can check for any version, the check 
could be as simple as this:

(swfobject && swfobject.version >= '2.3');

How complex to go with it should be up to the implementer, all we realy need is 
something to work with. Adding the string is in no way harmful, just document 
that it's implemented since 2.x and people wanting to use it will know what to 
do.

Original comment by nickstak...@gmail.com on 30 Jul 2011 at 6:08

GoogleCodeExporter commented 9 years ago
Issue 604 has been merged into this issue.

Original comment by platelu...@gmail.com on 6 Jan 2012 at 9:29