HYXT Blog

we produce valuable software for K12.
clock December 2, 2008 18:44 by author Sky Jia (贾超)

From http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx by Scott Guthrie

Last month I blogged about how Microsoft is extending support for jQuery.  Over the last few weeks we've been working with the jQuery team to add great jQuery intellisense support within Visual Studio 2008 and Visual Web Developer 2008 Express (which is free).  This is now available to download and use.

Steps to Enable jQuery Intellisense in VS 2008

To enable intellisense completion for jQuery within VS you'll want to follow three steps:

Step 1: Install VS 2008 SP1

VS 2008 SP1 adds richer JavaScript intellisense support to Visual Studio, and adds code completion support for a broad range of JavaScript libraries.

You can download VS 2008 SP1 and Visual Web Developer 2008 Express SP1 here.

Step 2: Install VS 2008 Patch KB958502 to Support "-vsdoc.js" Intellisense Files

Two weeks ago we shipped a patch that you can apply to VS 2008 SP1 and VWD 2008 Express SP1 that causes Visual Studio to check for the presence of an optional "-vsdoc.js" file when a JavaScript library is referenced, and if present to use this to drive the JavaScript intellisense engine.

These annotated "-vsdoc.js" files can include XML comments that provide help documentation for JavaScript methods, as well as additional code intellisense hints for dynamic JavaScript signatures that cannot automatically be inferred.  You can learn more about this patch here.  You can download it for free here.

Step 3: Download the jQuery-vsdoc.js file

We've worked with the jQuery team to put together a jQuery-vsdoc.js file that provides help comments and support for JavaScript intellisense on chained jQuery selector methods.  You can download both jQuery and the jQuery-vsdoc file from the official download page on the jQuery.com site:

Save the jquery-vsdoc.js file next to your jquery.js file in your project (and make sure its naming prefix matches the jquery file name):

You can then reference the standard jquery file with an html <script/> element like so:

Or alternatively reference it using the <asp:scriptmanager/> control, or by adding a /// <reference/> comment at the top of a standalone .js file. 

When you do this VS will now look for a -vsdoc.js file in the same directory as the script file you are referencing, and if found will use it for help and intellisense.  The annotated

For example, we could use jQuery to make a JSON based get request, and get intellisense for the method (hanging off of $.):

As well as help/intellisense for the $.getJSON() method's parameters:

 

The intellisense will continue to work if you nest a callback function within the method call.  For example, we might want to iterate over each JSON object returned from the server:

And for each of the items we could execute another nested callback function:

We could use the each callback function to dynamically append a new image to a list (the image src attribute will point to the URL of the returned JSON media image):

And on each dynamically created image we could wire-up a click event handler so that when it is pressed it will disappear via an animation:

Notice how the jQuery intellisense works cleanly at each level of our code. 

JavaScript Intellisense Tips and Tricks

Jeff King from the Web Tools team wrote up a great post earlier this week that answers a number of common questions about how JavaScript intellisense works with VS 2008.  I highly recommend reading it.

One trick he talks about which I'll show here is a technique you can use when you want to have JavaScript intellisense work within user-controls/partials (.ascx files).  Often you don't want to include a JavaScript library <script src=""/> reference  within these files, and instead have this live on the master page or content page the user control is used within.  The problem of course when you do this is that by default VS has no way of knowing that this script is available within the user control - and so won't provide intellisense of it for you.

One way you can enable this is by adding the <script src=""/> element to your user control, but then surround it with a server-side <% if %> block that always evaluates to false at runtime:

At runtime ASP.NET will never render this script tag (since it is wrapped in an if block that is always false).  However, VS will evaluate the <script/> tag and provide intellisense for it within the user-control.  A useful technique to use for scenarios like the user control one.  Jeff has even more details in his FAQ post as well as his original jQuery intellisense post.  Rick Strahl also has a good post about using jQuery intellisense here.

More Information

To learn more about jQuery, I recommend watching Stephen Walther's ASP.NET and jQuery PDC talk. Click here to download his code samples and powerpoint presentation.

Rick Strahl also has a really nice Introduction to jQuery article that talks about using jQuery with ASP.NET.  Karl Seguin has two nice jQuery primer posts here and here that provide shorter overviews of some of the basics of how to use jQuery. 

I also highly recommend the jQuery in Action book.

Hope this helps,

Scott 


clock November 19, 2008 09:49 by author arthur
Follwos are the jQuery Printable API. you can get their particular introduction in http://visualjquery.com/

Core

  • $(html)
  • $(elems)
  • $(fn)
  • $(expr, context)
  • $.extend(prop)
  • $.noConflict()
  • each(fn)
  • eq(pos)
  • get()
  • get(num)
  • gt(pos)
  • index(subject)
  • length()
  • lt(pos)
  • size()

DOM

  • addClass(class)
  • attr(name)
  • attr(properties)
  • attr(key, value)
  • attr(key, value)
  • html()
  • html(val)
  • removeAttr(name)
  • removeClass(class)
  • text()
  • text(val)
  • toggleClass(class)
  • val()
  • val(val)
  • after(content)
  • append(content)
  • appendTo(content)
  • before(content)
  • clone(deep)
  • empty()
  • insertAfter(content)
  • insertBefore(content)
  • prepend(content)
  • prependTo(content)
  • remove(expr)
  • wrap(html)
  • wrap(elem)
  • add(expr)
  • add(html)
  • add(elements)
  • children(expr)
  • contains(str)
  • end()
  • filter(expression)
  • filter(filter)
  • find(expr)
  • is(expr)
  • next(expr)
  • not(el)
  • not(expr)
  • not(elems)
  • parent(expr)
  • parents(expr)
  • prev(expr)
  • siblings(expr)

CSS

  • css(name)
  • css(properties)
  • css(key, value)
  • height()
  • height(val)
  • width()
  • width(val)

JavaScript

  • $.browser()
  • $.each(obj, fn)
  • $.extend(target, prop1, propN)
  • $.grep(array, fn, inv)
  • $.map(array, fn)
  • $.merge(first, second)
  • $.trim(str)

Events

  • bind(type, data, fn)
  • blur()
  • blur(fn)
  • change(fn)
  • click()
  • click(fn)
  • dblclick(fn)
  • error(fn)
  • focus()
  • focus(fn)
  • hover(over, out)
  • keydown(fn)
  • keypress(fn)
  • keyup(fn)
  • load(fn)
  • mousedown(fn)
  • mousemove(fn)
  • mouseout(fn)
  • mouseover(fn)
  • mouseup(fn)
  • one(type, data, fn)
  • ready(fn)
  • resize(fn)
  • scroll(fn)
  • select()
  • select(fn)
  • submit()
  • submit(fn)
  • toggle(even, odd)
  • trigger(type)
  • unbind(type, fn)
  • unload(fn)

Effects

  • animate(params, speed, easing, callback)
  • fadeIn(speed, callback)
  • fadeOut(speed, callback)
  • fadeTo(speed, opacity, callback)
  • hide()
  • hide(speed, callback)
  • show()
  • show(speed, callback)
  • slideDown(speed, callback)
  • slideToggle(speed, callback)
  • slideUp(speed, callback)
  • toggle()

Ajax

  • $.ajax(properties)
  • $.ajaxSetup(settings)
  • $.ajaxTimeout(time)
  • $.get(url, params, callback)
  • $.getIfModified(url, params, callback)
  • $.getJSON(url, params, callback)
  • $.getScript(url, callback)
  • $.post(url, params, callback)
  • ajaxComplete(callback)
  • ajaxError(callback)
  • ajaxSend(callback)
  • ajaxStart(callback)
  • ajaxStop(callback)
  • ajaxSuccess(callback)
  • load(url, params, callback)
  • loadIfModified(url, params, callback)
  • serialize()

clock October 26, 2008 22:42 by author ethan

【原文地址】jQuery and Microsoft
【原文发表日期】 Sunday, September 28, 2008 11:32 AM

jQuery 是个轻量级的开源JavaScript库(只有15kb大),在相当短的时间内,已经成为网上最受欢迎的JavaScript库之一。

jQuery如此受欢迎,有很大一部分是因为它允许你用最少数量的代码就能非常优雅地(且非常有效地)找出和操作HTML元素。jQuery是通过一个非常棒的“selector”API来实现这个的,该API允许开发人员查询HTML元素,然后对它们施加“命令(commands)”。jQuery命令的一个特征是,它们可以“串连(chained)”在一起,这样,一个命令的结果可以转而注入到另一个命令中去。jQuery还包含了一套内置的动画效果APIs,这些APIs可以用作命令之用。这样的组合允许你只要击键几次就可以做一些非常酷的事情。

例如,下面的JavaScript用了jQuery找出页面上所有拥有一个CSS类为 "product" 的 <div> 元素,然后使用动画效果慢慢使它们消失:

另一个例子,下面的JavaScript用了jQuery找出页面上一个特定的id为"datagrid1"的<table>,然后获取datagrid中的每隔一行的<tr>,给这些<tr>元素设置一个CSS类为"even",用来设置隔行的背景颜色:

[注意:这两个例子都改变自优秀图书《jQuery in Action》 中的代码片段]

一直以来,许许多多开发人员要求我们在ASP.NET AJAX中添加象上面这样的元素选择和动画效果操作的功能,这些支持其实早就作为提议的功能列在我们几个月前发表的《ASP.NET AJAX 路线图》中了。但当开发团队开始研究实现时,他们很快就意识到jQuery对这些场景的支持已经非常出色,而且围绕着jQuery已经建立有一个巨大的生态系统和社区。jQuery库在同一个页面上也与ASP.NET AJAX和 ASP.NET AJAX Control Toolkit协作良好。

我们想,与其复制这些功能,原封不动(as-is)地使用jQuery,将其作为VS/ASP.NET中的一个标准的,受支持的库不更好吗?然后我们可以将精力集中在建造充分利用jQuery的新功能上。我们给jQuery开发团队发了信,看他们对此是否有兴趣,我们很快收到回复,他们也觉得这是个非常有趣的主意。

对jQuery的支持

今天,我非常兴奋地宣布,从此以后,微软将把jQuery和Visual Studio一起发行。我们将把jQuery JavaScript库原封不动地发行,不会生成分叉或改变jQuery主干的源代码。相关文件会继续在现有的jQuery MIT许可下使用和发布。

我们还将发布intellisense注释版本,在设计时提供很好的Visual Studio intellisense和帮助集成。例如:

在有串连的命令时:

jQuery intellisense注释支持将能在几个星期后免费下载(该支持可以在VS 2008 SP1和免费的Visual WebDeveloper 2008 Express SP1下工作)。新的ASP.NETMVC也将发行jQuery,会将jQuery库默认加到所有新的项目中。

从今年稍后开始,我们还将把微软的产品支持扩展到jQuery,这将允许开发人员和企业每周7天/每天24小时都可以向Microsoft PSS(产品支持服务)电话求助和开设jQuery支持案子。

以后,我们将把jQuery作为类库之一,用来在ASP.NET AJAX控件工具包中实现高层次的控件,以及在ASP.NET MVC中实现新的Ajax服务器端辅助方法。加入ASP.NET AJAX的新功能(象客户端 模板 支持)也将设计来与jQuery完美集成。

我们还计划向jQuery开源项目贡献测试,缺陷修补和补丁。所有这些都将经过标准的jQuery补丁评估(patch review)过程。

结语

能与jQuery开发团队合作,我们非常高兴。jQuery是个极棒的类库,是我们认为能让ASP.NET和ASP.NET AJAX开发人员受益匪浅的东西。我们期待它将与Visual Studio和ASP.NET完美结合,能给更多的开发人员带来好处。

想了解关于今天这个宣布的细节,请参阅jQuery开发团队博客John Resig的贴子。Scott Hanselman也即将发表一个很好的教程,展示jQuery与ASP.NET AJAX(包括新的客户端模板引擎),以及ADO.NET数据服务(是在.NET 3.5 SP1中发布的,以前的代号名为“Astoria”)的集成。

希望本文对你有所帮助,

Scott

 

 

【译注】这应该是个非常重大的事件,好像这是微软第一次公开支持一个开源产品。从原贴子的跟贴来看,众多开发人员都是喜出望外。

clock October 7, 2008 12:08 by author War3

From: http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx

 

jQuery is a lightweight open source JavaScript library (only 15kb in size) that in a relatively short span of time has become one of the most popular libraries on the web.

A big part of the appeal of jQuery is that it allows you to elegantly (and efficiently) find and manipulate HTML elements with minimum lines of code.  jQuery supports this via a nice "selector" API that allows developers to query for HTML elements, and then apply "commands" to them.  One of the characteristics of jQuery commands is that they can be "chained" together - so that the result of one command can feed into another.  jQuery also includes a built-in set of animation APIs that can be used as commands.  The combination allows you to do some really cool things with only a few keystrokes.

For example, the below JavaScript uses jQuery to find all <div> elements within a page that have a CSS class of "product", and then animate them to slowly disappear:

As another example, the JavaScript below uses jQuery to find a specific <table> on the page with an id of "datagrid1", then retrieves every other <tr> row within the datagrid, and sets those <tr> elements to have a CSS class of "even" - which could be used to alternate the background color of each row:

[Note: both of these samples were adapted from code snippets in the excellent jQuery in Action book]

Providing the ability to perform selection and animation operations like above is something that a lot of developers have asked us to add to ASP.NET AJAX, and this support was something we listed as a proposed feature in the ASP.NET AJAX Roadmap we published a few months ago.  As the team started to investigate building it, though, they quickly realized that the jQuery support for these scenarios is already excellent, and that there is a huge ecosystem and community built up around it already.  The jQuery library also works well on the same page with ASP.NET AJAX and the ASP.NET AJAX Control Toolkit.

Rather than duplicate functionality, we thought, wouldn't it be great to just use jQuery as-is, and add it as a standard, supported, library in VS/ASP.NET, and then focus our energy building new features that took advantage of it?  We sent mail the jQuery team to gauge their interest in this, and quickly heard back that they thought that it sounded like an interesting idea too.

Supporting jQuery

I'm excited today to announce that Microsoft will be shipping jQuery with Visual Studio going forward.  We will distribute the jQuery JavaScript library as-is, and will not be forking or changing the source from the main jQuery branch.  The files will continue to use and ship under the existing jQuery MIT license.

We will also distribute intellisense-annotated versions that provide great Visual Studio intellisense and help-integration at design-time.  For example:

and with a chained command:

The jQuery intellisense annotation support will be available as a free web-download in a few weeks (and will work great with VS 2008 SP1 and the free Visual Web Developer 2008 Express SP1).  The new ASP.NET MVC download will also distribute it, and add the jQuery library by default to all new projects.

We will also extend Microsoft product support to jQuery beginning later this year, which will enable developers and enterprises to call and open jQuery support cases 24x7 with Microsoft PSS.

Going forward we'll use jQuery as one of the libraries used to implement higher-level controls in the ASP.NET AJAX Control Toolkit, as well as to implement new Ajax server-side helper methods for ASP.NET MVC.  New features we add to ASP.NET AJAX (like the new client template support) will be designed to integrate nicely with jQuery as well. 

We also plan to contribute tests, bug fixes, and patches back to the jQuery open source project.  These will all go through the standard jQuery patch review process.

Summary

We are really excited to be able to partner with the jQuery team on this.  jQuery is a fantastic library, and something we think can really benefit ASP.NET and ASP.NET AJAX developers.  We are looking forward to having it work great with Visual Studio and ASP.NET, and to help bring it to an even larger set of developers.

For more details on today's announcement, please check out John Resig's post on the jQuery team blog.  Scott Hanselman is also about to post a nice tutorial that shows off integrating jQuery with ASP.NET AJAX (including the new client templating engine) as well as ADO.NET Data Services (which shipped in .NET 3.5 SP1 and was previously code-named "Astoria").

Hope this helps,

Scott


Search

Calendar

<<  September 2010  >>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

Categories

Tags