New plugin help

Posted on 2014-07-28
Last Modified: 2014-08-27
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

Open in new window

Which after I import my ''messy working" code will display (for example) in my own dialogue box (dont like the JQuery UI one), so Ive written the following:-
    $.tcDialogue = function(el, openURL($strURL), showHTML($strHTML), closeDialoge, options){
        var base = this;
        base.$el = $(el);
        base.el = el;
        base.$"tcDialogue", base);
        base.init = function(){
            base.openURL($strURL) = function ($strURL) {
            base.showHTML($strHTML) = showHTML($strHTML);
            base.closeDialoge = closeDialoge;
            base.options = $.extend({},$.tcDialogue.defaultOptions, options);
    $.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));

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 in the hope an expert can show me my mistake.

Thank you
Question by:tonelm54
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 23

Accepted Solution

Ioannis Paraskevopoulos earned 500 total points
ID: 40226080
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) {

Open in new window

The left hand should not have parameters:
base.openURL= function ($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 () {

Open in new window

Or if you intend to pass an actual parameter then do it like this:
base.openURL= function (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.


Author Closing Comment

ID: 40287313
Thank you, Im still learning (early stages) so thank you for your help, Ill try and remember for future :-)

Featured Post

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Google Tag Manager - Add Trigger Using Div class 22 94
JQuery conflicts/syntax issue 4 30
Scroll 5 news at a time using vticker 2 34
bootstrap form validations! 1 35
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question