Created
August 15, 2011 15:46
-
-
Save ColinCampbell/1147034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ========================================================================== | |
// Project: SproutCore - JavaScript Application Framework | |
// Copyright: ©2006-2011 Strobe Inc. and contributors. | |
// Portions ©2008-2011 Apple Inc. All rights reserved. | |
// License: Licensed under MIT license (see license.js) | |
// ========================================================================== | |
var get = SC.get, set = SC.set, getPath = SC.getPath; | |
/** | |
@class | |
Implements basic target and action support for views. | |
@author Erich Ocean | |
@author Colin Campbell ([email protected]) | |
@since SproutCore 1.7 | |
*/ | |
SC.ActionSupport = | |
/** @scope SC.ActionSupport.prototype */ { | |
/** | |
The target object to invoke the action on when fireAction() is called. | |
If you set this target, the action will be called on the target object | |
directly when fireAction() is called. If you leave this property set to | |
null, then the responder chain will be searched for a view that implements | |
the action. | |
@type Object | |
@default null | |
*/ | |
target: null, | |
/** | |
The name of the action you want triggered when fireAction() is called. | |
This property is used in conjunction with the target property to execute | |
a method when fireAction() is called. | |
If you do not set a target, then calling fireAction() will cause the | |
responder chain to search for a view that implements the action you name | |
here. If you set a target, then fireAction() will try to call the | |
method on the target itself. | |
@type String | |
@default null | |
*/ | |
action: null, | |
/** | |
Will be sent along with the action to provide the context of the action. | |
This is an easy way to include information along with the action. | |
@type Object | |
@default null | |
*/ | |
actionContext: null, | |
/** | |
Perform the action. If an action paramter is not provided, then | |
the action defaults to the `action` property. | |
@param {String} [action] The action to fire. | |
@returns {Boolean} true if successful | |
@returns {Boolean} false otherwise | |
*/ | |
fireAction: function(action) { | |
var target = this.get('target') || this; | |
if (action === undefined) { action = this.get('action'); } | |
if (action) { | |
if (typeof target === 'string') { target = getPath(target); } | |
if (typeof target.sendAction === 'function') { | |
return target.sendAction(action, this, this.get('actionContext')); | |
} else { | |
if (typeof action === 'string') { action = target[action]; } | |
return action.call(target, this, this.get('actionContext')); | |
} | |
} | |
return false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment