Javascript

ExtJS4 Viewport Example

This is an simple example to show you how to create a viewport in ExtJs4. The Viewport renders itself to the document body, and automatically sizes itself to the size of the browser viewport and manages window resizing. There may only be one Viewport created in a page. The Viewport does not provide scrolling, so child Panels within the Viewport should provide for scrolling if needed using the autoScroll config. Unlike the panel component of Ext JS, Viewport does not have a tbar option. ...

ExtJS4 : read posting JSON data in PHP

I am working on a Ext-JS web application which needs to send data to the PHP server side to store. It took me a while to find out how to decodes the receiving JSON string in PHP. Ext-JS Assume you have a model and calling save to send a ajax request. [code] Ext.define('User', { extend: 'Ext.data.Model', fields: ['id', 'name', 'email'], proxy: { type: 'ajax', url : '/users' } }); var user = Ext.create('User', {name: 'Ed Spencer', email: 'ed@...

ExtJS4: Add Custom Right Click Menu in MVC

The way to create a custom menu in mouse right click event function in ExtJS 4 is little different with pre-version. It seems in Ext 4.0.2 they changed event name and arguments order. First, let's see how we create the menu in Ext 3. I get this example from aditia rahman: [code] var menu1 = new Ext.menu.Menu({ items: [ { text: 'I like Ext', checked: true }, '-', { text: 'Open With', menu: { items:...

Using Global variables and arrays in Extjs 4

This example will show you how to declare a global var and arrays in Extjs MVC application. You know where to find this code : [code] <script type="text/javascript"> Ext.BLANK_IMAGE_URL = '/Content/images/default/s.gif'; </script> [/code] Global application variable : [code] <script type="text/javascript"> Ext.BLANK_IMAGE_URL = '/Content/images/default/s.gif'; Ext.MY_GLOBAL_VAR = '<?php echo $myGlobalVar; ?>...

ExtJS4学习笔记 PHP代码

笔者在ExtJS4学习笔记原文中使用的服务器端代码是ASP的,我把它转成了PHP的。方便PHP的爱好者使用。代码如下: [code] <? //header('Cache-Control: no-cache, must-revalidate'); //header('Content-type: application/json'); //返回JSON数据,自定义一些测试数据。。 //这里的参数与EXT3.x相同,区别在于排序字段和排序方式使用了新的属性。 //由于这里是测试数据,接收的参数只用到了start,limit。sorts和dir在实际操作过程中,将之加入SQL的ORDER BY里即可。 $start = empty($_REQUEST["start"])?'':$_REQUEST["start"]; $limit = empty($_REQUEST["limit"])?'':$_REQUEST["limit"]; if ( $start == &qu...

Extjs- Ext.extend函数的使用

Ext.extend在Extjs 中扮演着重大角色,是Extjs中几个重要函数之一。要想深入了解EXTJS,这个函数非掌握不可,网上有很多关于这个函数的源码分析和介绍方面的文章,这里我只总结关于这个函数的使用的下几种情况,不详细分析这个函数的源码。 Example one: [code] function Base(config) { this.name=config.name; this.age=config.age; this.sex=config.sex; } function base(config) { this.identity=config.identity; this.msg=config.msg; this.phone=config.phone; base.superclass.constructor.call(this,config); } Ext.extend(base,Base,{ showMsg:function(){ window.alert(this.name+' '+...

Sorting a two dimensional array in javascript

Sorting arrays in JavaScript is done via the method array.sort(). Passing in a function reference into array.sort() As touched on already, array.sort() accepts an optional parameter in the form of a function reference (lets call it sortfunction). The format of this function looks like this: [code] array.sort(sortfunction) function sortfunction(a, b){ //Compare "a" and "b" in some fashion, and return -1, 0, or 1 } [/code] When such a function is passed in...

Pass variable to javascript use javascript

Client wants add following tracking code on website: [code] <script type="text/javascript" src="http://www.demo.com/show.php?mpt=[CACHEBUSTER]&mpvc="> </script> <noscript> <a href="http://www.demo.com/show.php?mpt=[CACHEBUSTER]"> <img src="http://www.demo.com/show.php?mpt=[CACHEBUSTER]" alt="Click Here" border="0"> </a> </noscript> [/code] To ensure accurate tracking, the...

How to use the W3C Geolocation API

Introduction Imagine visiting a city for the first time. You're hungry, but don't know where the nearest restaurants are and which of them are any good. Wouldn't it be nice if some app could detect your location and provide you with a list of restaurants closest to you, along with reviews and ratings for each one? And this is not the only consideration — could it detect your location accurately, keeping in mind your privacy as well? This is where the W3C Geolocation API comes in, suppo...

Javascript trim function

In programming, trim is a string manipulation function or algorithm. The most popular variants of the trim function strip only the beginning or end of the string. Typically named ltrim and rtrim respectively. This Javascript code trim implementation removes all leading and trailing occurrences of a set of characters specified. If no characters are specified it will trim whitespace characters from the beginning or end or both of the string. Without the second parameter, Javascript function ...