-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
093e796
commit 9d70022
Showing
5 changed files
with
24 additions
and
248 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,138 +1,22 @@ | ||
'use strict'; | ||
|
||
var Vue = require('vue'); | ||
var Vue__default = 'default' in Vue ? Vue['default'] : Vue; | ||
|
||
// @NOTE: We have to use Vue.nextTick because the element might not be | ||
// present at the time model changes, but will be in the next batch. | ||
// But because we use Vue.nextTick, the directive may already be unbound | ||
// by the time the callback executes, so we have to make sure it was not. | ||
|
||
var focus = { | ||
priority: 1000, | ||
|
||
bind: function() { | ||
var self = this; | ||
this.bound = true; | ||
|
||
this.focus = function() { | ||
if (self.bound === true) { | ||
self.el.focus(); | ||
} | ||
}; | ||
|
||
this.blur = function() { | ||
if (self.bound === true) { | ||
self.el.blur(); | ||
} | ||
}; | ||
}, | ||
|
||
update: function(value) { | ||
if (value) { | ||
Vue__default.nextTick(this.focus); | ||
} else { | ||
Vue__default.nextTick(this.blur); | ||
} | ||
inserted: function(el, binding) { | ||
if (binding.value) el.focus(); | ||
else el.blur(); | ||
}, | ||
|
||
unbind: function() { | ||
this.bound = false; | ||
}, | ||
}; | ||
|
||
var focusModel = { | ||
twoWay: true, | ||
priority: 1000, | ||
|
||
bind: function() { | ||
Vue.util.warn( | ||
this.name + '="' + | ||
this.expression + '" is deprecated, ' + | ||
'use v-focus="' + this.expression + '" @focus="' + this.expression + ' = true" @blur="' + this.expression + ' = false" instead' | ||
); | ||
|
||
var self = this; | ||
this.bound = true; | ||
|
||
this.focus = function() { | ||
if (self.bound === true) { | ||
self.el.focus(); | ||
} | ||
}; | ||
|
||
this.blur = function() { | ||
if (self.bound === true) { | ||
self.el.blur(); | ||
} | ||
}; | ||
|
||
this.focusHandler = function() { | ||
self.set(true); | ||
}; | ||
|
||
this.blurHandler = function() { | ||
self.set(false); | ||
}; | ||
|
||
Vue.util.on(this.el, 'focus', this.focusHandler); | ||
Vue.util.on(this.el, 'blur', this.blurHandler); | ||
}, | ||
|
||
update: function(value) { | ||
if (value === true) { | ||
Vue__default.nextTick(this.focus); | ||
} else if (value === false) { | ||
Vue__default.nextTick(this.blur); | ||
} else { | ||
if (process.env.NODE_ENV !== 'production') { | ||
Vue.util.warn( | ||
this.name + '="' + | ||
this.expression + '" expects a boolean value, ' + | ||
'got ' + JSON.stringify(value) | ||
); | ||
} | ||
} | ||
}, | ||
|
||
unbind: function() { | ||
Vue.util.off(this.el, 'focus', this.focusHandler); | ||
Vue.util.off(this.el, 'blur', this.blurHandler); | ||
this.bound = false; | ||
}, | ||
}; | ||
|
||
var focusAuto = { | ||
priority: 100, | ||
bind: function() { | ||
Vue.util.warn( | ||
this.name + ' is deprecated, ' + | ||
'use v-focus="true" instead' | ||
); | ||
|
||
var self = this; | ||
this.bound = true; | ||
|
||
Vue__default.nextTick(function() { | ||
if (self.bound === true) { | ||
self.el.focus(); | ||
} | ||
}); | ||
}, | ||
unbind: function(){ | ||
this.bound = false; | ||
componentUpdated: function(el, binding) { | ||
if (binding.value) el.focus(); | ||
else el.blur(); | ||
}, | ||
}; | ||
|
||
var mixin = { | ||
directives: { | ||
focus: focus, | ||
focusModel: focusModel, | ||
focusAuto: focusAuto, | ||
}, | ||
}; | ||
|
||
exports.focus = focus; | ||
exports.focusModel = focusModel; | ||
exports.focusAuto = focusAuto; | ||
exports.mixin = mixin; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,24 @@ | ||
(function (exports,Vue) { 'use strict'; | ||
|
||
var Vue__default = 'default' in Vue ? Vue['default'] : Vue; | ||
|
||
// @NOTE: We have to use Vue.nextTick because the element might not be | ||
// present at the time model changes, but will be in the next batch. | ||
// But because we use Vue.nextTick, the directive may already be unbound | ||
// by the time the callback executes, so we have to make sure it was not. | ||
(function (exports) { 'use strict'; | ||
|
||
var focus = { | ||
priority: 1000, | ||
|
||
bind: function() { | ||
var self = this; | ||
this.bound = true; | ||
|
||
this.focus = function() { | ||
if (self.bound === true) { | ||
self.el.focus(); | ||
} | ||
}; | ||
|
||
this.blur = function() { | ||
if (self.bound === true) { | ||
self.el.blur(); | ||
} | ||
}; | ||
}, | ||
|
||
update: function(value) { | ||
if (value) { | ||
Vue__default.nextTick(this.focus); | ||
} else { | ||
Vue__default.nextTick(this.blur); | ||
} | ||
inserted: function(el, binding) { | ||
if (binding.value) el.focus(); | ||
else el.blur(); | ||
}, | ||
|
||
unbind: function() { | ||
this.bound = false; | ||
}, | ||
}; | ||
|
||
var focusModel = { | ||
twoWay: true, | ||
priority: 1000, | ||
|
||
bind: function() { | ||
Vue.util.warn( | ||
this.name + '="' + | ||
this.expression + '" is deprecated, ' + | ||
'use v-focus="' + this.expression + '" @focus="' + this.expression + ' = true" @blur="' + this.expression + ' = false" instead' | ||
); | ||
|
||
var self = this; | ||
this.bound = true; | ||
|
||
this.focus = function() { | ||
if (self.bound === true) { | ||
self.el.focus(); | ||
} | ||
}; | ||
|
||
this.blur = function() { | ||
if (self.bound === true) { | ||
self.el.blur(); | ||
} | ||
}; | ||
|
||
this.focusHandler = function() { | ||
self.set(true); | ||
}; | ||
|
||
this.blurHandler = function() { | ||
self.set(false); | ||
}; | ||
|
||
Vue.util.on(this.el, 'focus', this.focusHandler); | ||
Vue.util.on(this.el, 'blur', this.blurHandler); | ||
}, | ||
|
||
update: function(value) { | ||
if (value === true) { | ||
Vue__default.nextTick(this.focus); | ||
} else if (value === false) { | ||
Vue__default.nextTick(this.blur); | ||
} else { | ||
if ('development' !== 'production') { | ||
Vue.util.warn( | ||
this.name + '="' + | ||
this.expression + '" expects a boolean value, ' + | ||
'got ' + JSON.stringify(value) | ||
); | ||
} | ||
} | ||
}, | ||
|
||
unbind: function() { | ||
Vue.util.off(this.el, 'focus', this.focusHandler); | ||
Vue.util.off(this.el, 'blur', this.blurHandler); | ||
this.bound = false; | ||
}, | ||
}; | ||
|
||
var focusAuto = { | ||
priority: 100, | ||
bind: function() { | ||
Vue.util.warn( | ||
this.name + ' is deprecated, ' + | ||
'use v-focus="true" instead' | ||
); | ||
|
||
var self = this; | ||
this.bound = true; | ||
|
||
Vue__default.nextTick(function() { | ||
if (self.bound === true) { | ||
self.el.focus(); | ||
} | ||
}); | ||
}, | ||
unbind: function(){ | ||
this.bound = false; | ||
componentUpdated: function(el, binding) { | ||
if (binding.value) el.focus(); | ||
else el.blur(); | ||
}, | ||
}; | ||
|
||
var mixin = { | ||
directives: { | ||
focus: focus, | ||
focusModel: focusModel, | ||
focusAuto: focusAuto, | ||
}, | ||
}; | ||
|
||
exports.focus = focus; | ||
exports.focusModel = focusModel; | ||
exports.focusAuto = focusAuto; | ||
exports.mixin = mixin; | ||
|
||
})((this.VueFocus = {}),Vue); | ||
})((this.VueFocus = {})); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "vue-focus", | ||
"description": "A set of reusable focus directives for reusable Vue.js components", | ||
"version": "1.0.0", | ||
"version": "2.0.0-rc1", | ||
"author": "Denis Karabaza <[email protected]>", | ||
"browserify": { | ||
"transform": [ | ||
|
@@ -36,7 +36,7 @@ | |
"license": "MIT", | ||
"main": "dist/vue-focus.common.js", | ||
"peerDependencies": { | ||
"vue": "^1.0.0" | ||
"vue": "^2.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|