Object doesn't support property or method 'widget'

Jan 4, 2012 at 6:26 AM

I created a simple example of widget in a MVC3 project for learning and got the error "Object doesn't support property or method 'widget'" unfortunately.

Following is my code, please help me.

(function ($) {
    var isVisible = false;
    $.widget('word.translate', {
        options: {
            DataUrl: null
        },

        _create: function () {
            var ele = this.element;
            ele.bind("mouseover", function () {
                isVisible = true;
                //_displayTranslateResult();
            }).bind("mouseout", function () {
                isVisible = false;
                //_hideTranslateResult();
            })
        }

//        _displayTranslateResult: function () {
//            alert("fang qi");
//        },

//        _hideTranslateResult: function () {
//            alert("hide");
//        }
    })
} (jQuery))

Page source code

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>
<div id="divContent">
    <span id="word">abandon</span>
</div>

@*<script src="@Url.Content("~/Scripts/Startup.js")" type="text/javascript"></script>*@
<script src="@Url.Content("~/Scripts/jquery.word.translate.js")" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function () {
        $("#word").pluginTest();
        $("#word").translate();
    });
    
</script>
<script>
    (function ($) {
        $.fn.extend({
            pluginTest: function () {
                alert("plugin test");
            }
        });
    } (jQuery))
</script>

 

Developer
Jan 4, 2012 at 7:13 PM

Hi,

I believe the problem you mentioned is caused by the fact that you are not adding the jQuery library files in your page as discussed in this other thread.

Please let us know if this is not your case.

Also I believe you might find the Widget QuickStart useful, as it shows the way Project Silk uses the jQuery UI Widget Factory to create maintainable widgets that implement client-side behavior.

Regards,

Agustin Adami
http://blogs.southworks.net/aadami

Jan 5, 2012 at 7:04 AM

Yes, I missed the library files. Appreciate!