views:

30

answers:

2

I'm having yet another wtf moment with jQuery.

I am importing the following files (among others)

<script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.core.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.tabs.min.js" type="text/javascript"></script>

html:

    <div id="tabs">
  <ul>
   <li><a href="#tabs-1">test1</a></li>
   <li><a href="#tabs-2">test2</a></li>
   <li><a href="#tabs-3">test3</a></li>
  </ul>
  <div id="tabs-1">
   <p>test1 content</p>
  </div>
  <div id="tabs-2">
   <p>test2 content</p>
  </div>
  <div id="tabs-3">
   <p>test3 content</p>
  </div>
 </div>

javascript:

$(document).ready(function() {
    alert($("#tabs"));     // '[object Object]' 
    alert($("#tabs").tabs) // 'undefined'
    $("#tabs").tabs();     // doesn't work
    alert('working');      // doesn't reach this line
});

I don't really see how this can possibly be difficult, but I've still somehow managed to spend 2 hours without getting it working. Any ideas?

+1  A: 

It's easier to use jQuery UI as a package, if you only need a subset of it that's fine, you can configure your download here.

This way you're including one .js for jQuery UI on the page, not trying to figure out dependencies :)

Alternatively, you can include the full library from a CDN, such as google's, like this:

<script type="text/javscript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"&gt;&lt;/script&gt;

If you're using a default theme, they host the CSS as well (be sure to change the version in the URL). You can see a question with links to that here.

Nick Craver
+1  A: 

When I go to do a custom download for tabs only it says "Widget is a needed dependency of Tabs.", so it looks like you need (if you haven't yet) the widget code too.

Here it is minified:

/*!
 * jQuery UI Widget 1.8.2
 *
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Widget
 */
(function(b){var j=b.fn.remove;b.fn.remove=function(a,c){return this.each(function(){if(!c)if(!a||b.filter(a,[this]).length)b("*",this).add(this).each(function(){b(this).triggerHandler("remove")});return j.call(b(this),a,c)})};b.widget=function(a,c,d){var e=a.split(".")[0],f;a=a.split(".")[1];f=e+"-"+a;if(!d){d=c;c=b.Widget}b.expr[":"][f]=function(h){return!!b.data(h,a)};b[e]=b[e]||{};b[e][a]=function(h,g){arguments.length&&this._createWidget(h,g)};c=new c;c.options=b.extend({},c.options);b[e][a].prototype=
b.extend(true,c,{namespace:e,widgetName:a,widgetEventPrefix:b[e][a].prototype.widgetEventPrefix||a,widgetBaseClass:f},d);b.widget.bridge(a,b[e][a])};b.widget.bridge=function(a,c){b.fn[a]=function(d){var e=typeof d==="string",f=Array.prototype.slice.call(arguments,1),h=this;d=!e&&f.length?b.extend.apply(null,[true,d].concat(f)):d;if(e&&d.substring(0,1)==="_")return h;e?this.each(function(){var g=b.data(this,a),i=g&&b.isFunction(g[d])?g[d].apply(g,f):g;if(i!==g&&i!==undefined){h=i;return false}}):this.each(function(){var g=
b.data(this,a);if(g){d&&g.option(d);g._init()}else b.data(this,a,new c(d,this))});return h}};b.Widget=function(a,c){arguments.length&&this._createWidget(a,c)};b.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",options:{disabled:false},_createWidget:function(a,c){this.element=b(c).data(this.widgetName,this);this.options=b.extend(true,{},this.options,b.metadata&&b.metadata.get(c)[this.widgetName],a);var d=this;this.element.bind("remove."+this.widgetName,function(){d.destroy()});this._create();
this._init()},_create:function(){},_init:function(){},destroy:function(){this.element.unbind("."+this.widgetName).removeData(this.widgetName);this.widget().unbind("."+this.widgetName).removeAttr("aria-disabled").removeClass(this.widgetBaseClass+"-disabled ui-state-disabled")},widget:function(){return this.element},option:function(a,c){var d=a,e=this;if(arguments.length===0)return b.extend({},e.options);if(typeof a==="string"){if(c===undefined)return this.options[a];d={};d[a]=c}b.each(d,function(f,
h){e._setOption(f,h)});return e},_setOption:function(a,c){this.options[a]=c;if(a==="disabled")this.widget()[c?"addClass":"removeClass"](this.widgetBaseClass+"-disabled ui-state-disabled").attr("aria-disabled",c);return this},enable:function(){return this._setOption("disabled",false)},disable:function(){return this._setOption("disabled",true)},_trigger:function(a,c,d){var e=this.options[a];c=b.Event(c);c.type=(a===this.widgetEventPrefix?a:this.widgetEventPrefix+a).toLowerCase();d=d||{};if(c.originalEvent){a=
b.event.props.length;for(var f;a;){f=b.event.props[--a];c[f]=c.originalEvent[f]}}this.element.trigger(c,d);return!(b.isFunction(e)&&e.call(this.element[0],c,d)===false||c.isDefaultPrevented())}}})(jQuery);
;
ILMV
that's fixed it! thank you!!!!!! It would have been nice of them to include that in the list of dependencies in the documentation so I didn't waste half a day on it :angry face:
fearofawhackplanet
Well it does, but it doesn't list widget as one of them :S, it was only when I went to build the custom download did it say it was required. Oh well, you're very welcome.
ILMV