Archive for the ‘JavaScript’ Category


Deprecated
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.

The Window.showModalDialog() creates and displays a modal dialog box containing a specified HTML document.

This feature is going away. Please fix your Web sites and applications.

Support has been removed in Chrome 37. But they have  added a temporary Enterprise Policy setting to re-enable showModalDialog. In May 2015 this setting will be removed andshowModalDialog() will be completely removed from Chrome.

Mozilla has announced that it will remove support for this method (bug 981796). Regarding timing, it shouldn’t be before Firefox 39. This means that the function will be around until around mid-June 2015. It also means that for enterprise you can switch to using ESR 38 builds, which will have the function into mid 2016.

Solution:

  // fix for deprecated method
    if (!window.showModalDialog) {
        window.showModalDialog = function(arg1, arg2, arg3) {

            var w;
            var h;
            var resizable = "no";
            var scroll = "no";
            var status = "no";

            // get the modal specs
            var mdattrs = arg3.split(";");
            for (i = 0; i < mdattrs.length; i++) {
                var mdattr = mdattrs[i].split(":");

                var n = mdattr[0];
                var v = mdattr[1];
                if (n) { n = n.trim().toLowerCase(); }
                if (v) { v = v.trim().toLowerCase(); }

                if (n == "dialogheight") {
                    h = v.replace("px", "");
                } else if (n == "dialogwidth") {
                    w = v.replace("px", "");
                } else if (n == "resizable") {
                    resizable = v;
                } else if (n == "scroll") {
                    scroll = v;
                } else if (n == "status") {
                    status = v;
                }
            }

            var left = window.screenX + (window.outerWidth / 2) - (w / 2);
            var top = window.screenY + (window.outerHeight / 2) - (h / 2);
            var targetWin = window.open(arg1, arg1, 'toolbar=no, location=no, directories=no, status=' + status + ', menubar=no, scrollbars=' + scroll + ', resizable=' + resizable + ', copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
            targetWin.focus();
        };
    }

 

 

Advertisements

You could use jQuery to dynamically update the mapping

function drawMap() {
 // remove image overlays used during transition
 $('.nivo-slice, .nivo-box').remove();
 var current_title = $('.nivoSlider').data('nivo:vars').currentImage.attr('title'); 
// set usemap attribute for current image
 $('.nivo-main-image').attr("useMap", current_title + "_map"); }

 

Then just call that function after load and after each transition

$('.nivoSlider').nivoSlider({
 // slider config
 afterLoad: drawMap,
 afterChange: drawMap
));

Key Code
backspace 8
tab 9
enter 13
shift 16
ctrl 17
alt 18
pause/break 19
caps lock 20
escape 27
page up 33
page down 34
end 35
home 36
left arrow 37
up arrow 38
right arrow 39
down arrow 40
insert 45
delete 46
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
a 65
b 66
c 67
d 68
 
Key Code
e 69
f 70
g 71
h 72
i 73
j 74
k 75
l 76
m 77
n 78
o 79
p 80
q 81
r 82
s 83
t 84
u 85
v 86
w 87
x 88
y 89
z 90
left window key 91
right window key 92
select key 93
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
 
Key Code
numpad 8 104
numpad 9 105
multiply 106
add 107
subtract 109
decimal point 110
divide 111
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123
num lock 144
scroll lock 145
semi-colon 186
equal sign 187
comma 188
dash 189
period 190
forward slash 191
grave accent 192
open bracket 219
back slash 220
close braket 221
single quote 222

 

ResolveUrl in Javascript

Posted: May 31, 2011 in JavaScript

Here is something that is super easy, yet I get asked about it quite often. Here’s how you do it: In the master page for the site, put this:

<script type="text/javascript">
        var baseUrl = "<%= ResolveUrl("~/") %>";
</script>

Then, in your javascript file, put this function:

function ResolveUrl(url) {
    if (url.indexOf("~/") == 0) {
        url = baseUrl + url.substring(2);
    }
    return url;
}

 

You could have put the function right in the master page, but then you wouldn’t get intelli-sense on it for the rest of your code. Now you can call ResolveUrl with ~/ right from javascript. Super easy, but also super useful! If you use themes, you might even want to write something that does a “get themed url” where the current theme is output from the master page via Page.Theme.