浏览代码

[core] Add KO binding for selecting content with one click

By adding data-bind="oneClickSelect" the user will be able to select all the contents of that element with one click.
Johan Åhlén 10 年之前
父节点
当前提交
c05366d
共有 1 个文件被更改,包括 15 次插入0 次删除
  1. 15 0
      desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

+ 15 - 0
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -630,6 +630,21 @@ ko.bindingHandlers.daterangepicker = {
   }
 }
 
+ko.bindingHandlers.oneClickSelect = {
+  init: function (element) {
+    $(element).click(function() {
+      if (document.selection) {
+        var range = document.body.createTextRange();
+        range.moveToElementText(element);
+        range.select();
+      } else if (window.getSelection) {
+        var range = document.createRange();
+        range.selectNode(element);
+        window.getSelection().addRange(range);
+      }
+    });
+  }
+};
 
 ko.bindingHandlers.augmenthtml = {
   render: function (element, valueAccessor, allBindingsAccessor, viewModel) {