开发者

How to manually call functions that come with some libraries

I have installed a lightbox plugin and i would like to resue some if its functionality for other parts of my application without having to recode a separate module since it would be kind of redundant, so is it possible to reuse/share some functions from a library like say from this one

http://www.notesfor.net/samples/jquery/notesforlightbox/js/nf.lightbox.js

My intention is this light box plug in already supports hotkeys for Next, Previous, Close etc...

Here is the situation... form the lightbox.js... I want to reuse this particular function for another part of my application

(function($) {
$.fn.lightBox = function(settings) {

.... ...... ...... ..... etc ...

    function _keyboard_action(objEvent) {
        // To ie
        if (objEvent == null) {
            keycode = event.keyCode;
            escapeKey = 27;
            // To Mozilla
        } else {
            keycode = objEvent.keyCode;
            escapeKey = objEvent.DOM_VK_ESCAPE;
        }
        // Get the key in lower case form
        key = String.fromCharCode(keycode).toLowerCase();
        // Verify the keys to close the ligthBox
        if ((key == settings.keyToClose) || (key == 'x') || (keycode == escapeKey)) {
            _finish();
        }
        // Verify the key to show the previous image
        if ((key == settings.keyToPrev) || (keycode == 37)) {
            // If we´re not showing the first image, call the previous
            if (settings.activeImage != 0) {
                settings.activeImage = settings.activeImage - 1;
                _set_image_to_view();
                _disable_keyboard_navigation();
            }
        }
        // Verify the key to show the next image
        if ((key == settings.keyToNext) || (keycode == 39)) {
            // If we´re not showing the last image, call the next
            if (settings.activeImage != (settings.imageArray.length - 1)) {
                settings.activeImage = settings.activeImage + 1;
                _set_image_to_view();
                _disable_keyboard_navigation开发者_开发问答();
            }
        }
    }

.... ...... ...... ..... etc ...

};

})(jQuery);

but if i call : _keyboard_action(objEvent) from outside, i would get an error, so what is the correct syntax to do so?


From what I understood from this post (and If I'm not misunderstood), you can simply use

<script src="NameOfJavascriptFile.js" type="text/javascript">

in your html <head> section and then call the functions like normal functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜