From ac4dd51ed727c861059df85b7b1da709a0794939 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 29 Dec 2011 15:40:08 +0530 Subject: [PATCH] Only return Ox.Element if exactly one jquery element is return. Fixes use of find, children --- source/Ox.UI/js/Calendar/Ox.Calendar.js | 2 +- source/Ox.UI/js/Core/Ox.JQueryElement.js | 9 +++++---- source/Ox.UI/js/List/Ox.List.js | 2 +- source/Ox.UI/js/List/Ox.TextList.js | 10 +++++----- source/Ox.UI/js/List/Ox.TreeList.js | 5 +---- source/Ox.UI/js/Video/Ox.VideoPlayer.js | 2 +- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/source/Ox.UI/js/Calendar/Ox.Calendar.js b/source/Ox.UI/js/Calendar/Ox.Calendar.js index cdad273e..56e76ce3 100644 --- a/source/Ox.UI/js/Calendar/Ox.Calendar.js +++ b/source/Ox.UI/js/Calendar/Ox.Calendar.js @@ -1124,7 +1124,7 @@ Ox.Calendar = function(options, self) { } function setEventControls(event) { - var $eventControls = that.$element.find('.OxEventControl'), + var $eventControls = that.find('.OxEventControl'), isVisible = self.$eventControls.name.is(':visible'); if (event) { self.$eventControls.name.options({title: event.name}); diff --git a/source/Ox.UI/js/Core/Ox.JQueryElement.js b/source/Ox.UI/js/Core/Ox.JQueryElement.js index b1dd2c38..652af550 100644 --- a/source/Ox.UI/js/Core/Ox.JQueryElement.js +++ b/source/Ox.UI/js/Core/Ox.JQueryElement.js @@ -10,8 +10,7 @@ Ox.JQueryElement Wrapper for jQuery $element jQuery DOM Element @*/ -// fixme: it seems that children(), find() etc. don't work directly, -// and still have to be called on the $element +// fixme: now that children(), find() work, change code to call find directly. Ox.JQueryElement = function($element) { var that = this; @@ -48,10 +47,12 @@ Ox.forEach($('
'), function(val, key) { } }); ret = that.$element[key].apply(that.$element, args); - // if the $element of an ox object was returned + // if exactly one $element of an ox object was returned // then return the ox object instead // so that we can do oxObj.jqFn().oxFn() - return ret && ret.jquery && Ox.UI.elements[id = ret.data('oxid')] + return ret && ret.jquery + && ret.length == 1 + && Ox.UI.elements[id = ret.data('oxid')] ? Ox.UI.elements[id] : ret; }; } diff --git a/source/Ox.UI/js/List/Ox.List.js b/source/Ox.UI/js/List/Ox.List.js index 1b2dbcc5..bfc02c4f 100644 --- a/source/Ox.UI/js/List/Ox.List.js +++ b/source/Ox.UI/js/List/Ox.List.js @@ -426,7 +426,7 @@ Ox.List = function(options, self) { function emptyFirstPage() { if (self.$pages[0]) { if (self.options.type == 'text') { - self.$pages[0].$element.find('.OxEmpty').remove(); + self.$pages[0].find('.OxEmpty').remove(); } else if (self.options.orientation == 'both') { that.$content.css({height: getListSize() + 'px'}); } diff --git a/source/Ox.UI/js/List/Ox.TextList.js b/source/Ox.UI/js/List/Ox.TextList.js index d1e3829b..eedb0f0f 100644 --- a/source/Ox.UI/js/List/Ox.TextList.js +++ b/source/Ox.UI/js/List/Ox.TextList.js @@ -615,7 +615,7 @@ Ox.TextList = function(options, self) { function getItem(id) { //Ox.Log('List', 'getItem', id) var $item = null; - that.$element.find('.OxItem').each(function() { + that.find('.OxItem').each(function() { var $this = $(this); if ($this.data('id') == id) { $item = $this; @@ -658,7 +658,7 @@ Ox.TextList = function(options, self) { ? $('.OxHeadCell' + stopSelector).next() : $('.OxHeadCell' + stopSelector)); $resize.detach().insertAfter($column); - that.$body.$element.find('.OxItem').each(function() { + that.$body.find('.OxItem').each(function() { var $this = $(this); $this.children(startSelector).detach()[insert]( $this.children(stopSelector) @@ -672,7 +672,7 @@ Ox.TextList = function(options, self) { self.visibleColumns.splice(stopPos, 0, visibleColumn); var pos = getColumnPositionById(self.options.columns[self.selectedColumn].id); if (pos > -1) { - that.$element.find('.OxResize .OxSelected').removeClass('OxSelected'); + that.find('.OxResize .OxSelected').removeClass('OxSelected'); pos > 0 && self.$heads[pos].prev().children().eq(2).addClass('OxSelected'); self.$heads[pos].next().children().eq(0).addClass('OxSelected'); if (pos == stopPos) { @@ -697,7 +697,7 @@ Ox.TextList = function(options, self) { that.$head.$content.empty(); constructHead(); itemWidth = getItemWidth(); - that.$body.$element.find('.OxItem').each(function() { + that.$body.find('.OxItem').each(function() { var $this = $(this); $this.children(selector).remove(); $this.css({width: itemWidth + 'px'}); @@ -738,7 +738,7 @@ Ox.TextList = function(options, self) { width: width - 9 - (i == self.selectedColumn ? 16 : 0) + 'px' }); } - that.$element.find('.OxCell.OxColumn' + Ox.toTitleCase(self.options.columns[i].id)).css({ + that.find('.OxCell.OxColumn' + Ox.toTitleCase(self.options.columns[i].id)).css({ width: width - (self.options.columnsVisible ? 9 : 8) + 'px' }); setWidth(); diff --git a/source/Ox.UI/js/List/Ox.TreeList.js b/source/Ox.UI/js/List/Ox.TreeList.js index df272804..05b867a1 100644 --- a/source/Ox.UI/js/List/Ox.TreeList.js +++ b/source/Ox.UI/js/List/Ox.TreeList.js @@ -181,10 +181,7 @@ Ox.TreeList = function(options, self) { function toggleItem(item, expanded) { var $img, pos; item.expanded = expanded; - //fixme why does - //that.$element.find('.OxItem').each(function() { - //only return one element? - $(that.$element).find('.OxItem').each(function() { + that.find('.OxItem').each(function() { var $item = $(this); if ($item.data('id') == item.id) { $img = $item.find('.OxToggle'); diff --git a/source/Ox.UI/js/Video/Ox.VideoPlayer.js b/source/Ox.UI/js/Video/Ox.VideoPlayer.js index 12e0ac15..05f496de 100644 --- a/source/Ox.UI/js/Video/Ox.VideoPlayer.js +++ b/source/Ox.UI/js/Video/Ox.VideoPlayer.js @@ -1131,7 +1131,7 @@ Ox.VideoPlayer = function(options, self) { }); showControls(); hideControls(); - that.$element.find('.OxControls').bind({ + that.find('.OxControls').bind({ mouseenter: function() { self.mouseIsInControls = true; },