EzDevInfo.com

shim

Shim is a node.js-based browser-compatibility tool that lets you synchronize several devices/browsers and surf the same pages simultaneously on all of them.

What is the difference between a shim and a polyfill? [closed]

Both seem to be used in web development circles, see e.g. HTML5 Cross Browser Polyfills, which says:

So here we're collecting all the shims, fallbacks, and polyfills...

Or, there's the es5-shim project.

In my current project we're using a number of these, and I want to stick them all in the same directory. So, what should I call this directory---shims, or polyfills?


Source: (StackOverflow)

What is a Shim?

What's the definition of a Shim?


Source: (StackOverflow)

Advertisements

Shim a jQuery plugin with browserify

Hi I'm using the grunt browserify task to setup my code, I have shimmed in jQuery and I'm now trying to include jquery.tablesorter.

Can jquery plugins be used with browserify in this way?

shim: {
    jquery: {
        path: 'lib/bower/jquery/jquery.js',
        exports: '$'
    },
    'jquery.tablesorter': {
        path: 'lib/bower/jquery.tablesorter/js/jquery.tablesorter.js',
        exports: 'tablesorter',
        depends: {
            jquery: '$',
        }
    }
}

Source: (StackOverflow)

Shims or Facade/Adapter pattern

I'm developing an application that need to work with different incompatible versions of some library. My gut instinct was introducing an adapter between the app and the library that will have proper object of the library injected in it. Then, someone told me about shims. Not much literature is available about it.

I wanted to know how are shims different from facade and adapter design pattern? And what are some of the popular uses of the same?


Source: (StackOverflow)

What is the meaning of polyfills in HTML5?

What is the meaning of polyfills in HTML5? I saw this word in many sites about HTML5, like here: https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills

So here we're collecting all the shims, fallbacks, and polyfills in order to implant HTML5 functionality in browsers that don't natively support them.

I actually don't understood what is the meaning of polyfills.

Is it a new HTML5 technique or a JavaScript library? I never heard this word before HTML5.

And what is the difference between shims, fallbacks, and polyfills?


Source: (StackOverflow)

Loading jQuery, Underscore and Backbone using RequireJS 2.0.1 and shim

I am experimenting a little bit with RequireJS 2.0.1. My goal is to load correctly jQuery, Underscore and Backbone. From the original RequireJS doc I discovered that the author J. Burke added (to this new release) a new config option called shim.

Then I wrote this stuff down here:

index.html

<!DOCTYPE html>
<html>
    <head>
        <title>Testing time</title>
        <script data-main="scripts/main" src="scripts/require.js"></script>
    </head>
    <body>
        <h1>Testing time</h1>
    </body>
</html>

scripts/main.js

requirejs.config({
    shim: {
        'libs/jquery': {
            exports: '$'
        },
        'libs/underscore': {
            exports: '_'
        },
        'libs/backbone': {
            deps: ['libs/underscore', 'libs/jquery'],
            exports: 'Backbone'
        }
    }
});


define(
    ['libs/jquery', 'libs/underscore', 'libs/backbone'],

    function (jQueryLocal, underscoreLocal, backboneLocal) {
        console.log('local', jQueryLocal);
        console.log('local', underscoreLocal);
        console.log('local', backboneLocal);
        console.log('global', $);
        console.log('global', _);
        console.log('global', Backbone);
    }
);

Everything seems to work quite fine, but I have the feeling that I'm missing something, I know that there are AMDed version of jQuery and Underscore but if the setup is so simple I don't understand why I should use them.

So, is this setup right or I'm missing something?


Source: (StackOverflow)

iframe shimming or ie6 (and below) select z-index bug

uhm im not sure if anyone has encountered this problem
a brief description is on IE6 any <select> objects get displayed over any other item, even div's... meaning if you have a fancy javascript effect that displays a div that's supposed to be on top of everything (e.g: lightbox, multibox etc..) onclick of a certain element and that div overlaps a <select> your div get's to be displayed as if its under the <select> [on this case a max and minimum z-index doesnt work ]

i've tried googling and found the iframe shim solution
but i wanted some pretty clean alternatives or better yet has anyone found a better solution? since the method using iframes uses around 130mb of ram might slow down poor people's machines


Source: (StackOverflow)

vs 2012: Shims compile

I am trying to make a shim in VS 2012 ultimate as it described in MSDN site:

[TestClass]
public class TestClass1
{ 
    [TestMethod]
    public void TestCurrentYear()
    {
        int fixedYear = 2000;

        using (ShimsContext.Create())
        {
          // Arrange:
          // Detour DateTime.Now to return a fixed date:
          System.Fakes.ShimDateTime.NowGet = 
              () =>
              { return new DateTime(fixedYear, 1, 1); };

          // Instantiate the component under test:
          var componentUnderTest = new MyComponent();

          // Act:
          int year = componentUnderTest.GetTheCurrentYear();

          // Assert: 
          // This will always be true if the component is working:
          Assert.AreEqual(fixedYear, year);
        }
    }
}

see http://msdn.microsoft.com/en-us/library/hh549176.aspx

But when I compile my test project I get a notion in Output:

warning : Some fakes could not be generated. For complete details, set Diagnostic attribute of the Fakes element in this file to 'true' and rebuild the project.

How can I resolve this warning?


Source: (StackOverflow)

Windows: How to create custom appcompat shims (Application Fixes)?

Windows has the capability to apply shims to mis-behaving applications. Shims are used to intercept API calls and change it. For example, shims can be used to:

  • change the incoming paramters
  • lie about the return values
  • change it to call something else

The Application Compatibility Tookit has quite a few existing shims you can apply to your own mis-behaving application. Here's an example of one that ignores your API call and instead calls a completely different API instead:

alt text

i need a shim that isn't one of the hundreds of shims Microsoft already wrote. i need a custom shim.

In my case i want to intercept calls to:

GetSystemMetrics(0x1000)

so that it returns 0. i can't find any information on how to give Windows my own DLL that will have the fix i need. i don't even know if you can create custom shims.

Does Windows support custom shims?


Source: (StackOverflow)

Using ES5 shim with jquery/mootools/prototype

I stumbled across this project: https://github.com/termi/ES5-DOM-SHIM which provides almost full ES5 support in all browsers including old IEs.

I've been using it in pure JS projects, but now I have to include jquery/mootools/prototype in a project (that uses High Charts).

Even just including the jquery script causes errors to be thrown in IE8 along with this shim. How can I keep the best of both worlds?

My document head looks like this:

<!--[if lte IE 8]>
<script src="/js/a.ie8.js"></script>
<![endif]-->
<script src="/js/a.js"></script>
<script src="/js/jquery.1.8.2.js"></script>
<script src="/js/main.js"></script>

Source: (StackOverflow)

usable D3 replacement in IE8 (graphs with D3 and svg)

I have developed working D3 driven charts and as far as all the other browsers go, there are no problems.

but recently the need to support them also in Internet Explorer 8 cropped up.

But so far i can't make this html display in IE8.

these are the tags used in D3:

<svg> <path> <g> <line> <circle> <rect>

for the last 6 hours i have skimmed through a lot of materials and questions including:

"Display inline SVG in IE8" which has this answer from October 2012:

I have been looking into this too and a number of options came up.

  • Chrome Frame - A browser plug-in that actually uses chrome underneath, meaning SVG just works. This is great if you're able to deploy plugins to the browser, for a real commercial environment however this may not be possible.

  • SVG Web - The aim is it bring SVG to all browsers. It looks like a fairly large project, one that's had Google's input. This doesn't however work out of the box with D3 though I don't know much about the issues.

  • D34Raphael - You've mentioned this one, I found again it doesn't work out of the box. Check the project out on GitHub, there hasn't been any commit activity in months and there's some pull requests "first pass on trying to get support for .on() required for event binding". If it doesn't support events, is that an issue to you? I'd generally keep away from this one.

  • R2D3 - Again another one you mentioned. I took the Sankey example from the D3 website and had to make a few changes to get it working. The main things I couldn't get working (Drag Events, Groups - though can use an alternative). It took about a day of effort to get the example working in IE8 and I believe is in a useable state. The project on GitHub is also much more active, the developer is committing, pulling work in and is very active on discussions etc. This gets my vote.

Also:

D3 IE8 Compatibility?

wikipedia.org/wiki/Scalable_Vector_Graphics

SVG Web Compatibility

But the solutions using client-side plugins are not acceptable and so far it looks that i can't display svg in IE8. So the solution is to find some other ways to render vector graphs. I presume that others have had the same problems


Edit:

either way, people that will encounter this same problem after me will at least have somewhat concentrated materials and will realize that there is no easy/real solution to display svg on IE8 and better to spend time starting on the existing code rewriting/adjusting for non-svg version

Edit:

after some testing i would say that its worth trying to go through R2D3 examples and see if its possible to simplify/execute the code in IE8

Samples

Edit:

During the process of testing different elements separately some r2d3 problems seem to arise

most common would be Invalid argument and Object doesn't support this property or method

as i am not used to develop for IE8 there were some useful tips that i found:

dump javascript vars and display objects


Source: (StackOverflow)

Is there a way to hook or intercept CoGetClassObject and/or CoCreateInstance calls?

I'd like to intercept the COM CoCreateInstanceEx and/or CoGetClassObject functions to replace a class with a testing shim in a unit test. This will only be for a single CLSID; all others can go through unchanged. Is there a way to do this without horrible, evil hacks?


Source: (StackOverflow)

HTML5 shim fallback? [duplicate]

Possible Duplicate:
HTML5 in IE6 when JavaScript is disabled

I've heard a lot of talk about using HTML5 now and just relying on a javascript shim as a fallback for < IE8. But what happens if the user has javascript disabled? It's a tricky situation. Could there be a fallback for the html5 shim fallback? What's your opinion on the matter?


Source: (StackOverflow)

ShimNotSupportedException in MS VisualStudio 2012

I'm just trying to get familiar with the new Fakes Isolation Framework in Visual Studio 2012 RC but I'm consequently facing issues with ShimNotSupportedExceptions.
At the first tries, each single shim method I tried to hook up a delegate to, had thrown a ShimNotSupportedException when trying to run/debug the test.

[TestMethod]
public void GetFoo_ValidBar_ReturnsBaz()
{
    using(ShimsContext.Create())
    {
        ShimDateTime.NowGet = () => new DateTime(2012,08,11,10,20,59);

        const string expected = "20120811_102059";
        string actual = GetFoo();

        Assert.AreEqual(expected,actual);
    }
} 

This is the corresponding stack trace:

The GetFoo_ValidBar_ReturnsBaz test method has thrown an exception: Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotSupportedException: System.DateTime at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InvokeEvent(T value, Action1 eh) at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.OnAttachedUnsupportedMethod(MethodBase method) at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.CheckInstrumentation(MethodBase method) at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InternalAttachDetour(Object optionalReceiver, MethodBase method, Delegate detourDelegate) at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.AttachDetour(Object optionalReceiver, MethodBase method, Delegate detourDelegate) at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShimMethod(Delegate optionalStub, Object optionalReceiver, MethodBase method) at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShim(Delegate optionalStub, Type receiverType, Object optionalReceiver, String name, ShimBinding flags, Type returnType, Type[] parameterTypes) at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShimPublicStatic(Delegate optionalStub, Type receiverType, String name, Type returnType, Type[] parameterTypes) at System.Fakes.ShimDateTime.set_NowGet(Func'1 value) at GetFoo_ValidBar_ReturnsBaz() in BazTests.cs: line 48.

After having read the two threads I had found at MSDN dealing with this issue I followed their instructions (turning CodeCoverage off, deleting .testsettings file) which didn't work for me!
Nevertheless I have found a workaround for this issue:
By firstly running all tests from the Test Explorer (instead of using the "MSTest Test (click to run)" button directly out of the coding area) everything worked correctly and no exceptions were thrown. Afterwards I could even debug the test and the assignment to the shim method worked just as expected.
This worked for all following shims I used as well.
But now I'm having the same issue again when trying to implement fakes of the MS Enterprise Library for database access.

This is what the test looks like:

[TestMethod]
public void GetFooFromEF_NonEmptyDataReader_ObjectsCorrectlyInstantiated()
{
    using(ShimsContext.Create()){
        var dataReader = new StubIDataReader()
            {
                ItemGetString = s => 1,
                DepthGet = () => 2
            };

        ShimFoo.GetBar = guid => dataReader;

        var bar = new StubIBar()
        {
            ConvertIBarToBaz = record => null
        };

        ShimQux.AllInstances.GetBar = (a, b) => bar;

        var dbFactory = new StubDbProviderFactory();
        var db = new StubDatabase("test", dbFactory);
        ShimDatabaseFactory.CreateDatabaseString = s => db;

        List<BarInformation> actual = accessor.InvokeStatic("GetBar",
                                                                new Object[] { }) as List<BarInformation>;
        Assert.IsTrue(true);
    }
}

The first two shim assignments (ShimFoo & ShimQux) are working as expected. But ShimDatabaseFactory.CreateDatabaseString (which is supposed to make DatabaseFactory.CreateDatabase(string) return a stub database when trying to create a new database instance) throws a ShimNotSupportedException again. And I just can't figure out why!
Do you have any ideas what went wrong here?

I would appreciate any input on this.

Thanks,
Benjamin


Source: (StackOverflow)

Equivalent for `-moz-element` in other browsers?

I want to create an opacity blur overlay, similar to Windows Aero or iOS7. Unfortunately the filter: blur() or filter: url(#svgBlur) properties can only apply to the element, not content behind it.

To get round this we need a copy of the background that is blurred. This is possible in FX using the background: -moz-element(#elementId) experimental CSS property. Using that I can get the effect I want in FX only.

There are other questions about solving the blur problem, and one solution appears to be the use of the html2Canvas plug in.

However that is recreating the entire blurred content, including manually recreated styles and the like. It's very impressive work, but it seems like massive overkill (both in performance and size) for this kind of effect.

What I want to do is create is some kind of shim just for -moz-element. It looks like that should be possible using an SVG foreignObject, but that has both security issues and fails if your HTML is not valid XML.

Is there any way round of emulating -moz-element (using canvas, SVG, or something else) where I don't have to parse/redraw the entire overlaid area?


Source: (StackOverflow)