Skip to content

Commit

Permalink
Merge pull request #8 from zpbx/str-conv
Browse files Browse the repository at this point in the history
Update String conversion method.
  • Loading branch information
cssmagic committed Oct 9, 2014
2 parents d06ba4e + d2ecd58 commit 3fda41d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "action.js",
"version": "0.2.1",
"version": "0.2.2",
"homepage": "https://github.com/cssmagic/action.js",
"authors": [
"cssmagic"
Expand Down
30 changes: 16 additions & 14 deletions src/action.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Action.js - Easy and lazy solution for click-event-binding.
* (https://github.com/cssmagic/action.js)
* Released under the MIT license.
* https://github.com/cssmagic/action.js
*/
var action = function () {
'use strict'
Expand All @@ -11,6 +12,20 @@ var action = function () {
var SELECTOR = '[data-action]'
var _actionList = {}

//util
function _getActionName($elem) {
var result = $elem.data('action') || ''
if (!result) {
var href = $.trim($elem.attr('href'))
if (href && href.indexOf('#') === 0) result = href
}
return _formatActionName(result)
}
function _formatActionName(s) {
var result = s ? $.trim(String(s)).replace(/^[#!]+/, '') : ''
return $.trim(result)
}

function _init() {
var $wrapper = $(document.body || document.documentElement)
$wrapper.on('click', SELECTOR, function (ev) {
Expand All @@ -28,19 +43,6 @@ var action = function () {
}
})
}

function _getActionName($elem) {
var result = $elem.data('action') || ''
if (!result) {
var href = $.trim($elem.attr('href'))
if (href && href.indexOf('#') === 0) result = href
}
return _formatActionName(result)
}
function _formatActionName(s) {
var result = s ? $.trim(s + '').replace(/^[#!]+/, '') : ''
return $.trim(result)
}
function _handle(actionName, context) {
var fn = _actionList[actionName]
if ($.isFunction(fn)) {
Expand Down

0 comments on commit 3fda41d

Please sign in to comment.