You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2018/05/30 16:26:47 UTC

[myfaces-tobago] branch tobago-3.0.x updated: TOBAGO-1902: Migrate to jQuery 3

This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch tobago-3.0.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/tobago-3.0.x by this push:
     new ee0ecc8  TOBAGO-1902: Migrate to jQuery 3
ee0ecc8 is described below

commit ee0ecc835f913029b8aa81d80f5783d2201adcf5
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Wed May 30 18:04:36 2018 +0200

    TOBAGO-1902: Migrate to jQuery 3
    
    Preparation: compatibel changes (resp. jQuery 2.2.4)
    
    (cherry picked from commit 795bbcd)
---
 .../30-concept/70-dataAttribute/dataAttribute.js   |  2 +-
 .../src/main/webapp/script/tobago-testAll.js       |  2 +-
 .../src/main/webapp/test/object/object-full.xhtml  |  2 +-
 .../sheet/sheet-auto-height-header-footer.xhtml    |  2 +-
 .../tobago/standard/script/tobago-sheet.js         | 70 +++++++++++-----------
 .../tobago/standard/script/tobago-tree.js          |  6 +-
 .../resources/tobago/standard/script/tobago.js     | 38 ++++++------
 7 files changed, 61 insertions(+), 61 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/70-dataAttribute/dataAttribute.js b/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/70-dataAttribute/dataAttribute.js
index f739d07..b9132d2 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/70-dataAttribute/dataAttribute.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/70-dataAttribute/dataAttribute.js
@@ -16,7 +16,7 @@
  */
 
 /*
- jQuery(document).ready(function () {
+ jQuery(function () {
  jQuery("[data-colored]")
  .css("background-color", "#aaaaaa")
  .click(function () {
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-testAll.js b/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-testAll.js
index ce62d70..31bce5d 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-testAll.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-testAll.js
@@ -17,7 +17,7 @@
 
 Tobago.registerListener(function() {
   jQuery("iframe").each(function() {
-    jQuery(this).load(function() {
+    jQuery(this).on("load", function() {
 
       var idCount = jQuery(this).attr("id").substring(7);
       var $thisFrame = jQuery("#page\\:tp" + idCount);
diff --git a/tobago-example/tobago-example-test/src/main/webapp/test/object/object-full.xhtml b/tobago-example/tobago-example-test/src/main/webapp/test/object/object-full.xhtml
index bdad532..4d36a30 100644
--- a/tobago-example/tobago-example-test/src/main/webapp/test/object/object-full.xhtml
+++ b/tobago-example/tobago-example-test/src/main/webapp/test/object/object-full.xhtml
@@ -30,7 +30,7 @@
        * XXX We may find a better solution (e. g. partially switch off layout)
        */
 
-      jQuery(document).ready(function () {
+      jQuery(function () {
         jQuery("form").css("width", "100%");
         jQuery("form").css("height", "100%");
         jQuery(".tobago-page-content").css("width", "100%");
diff --git a/tobago-example/tobago-example-test/src/main/webapp/test/sheet/sheet-auto-height-header-footer.xhtml b/tobago-example/tobago-example-test/src/main/webapp/test/sheet/sheet-auto-height-header-footer.xhtml
index 8c9bdb8..c5f41ba 100644
--- a/tobago-example/tobago-example-test/src/main/webapp/test/sheet/sheet-auto-height-header-footer.xhtml
+++ b/tobago-example/tobago-example-test/src/main/webapp/test/sheet/sheet-auto-height-header-footer.xhtml
@@ -90,7 +90,7 @@
     <tc:script file="script/tobago-assert.js"/>
 
     <tc:script>
-      jQuery(document).ready(function () {
+      jQuery(function () {
         jQuery("td>span").css("background-color", "white");
         jQuery("td:odd").css("background-color", "#ffbbff");
         jQuery("td:even").css("background-color", "#bbffbb");
diff --git a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago-sheet.js b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago-sheet.js
index 45adaf4..9172225 100644
--- a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago-sheet.js
+++ b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago-sheet.js
@@ -55,16 +55,16 @@ Tobago.Sheet.init = function(elements) {
     var click = commands ? commands.click : undefined;
     var dblclick = commands ? commands.dblclick : undefined;
     new Tobago.Sheet(id, undefined, undefined, undefined, undefined,
-        click != undefined ? click.action  : undefined,
-        click != undefined ? click.partially : undefined, // fixme: partially no longer used
-        dblclick != undefined ? dblclick.action : undefined,
-        dblclick != undefined ? dblclick.partially: undefined, // fixme: partially no longer used
+        click !== undefined ? click.action  : undefined,
+        click !== undefined ? click.partially : undefined, // fixme: partially no longer used
+        dblclick !== undefined ? dblclick.action : undefined,
+        dblclick !== undefined ? dblclick.partially: undefined, // fixme: partially no longer used
         sheet.data("tobago-behavior-commands")); // type array
 
     //////////////////////////////////////////////
     // XXX bugfix for IE11 (lower than IE11 isn't supported for that feature)
     // if a max-height is set on the sheet,
-    if (Tobago.browser.isMsie && sheet.css("max-height") != "none") {
+    if (Tobago.browser.isMsie && sheet.css("max-height") !== "none") {
       sheet.css("height", sheet.css("height")); // reset the height to the same value
     }
   });
@@ -136,7 +136,7 @@ Tobago.Sheet.setup2 = function (sheets) {
       var columnWidths = jQuery.parseJSON(hidden.val());
       console.info("columnWidths: " + columnWidths); // @DEV_ONLY
     }
-    if (columnWidths != undefined && columnWidths.length == 0) {
+    if (columnWidths !== undefined && columnWidths.length === 0) {
       // otherwise use the layout definition
       var layout = $sheet.data("tobago-layout");
       if (layout && layout.columns && layout.columns.length > 0) {
@@ -148,17 +148,17 @@ Tobago.Sheet.setup2 = function (sheets) {
         var $bodyTable = $sheet.children("div").children("table");
         var $bodyCol = $bodyTable.children("colgroup").children("col");
 
-        console.assert($headerCol.length - 1 == $bodyCol.length, "header and body column number doesn't match");  // @DEV_ONLY
+        console.assert($headerCol.length - 1 === $bodyCol.length, "header and body column number doesn't match");  // @DEV_ONLY
 
         var i;
         var intValue;
         var sumRelative = 0;
         var widthRelative = $bodyTable.width();
         for (i = 0; i < tokens.length; i++) {
-          if (rendered[i] == "true") {
-            if (typeof tokens[i] == "number") {
+          if (rendered[i] === "true") {
+            if (typeof tokens[i] === "number") {
               sumRelative += tokens[i];
-            } else if (typeof tokens[i] == "object" && tokens[i].measure != undefined) {
+            } else if (typeof tokens[i] === "object" && tokens[i].measure !== undefined) {
               intValue = parseInt(tokens[i].measure);
               if (tokens[i].measure.lastIndexOf("px") > 0) {
                 widthRelative -= intValue;
@@ -175,10 +175,10 @@ Tobago.Sheet.setup2 = function (sheets) {
         var headerBodyColCount = 0;
         for (i = 0; i < tokens.length; i++) {
           var colWidth = 0;
-          if (rendered[i] == "true") {
-            if (typeof tokens[i] == "number") {
+          if (rendered[i] === "true") {
+            if (typeof tokens[i] === "number") {
               colWidth = parseInt((tokens[i] * widthRelative) / sumRelative);
-            } else if (typeof tokens[i] == "object" && tokens[i].measure != undefined) {
+            } else if (typeof tokens[i] === "object" && tokens[i].measure !== undefined) {
               intValue = parseInt(tokens[i].measure);
               if (tokens[i].measure.lastIndexOf("px") > 0) {
                 colWidth = intValue;
@@ -257,7 +257,7 @@ Tobago.Sheet.setup2 = function (sheets) {
         var usedWidth = 0;
         var headerBodyColCount = 0;
         for (i = 0; i < rendered.length; i++) {
-          if (rendered[i] == "true") {
+          if (rendered[i] === "true") {
             // last column is the filler column
             var newWidth = headerCols.eq(headerBodyColCount).width();
             // for the hidden field
@@ -265,25 +265,25 @@ Tobago.Sheet.setup2 = function (sheets) {
             usedWidth += newWidth;
 
             var oldWidth = bodyCols.eq(headerBodyColCount).width();
-            if (oldWidth != newWidth) {
+            if (oldWidth !== newWidth) {
               // set to the body
               bodyCols.eq(headerBodyColCount).attr("width", newWidth);
               // reset the width inside of the cells (TD) if the value was changed.
-              var tds = jQuery("td:nth-child(" + (headerBodyColCount + 1) + ")", bodyTable);
-              if (tds.size() > 0) {
-                var innerWidth = tds.children().eq(0).width() - oldWidthList[headerBodyColCount] + newWidth;
+              var $tds = jQuery("td:nth-child(" + (headerBodyColCount + 1) + ")", bodyTable);
+              if ($tds.length > 0) {
+                var innerWidth = $tds.children().eq(0).width() - oldWidthList[headerBodyColCount] + newWidth;
                 // setting all sizes of the inner cells to the same value
-                tds.children().width(innerWidth);
+                $tds.children().width(innerWidth);
                 // XXX later, if we have box-sizing: border-box we can set the width to 100%
               }
             }
             headerBodyColCount++;
-          } else if (hiddenWidths != undefined && hiddenWidths.length >= i) {
+          } else if (hiddenWidths !== undefined && hiddenWidths.length >= i) {
             widths[i] = hiddenWidths[i];
           } else {
-            if (typeof tokens[i] == "number") {
+            if (typeof tokens[i] === "number") {
               widths[i] = 100;
-            } else if (typeof tokens[i] == "object" && tokens[i].measure != undefined) {
+            } else if (typeof tokens[i] === "object" && tokens[i].measure !== undefined) {
               var intValue = parseInt(tokens[i].measure);
               if (tokens[i].measure.lastIndexOf("px") > 0) {
                 widths[i] = intValue;
@@ -323,7 +323,7 @@ Tobago.Sheet.setup2 = function (sheets) {
     var sheet = jQuery(this);
     var hidden = Tobago.Sheet.findHiddenScrollPosition(sheet);
     var sep = hidden.val().indexOf(";");
-    if (sep != -1) {
+    if (sep !== -1) {
       var scrollLeft = hidden.val().substr(0, sep);
       var scrollTop = hidden.val().substr(sep + 1);
       var body = sheet.children(".tobago-sheet-body");
@@ -337,7 +337,7 @@ Tobago.Sheet.setup2 = function (sheets) {
   jQuery(sheets).each(function () {
     var sheet = jQuery(this);
     var selectionMode = sheet.data("tobago-selection-mode");
-    if (selectionMode == "single" || selectionMode == "singleOrNone" || selectionMode == "multi") {
+    if (selectionMode === "single" || selectionMode === "singleOrNone" || selectionMode === "multi") {
       Tobago.Sheet.getRows(sheet).each(function () {
         var row = jQuery(this);
         row.bind("mousedown", function (event) {
@@ -364,20 +364,20 @@ Tobago.Sheet.setup2 = function (sheets) {
 
             var selectionMode = $sheet.data("tobago-selection-mode");
 
-            if ((!event.ctrlKey && !event.metaKey && $selector.size() == 0)
-                || selectionMode == "single" || selectionMode == "singleOrNone") {
+            if ((!event.ctrlKey && !event.metaKey && $selector.length === 0)
+                || selectionMode === "single" || selectionMode === "singleOrNone") {
               Tobago.Sheet.deselectAll($sheet);
               Tobago.Sheet.resetSelected($sheet);
             }
 
             var lastClickedRowIndex = $sheet.data("tobago-last-clicked-row-index");
-            if (event.shiftKey && selectionMode == "multi" && lastClickedRowIndex > -1) {
+            if (event.shiftKey && selectionMode === "multi" && lastClickedRowIndex > -1) {
               if (lastClickedRowIndex <= $row.index()) {
                 Tobago.Sheet.selectRange($sheet, $rows, lastClickedRowIndex, $row.index(), true, false);
               } else {
                 Tobago.Sheet.selectRange($sheet, $rows, $row.index(), lastClickedRowIndex, true, false);
               }
-            } else if (selectionMode != "singleOrNone" || !Tobago.Sheet.isRowSelected($sheet, $row)) {
+            } else if (selectionMode !== "singleOrNone" || !Tobago.Sheet.isRowSelected($sheet, $row)) {
               Tobago.Sheet.toggleSelection($sheet, $row, $selector);
             }
             var commands = sheet.data("tobago-row-action");
@@ -443,7 +443,7 @@ Tobago.Sheet.setup2 = function (sheets) {
         .blur(function () {
           Tobago.Sheet.hideInputOrSubmit(jQuery(this));
         }).keydown(function (event) {
-          if (event.keyCode == 13) {
+          if (event.keyCode === 13) {
             event.stopPropagation();
             event.preventDefault();
             jQuery(this).blur();
@@ -454,7 +454,7 @@ Tobago.Sheet.setup2 = function (sheets) {
 
 Tobago.Sheet.hideInputOrSubmit = function(input) {
   var output = input.siblings(".tobago-sheet-pagingOutput");
-  var changed = output.html() != input.val();
+  var changed = output.html() !== input.val();
   var sheetId = input.parents(".tobago-sheet:first").attr("id");
   output.html(input.val());
   if (changed) {
@@ -508,7 +508,7 @@ Tobago.Sheet.prototype.setup = function() {
 Tobago.Sheet.prototype.initReload = function() {
   var sheet = jQuery(Tobago.Utils.escapeClientId(this.id));
   var reload = sheet.data("tobago-reload");
-  if (typeof reload == "number") {
+  if (typeof reload === "number") {
     Tobago.addReloadTimeout(this.id, Tobago.bind2(this, "reloadWithAction", null, this.id), reload);
   }
 };
@@ -603,21 +603,21 @@ Tobago.Sheet.toggleSelection = function($sheet, $row, $checkbox) {
 
 Tobago.Sheet.selectAll = function($sheet) {
   var $rows = Tobago.Sheet.getRows($sheet);
-  Tobago.Sheet.selectRange($sheet, $rows, 0, $rows.size() - 1, true, false);
+  Tobago.Sheet.selectRange($sheet, $rows, 0, $rows.length - 1, true, false);
 };
 
 Tobago.Sheet.deselectAll = function($sheet) {
   var $rows = Tobago.Sheet.getRows($sheet);
-  Tobago.Sheet.selectRange($sheet, $rows, 0, $rows.size() - 1, false, true);
+  Tobago.Sheet.selectRange($sheet, $rows, 0, $rows.length - 1, false, true);
 };
 
 Tobago.Sheet.toggleAll = function(sheet) {
   var rows = Tobago.Sheet.getRows(sheet);
-  Tobago.Sheet.selectRange(sheet, rows, 0, rows.size() - 1, true, true);
+  Tobago.Sheet.selectRange(sheet, rows, 0, rows.length - 1, true, true);
 };
 
 Tobago.Sheet.selectRange = function($sheet, $rows, first, last, selectDeselected, deselectSelected) {
-  if ($rows.size() == 0) {
+  if ($rows.length === 0) {
     return;
   }
   var selected = Tobago.Sheet.findHiddenSelected($sheet);
diff --git a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago-tree.js b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago-tree.js
index d76966e..ddad1c1 100644
--- a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago-tree.js
+++ b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago-tree.js
@@ -132,7 +132,7 @@ Tobago.Tree.init = function(elements) {
   Tobago.Utils.selectWithJQuery(elements, ".tobago-treeMenuNode-markup-folder .tobago-treeMenuNode-toggle")
       .parent().each(function() {
     // if there is no command, than the whole node element should be the toggle
-    var toggle = jQuery(this).children(".tobago-treeMenuCommand").size() == 0
+    var toggle = jQuery(this).children(".tobago-treeMenuCommand").length === 0
         ? jQuery(this)
         : jQuery(this).find(".tobago-treeMenuNode-toggle");
     toggle.click(function(event) {
@@ -163,7 +163,7 @@ Tobago.Tree.init = function(elements) {
     var data = select.closest(".tobago-treeMenu, .tobago-tree, .tobago-sheet");
     var hidden = data.children(".tobago-treeMenu-selected, .tobago-tree-selected, .tobago-sheet-selected");
     var newValue;
-    if (select.attr("type") == "radio") {
+    if (select.attr("type") === "radio") {
       newValue = "," + Tobago.Tree.rowIndex(select) + ",";
     } else if (selected) {
       newValue = hidden.val() + Tobago.Tree.rowIndex(select) + ",";
@@ -245,7 +245,7 @@ Tobago.Tree.findChildren = function (node) {
 };
 
 Tobago.Tree.isInSheet = function(node) {
-  return node.parent("td").size() == 1;
+  return node.parent("td").length === 1;
 };
 
 Tobago.registerListener(Tobago.Tree.init, Tobago.Phase.DOCUMENT_READY);
diff --git a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago.js b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago.js
index bb82068..6f6ee4f 100644
--- a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago.js
+++ b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/script/tobago.js
@@ -658,13 +658,13 @@ var Tobago = {
 
     var $hasDanger = Tobago.Utils.selectWithJQuery(elements, '.has-danger');
     var $dangerInput = $hasDanger.find("*").filter(":input:enabled:visible:first");
-    if ($dangerInput.size() > 0) {
+    if ($dangerInput.length > 0) {
       Tobago.setFocus($dangerInput);
       return;
     }
 
     var $autoFocus = Tobago.Utils.selectWithJQuery(elements, '[autofocus]');
-    var hasAutoFocus = $autoFocus.size() > 0;
+    var hasAutoFocus = $autoFocus.length > 0;
     if (hasAutoFocus) {
       // nothing to do, because the browser make the work.
 
@@ -688,7 +688,7 @@ var Tobago = {
     }
 
     var $firstInput = jQuery(":input:enabled:visible:not(button):not([tabindex='-1']):first");
-    if ($firstInput.size() > 0) {
+    if ($firstInput.length > 0) {
       Tobago.setFocus($firstInput);
       return;
     }
@@ -939,7 +939,7 @@ jQuery(document).ready(function() {
   Tobago.init();
 });
 
-jQuery(window).load(function() {
+jQuery(window).on("load", function() {
   for (var order = 0; order < Tobago.listeners.windowLoad.length; order++) {
     var list = Tobago.listeners.windowLoad[order];
     for (var i = 0; i < list.length; i++) {
@@ -1145,7 +1145,7 @@ Tobago.Command.initEnter = function(elements) {
       var id = target.name ? target.name : target.id;
       while (id != null) {
         var command = jQuery("[data-tobago-default='" + id + "']");
-        if (command.size() > 0) {
+        if (command.length > 0) {
           command.click();
           break;
         }
@@ -1190,27 +1190,27 @@ Tobago.SelectManyShuttle.init = function(elements) {
   });
 };
 
-Tobago.SelectManyShuttle.moveSelectedItems = function(shuttle, direction, all) {
-  var unselected = shuttle.find(".tobago-selectManyShuttle-unselected");
-  var selected = shuttle.find(".tobago-selectManyShuttle-selected");
-  var count = selected.children().size();
-  var source = direction ? unselected : selected;
-  var target = direction ? selected : unselected;
-  var shifted = source.find(all ? "option:not(:disabled)" : "option:selected").remove().appendTo(target);
+Tobago.SelectManyShuttle.moveSelectedItems = function($shuttle, direction, all) {
+  var $unselected = $shuttle.find(".tobago-selectManyShuttle-unselected");
+  var $selected = $shuttle.find(".tobago-selectManyShuttle-selected");
+  var count = $selected.children().length;
+  var $source = direction ? $unselected : $selected;
+  var $target = direction ? $selected : $unselected;
+  var $shifted = $source.find(all ? "option:not(:disabled)" : "option:selected").remove().appendTo($target);
 
   // synchronize the hidden select
-  var hidden = shuttle.find(".tobago-selectManyShuttle-hidden");
-  var hiddenOptions = hidden.find("option");
+  var $hidden = $shuttle.find(".tobago-selectManyShuttle-hidden");
+  var $hiddenOptions = $hidden.find("option");
   // todo: may be optimized: put values in a hash map?
-  shifted.each(function() {
-    var option = jQuery(this);
-    hiddenOptions.filter("[value='" + option.val() + "']").prop("selected", direction);
+  $shifted.each(function() {
+    var $option = jQuery(this);
+    $hiddenOptions.filter("[value='" + $option.val() + "']").prop("selected", direction);
   });
 
-  if (count != selected.children().size()) {
+  if (count !== $selected.children().length) {
     var e = jQuery.Event("change");
     // trigger an change event for command facets
-    hidden.trigger( e );
+    $hidden.trigger( e );
   }
 };
 

-- 
To stop receiving notification emails like this one, please contact
lofwyr@apache.org.