jquery fancybox, get a variable out of the initial function -


this out there have taken apart fancybox little bit, or can understand jquery stuff behind better me (shouldn't hard) :)

coming situation described in this article, have added new value fancybox main function retrieves link being clicked on.

; (function($) { var tmp, loading, overlay, wrap, outer, content, close, title, perma, nav_left, nav_right, 

perma being variable; used in _start function retrieve value <a>:

perma = selectedopts.perma || (obj.nodename ? $(obj).attr('perma') : obj.perma) || ''; 

if @ point quick alert(perma) confirmation variable being retrieved expected.

now, has happened inside function _start, inside main function $; but, need use variable outside of such functions, down in script within $.fancybox.init, use such:

$('#permabox').bind("click", function(){         window.location.replace(perma);     }); 

however here perma value returns undefined.

how value have in other function use one???

once again figured out answer own question:

1) variable must declared @ beginning of _finish function:

_finish = function () {         var perma; (...) 

2) strangely enough, var perma should not recalled within function returns it:

_givemeperma = function () {             /*var perma;    breaks it*/             return perma;         }; 

the above used in _finish, after having appended div fancybox outer, this:

$('#permabox').bind("click", function(){         var permalink = _givemeperma();         window.location.assign(permalink);     });//permabox 

this opens permalink retrieved function _givemeperma, retrieves variables contained in link , collected fancybox.

that's :)


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -