Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions src/components/chips/js/chipController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular

/**
* Controller for the MdChip component. Responsible for handling keyboard
* events and editting the chip if needed.
* events and editing the chip if needed.
*
* @param $scope
* @param $element
Expand Down Expand Up @@ -42,7 +42,7 @@ function MdChipCtrl ($scope, $element, $mdConstant, $timeout, $mdUtil) {
/**
* @type {boolean}
*/
this.isEditting = false;
this.isEditing = false;

/**
* @type {MdChipsCtrl}
Expand All @@ -65,14 +65,14 @@ MdChipCtrl.prototype.init = function(controller) {

if (this.enableChipEdit) {
this.$element.on('keydown', this.chipKeyDown.bind(this));
this.$element.on('mousedown', this.chipMouseDown.bind(this));
this.$element.on('dblclick', this.chipMouseDoubleClick.bind(this));
this.getChipContent().addClass('_md-chip-content-edit-is-enabled');
}
};


/**
* @return {Object}
* @return {Object} first element with the md-chip-content class
*/
MdChipCtrl.prototype.getChipContent = function() {
var chipContents = this.$element[0].getElementsByClassName('md-chip-content');
Expand All @@ -81,28 +81,29 @@ MdChipCtrl.prototype.getChipContent = function() {


/**
* @return {Object}
* @return {Object} first content element of the chips content element
*/
MdChipCtrl.prototype.getContentElement = function() {
return angular.element(this.getChipContent().children()[0]);
return angular.element(this.getChipContent().contents()[0]);
};


/**
* @return {number}
* @return {number} index of this chip
*/
MdChipCtrl.prototype.getChipIndex = function() {
return parseInt(this.$element.attr('index'));
};


/**
* Presents an input element to edit the contents of the chip.
* Update the chip's contents, focus the chip if it's selected, and exit edit mode.
* If the contents were updated to be empty, remove the chip and re-focus the input element.
*/
MdChipCtrl.prototype.goOutOfEditMode = function() {
if (!this.isEditting) return;
if (!this.isEditing) return;

this.isEditting = false;
this.isEditing = false;
this.$element.removeClass('_md-chip-editing');
this.getChipContent()[0].contentEditable = 'false';
var chipIndex = this.getChipIndex();
Expand All @@ -127,7 +128,7 @@ MdChipCtrl.prototype.goOutOfEditMode = function() {

/**
* Given an HTML element. Selects contents of it.
* @param node
* @param {Element} node
*/
MdChipCtrl.prototype.selectNodeContents = function(node) {
var range, selection;
Expand All @@ -149,7 +150,7 @@ MdChipCtrl.prototype.selectNodeContents = function(node) {
* Presents an input element to edit the contents of the chip.
*/
MdChipCtrl.prototype.goInEditMode = function() {
this.isEditting = true;
this.isEditing = true;
this.$element.addClass('_md-chip-editing');
this.getChipContent()[0].contentEditable = 'true';
this.getChipContent().on('blur', function() {
Expand All @@ -164,15 +165,15 @@ MdChipCtrl.prototype.goInEditMode = function() {
* Handles the keydown event on the chip element. If enable-chip-edit attribute is
* set to true, space or enter keys can trigger going into edit mode. Enter can also
* trigger submitting if the chip is already being edited.
* @param event
* @param {KeyboardEvent} event
*/
MdChipCtrl.prototype.chipKeyDown = function(event) {
if (!this.isEditting &&
if (!this.isEditing &&
(event.keyCode === this.$mdConstant.KEY_CODE.ENTER ||
event.keyCode === this.$mdConstant.KEY_CODE.SPACE)) {
event.preventDefault();
this.goInEditMode();
} else if (this.isEditting &&
} else if (this.isEditing &&
event.keyCode === this.$mdConstant.KEY_CODE.ENTER) {
event.preventDefault();
this.goOutOfEditMode();
Expand All @@ -181,12 +182,10 @@ MdChipCtrl.prototype.chipKeyDown = function(event) {


/**
* Handles the double click event
* Enter edit mode if we're not already editing and the enable-chip-edit attribute is enabled.
*/
MdChipCtrl.prototype.chipMouseDown = function() {
if(this.getChipIndex() == this.parentController.selectedChip &&
this.enableChipEdit &&
!this.isEditting) {
MdChipCtrl.prototype.chipMouseDoubleClick = function() {
if (this.enableChipEdit && !this.isEditing) {
this.goInEditMode();
}
};
13 changes: 8 additions & 5 deletions src/components/chips/js/chipDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ angular
* @module material.components.chips
*
* @description
* `<md-chip>` is a component used within `<md-chips>` and is responsible for rendering individual
* chips.
* `<md-chip>` is a component used within `<md-chips>`. It is responsible for rendering an
* individual chip.
*
*
* @usage
* <hljs lang="html">
* <md-chip>{{$chip}}</md-chip>
* <md-chips>
* <md-chip>{{$chip}}</md-chip>
* </md-chips>
* </hljs>
*
*/

// This hint text is hidden within a chip but used by screen readers to
// This hint text is visually hidden within a chip but used by screen readers to
// inform the user how they can interact with a chip.

var DELETE_HINT_TEMPLATE = '\
<span ng-if="!$mdChipsCtrl.readonly" class="md-visually-hidden">\
{{$mdChipsCtrl.deleteHint}}\
Expand All @@ -32,6 +33,8 @@ var DELETE_HINT_TEMPLATE = '\
*
* @param $mdTheming
* @param $mdUtil
* @param $compile
* @param $timeout
* @ngInject
*/
function MdChip($mdTheming, $mdUtil, $compile, $timeout) {
Expand Down
Loading