New plugin help

Im trying to create my first plugin (to take a very messy code and hopefully tidy it up), however Im getting very stuck with the documentation.

What Im trying to do is create a plugin by:-
    var $newDialogue = $.tcDialogue({
        modal: true,
        draggable: true
    });
    $newDialogue.openURL("www.google.co.uk");

Open in new window


Which after I import my ''messy working" code will display www.google.co.uk (for example) in my own dialogue box (dont like the JQuery UI one), so Ive written the following:-
(function($){
    $.tcDialogue = function(el, openURL($strURL), showHTML($strHTML), closeDialoge, options){
        var base = this;
        
        base.$el = $(el);
        base.el = el;
        
        base.$el.data("tcDialogue", base);
        
        base.init = function(){
            base.openURL($strURL) = function ($strURL) {
                alert($strURL);
            };
            base.showHTML($strHTML) = showHTML($strHTML);
            base.closeDialoge = closeDialoge;
            
            base.options = $.extend({},$.tcDialogue.defaultOptions, options);
            
        };
        base.init();
    };
    
    $.tcDialogue.defaultOptions = {
        modal: true,
        draggable: true
    };
    
    $.fn.tcDialogue = function(openURL($strURL), showHTML($strHTML), closeDialoge, options){
        return this.each(function(){
            (new $.tcDialogue(this, openURL($strURL), showHTML($strHTML), closeDialoge, options));
        });
    };
    
})(jQuery);

Open in new window


But cant seem to get it to display the alert in, Ive spent a few hours on this and cannot see my mistake, Im now loosing my temper with it, and looking at just using my 'messy' code just to continue with the project, but hopefully an expert can spot my mistake and point me in the right direction. Ive uploaded the code to http://jsfiddle.net/YXsbZ/ in the hope an expert can show me my mistake.

Thank you
tonelm54Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ioannis ParaskevopoulosCommented:
I have seen several issues with your code. I will try to list them here:

1. Wrong format of function params

Check the following line which initializes a function:
$.tcDialogue = function(el, openURL($strURL), showHTML($strHTML), closeDialoge, options)

Open in new window

It seems as you are passing a function call as a parameter. Pass the parameters themselves instead:
$.tcDialogue = function(el, $strURL, $strHTML, closeDialoge, options)

Open in new window

The same applies to the following:
$.fn.tcDialogue = function(openURL($strURL), showHTML($strHTML), closeDialoge, options)

Open in new window

Should be:
$.fn.tcDialogue = function($strURL, $strHTML, closeDialoge, options)

Open in new window


2. Wrong function calls

You are trying to call a function passing results of void functions as params:
$.tcDialogue(this, openURL($strURL), showHTML($strHTML), closeDialoge, options)

Open in new window

Try the following:
$.tcDialogue(this, $strURL, $strHTML, closeDialoge, options)

Open in new window


3. Wrong methods declaration

You are trying to declare object methods like:
           
base.openURL($strURL) = function ($strURL) {
    alert($strURL);
};

Open in new window

The left hand should not have parameters:
           
base.openURL= function ($strURL) {
    alert($strURL);
};

Open in new window

Also, the argument passed in the function will mask the property of the object with the same name. So if you intend to just open the url described in the object property then just use:
           
base.openURL= function () {
    alert($strURL);
};

Open in new window

Or if you intend to pass an actual parameter then do it like this:
           
base.openURL= function (url) {
    alert(url);
};

Open in new window


Check out this fork of your fiddle

I have commended out the code:
//base.showHTML = showHTML(strHTML);

Open in new window

I did not know what you wanted there.

Giannis
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tonelm54Author Commented:
Thank you, Im still learning (early stages) so thank you for your help, Ill try and remember for future :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.