diff --git a/demo/AnyPicker-DateTimeDecimal.htm b/demo/AnyPicker-DateTimeDecimal.htm new file mode 100644 index 0000000..8ba8cc9 --- /dev/null +++ b/demo/AnyPicker-DateTimeDecimal.htm @@ -0,0 +1,205 @@ + + + + + + + Decimal - AnyPicker + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Start Date :
+ +
End Date :
+ +
Setpoint :
+ +
+ + + + diff --git a/src/anypicker-include-decimal b/src/anypicker-include-decimal new file mode 100644 index 0000000..ec57fd2 --- /dev/null +++ b/src/anypicker-include-decimal @@ -0,0 +1,6729 @@ +/* ----------------------------------------------------------------------------- + + AnyPicker - Customizable Picker for Mobile OS + Version 2.0.9 + Copyright (c)2017 Lajpat Shah + Contributors : https://github.com/nehakadam/AnyPicker/contributors + Repository : https://github.com/nehakadam/AnyPicker + Homepage : https://nehakadam.github.io/AnyPicker + + ----------------------------------------------------------------------------- */ + +(function () { + + "use strict"; + +// --------------------------------- Global Variables : AnyPicker.Core Start -------------------------------------- + +//"use strict"; + +$.CF = { + + setPropertiesStyle: function(sProp, sArrProps) + { + var oTest = window.getComputedStyle(document.documentElement, ''); + for(var iProp in sArrProps) + { + if(oTest[sArrProps[iProp]] !== undefined) + { + var sPrefix = ""; + + if(sArrProps[iProp].search("Webkit") !== -1) + sPrefix = "-webkit-"; + else if(sArrProps[iProp].search("Moz") !== -1) + sPrefix = "-moz-"; + else if(sArrProps[iProp].search("O") !== -1) + sPrefix = "-o-"; + else if(sArrProps[iProp].search("ms") !== -1) + sPrefix = "-ms-"; + + return sPrefix + sProp; + } + } + }, + + testProperties: function(sProp, sArrProps, bReturnProp) + { + var oTest = window.getComputedStyle(document.documentElement, ''); + for(var iProp in sArrProps) + { + if(oTest[sArrProps[iProp]] !== undefined) + { + if(bReturnProp) + { + return sArrProps[iProp]; + } + else + return true; + } + } + if(bReturnProp) + return ""; + else + return false; + }, + + compareDataType: function(oVariable, sDataType) + { + if(typeof oVariable === sDataType.toLocaleLowerCase()) + return true; + return false; + }, + + compareStrings: function(sString1, sString2) + { + var to = this; + if(sString1 !== null && sString1 !== undefined && sString2 !== null && sString2 !== undefined) + { + if(typeof sString1 === "string" && typeof sString2 === "string") + { + if(sString1.toLocaleLowerCase() === sString2.toLocaleLowerCase()) + return true; + } + return false; + } + else + { + if((sString1 === null && sString2 === null) || (sString1 === undefined && sString2 === undefined)) + return true; + else + return false; + } + }, + + isValid: function(oValue) + { + if(oValue !== undefined && oValue !== null && oValue !== "") + return true; + else + return false; + } + +}; + +$.AnyPicker = $.AnyPicker || { + + name: "AnyPicker", // Plugin Name + + version: "2.0.3", // Plugin Version + + i18n: // Internationalization Strings + { + + }, + + defaults: // Defaults Settings + { + mode: "datetime", + + parent: "body", + layout: "popup", + hAlign: "left", + vAlign: "bottom", + relativeTo: null, + inputElement: null, + inputChangeEvent: "onSet", + + lang: "", + rtl: false, + animationDuration: 500, + + // View Section Components Start + + setButton: + { + markup: "Set", + markupContentWindows: "set", + type: "Button" + // action: function(){} + }, + + clearButton: + { + markup: "Clear", + markupContentWindows: "clear", + type: "Button" + // action: function(){} + }, + + nowButton: + { + markup: "Now", + markupContentWindows: "now", + type: "Button" + // action: function(){} + }, + + cancelButton: + { + markup: "Cancel", + markupContentWindows: "cancel", + type: "Button" + // action: function(){} + }, + + headerTitle: + { + markup: "Select", + type: "Text", + contentBehaviour: "Static", // Static or Dynamic + format: "" // DateTime Format + }, + + // View Section Components End + + viewSections: + { + header: ["headerTitle"], + contentTop: [], + contentBottom: [], + footer: ["cancelButton", "setButton"] + }, + + i18n: + { + headerTitle: "Select", + setButton: "Set", + clearButton: "Clear", + nowButton: "Now", + cancelButton: "Cancel", + dateSwitch: "Date", + timeSwitch: "Time" + }, + + theme: "Default", + + //------------------ Callback Functions Start -------------------------- + + onInit: null, // () + + onBeforeShowPicker: null, // () + onShowPicker: null, // () + + onBeforeHidePicker: null, // () + onHidePicker: null, // () + + parseInput: null, // () + formatOutput: null, // () + + setOutput: null, + onSetOutput: null, + + buttonClicked: null + + //------------------ Callback Functions End -------------------------- + }, + + tempDefaults: // Plugin-level Variables required to maintain state across methods + { + sOrientation: "portrait", + overlayClass: "", + overlaySelector: "", + iExt: 2, + dir: "ltr", + sElemTag: "", + oElemValid: { + bIsInput: false, + bIsListItem: false, + bIsSelect: false + }, + sInputElemTag: "", + oInputElemValid: { + bIsInput: false, + bIsListItem: false, + bIsSelect: false + }, + prevActive: null, + bFirst: true, + sDateTimeTab: "date", + iCompDragStart: 0, + headerTitleDefined: false, + bIsiPad: false, + bModified: { + set: false, + cancel: false, + clear: false, + now: false + }, + tabKey: false + }, + + extra: // Common Temporary Variables + { + sArrModes: ["select", "datetime", "decimal"], // Modes of AnyPicker + sArrLayout: ["popup", "relative", "fixed", "inline"], // Type of AnyPicker Layout + sArrHAlign: ["left", "center", "right"], // Horizontal Alignment of View + sArrVAlign: ["top", "middle", "bottom"], // Vertical Alignment of View + sArrViewSections: ["header", "contentTop", "contentBottom", "footer"], + oArrInputChangeEvent: ["onChange", "onSet"], + sArrThemes: ["Default", "iOS", "Android", "Windows"], + + bIsTouchDevice: "ontouchstart" in document.documentElement, + sClickHandler: ("ontouchstart" in document.documentElement ? "click" : "click"), + sClickHandlerButtons: ("ontouchstart" in document.documentElement ? "touchstart" : "click"), + + bHasCSS3D : $.CF.testProperties("perspective", ["WebkitPerspective", "MozPerspective", "OPerspective", "msPerspective", "perspective", "perspectiveProperty"], false), + sCSSTransform: $.CF.testProperties("transform", ["WebkitTransform", "MozTransform", "OTransform", "msTransform", "transform"], true), + sCSSTransformStyle: $.CF.setPropertiesStyle("transform", ["WebkitTransform", "MozTransform", "OTransform", "msTransform", "transform"]), + sCSSTransition: $.CF.testProperties("transition", ["WebkitTransition", "MozTransition", "OTransition", "msTransition", "transition"], true), + bHasCSSAnimation: $.CF.testProperties("animation", ["WebkitAnimation", "MozAnimation", "OAnimation", "msAnimation", "animation"], false), + sMouseWheel: ('onwheel' in document || document.documentMode >= 9 ) ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'], //"MozMousePixelScroll DOMMouseScroll mousewheel wheel" + bHasIE10Pointer: window.navigator.msPointerEnabled && !window.navigator.pointerEnabled, + bHasPointer: window.navigator.pointerEnabled || window.navigator.msPointerEnabled, + bIsiPad: navigator.userAgent.match(/iPad/i) !== null + } + +}; + +// --------------------------------- Global Variables : AnyPicker.Core End -------------------------------------- + +(function (factory) +{ + if (typeof define === 'function' && define.amd) // AMD. Register as an anonymous module. + { + define(['jquery'], factory); + } + else if (typeof exports === 'object') // Node/CommonJS + { + module.exports = factory(require('jquery')); + } + else // Browser globals + { + factory(jQuery); + } +} +(function ($) +{ + $.fn.AnyPicker = function(options) + { + var oAnyPicker = $(this).data(); + + var sArrDataKeys = Object.keys(oAnyPicker), + iKey, sKey; + if(options === null || options === undefined) // return AnyPicker object + { + if(sArrDataKeys.length > 0) + { + for(iKey in sArrDataKeys) + { + sKey = sArrDataKeys[iKey]; + if(sKey.search("plugin_AnyPicker_") !== -1) + { + return oAnyPicker[sKey]; + } + } + } + else + console.log("No AnyPicker Object Defined For This Element"); + } + else if(typeof options === "string") // call methods using AnyPicker object + { + if(oAnyPicker !== null || oAnyPicker !== undefined) + { + if(sArrDataKeys.length > 0) + { + if(options === "destroy") + { + if(sArrDataKeys.length > 0) + { + for(iKey in sArrDataKeys) + { + sKey = sArrDataKeys[iKey]; + if(sKey.search("plugin_AnyPicker_") !== -1) + { + oAnyPicker = oAnyPicker[sKey]; + $(window).off("blur." + oAnyPicker.setting.timestamp); + var oInput = $(oAnyPicker.setting.inputElement); + $(oInput).off("focus." + oAnyPicker.setting.timestamp); + $(oInput).off("blur." + oAnyPicker.setting.timestamp); + + $(".ap-overlay-" + sKey.replace("plugin_AnyPicker_", "")).remove(); // Remove AnyPicker DOM appended for a particular AnyPicker object + $(this).removeData(sKey); + + //console.log("Destroyed AnyPicker Object"); + //console.log(oAnyPicker); + + break; + } + } + } + else + console.log("No AnyPicker Object Defined For This Element"); + + // ** Destoy AnyPicker Object ** + // unbind events + // remove data attached to Element + // remove AnyPicker Object from the $.AnyPicker.extra.oArrAnyPicker + } + } + else + console.log("No AnyPicker Object Defined For This Element"); + } + } + else // create a new AnyPicker object + { + return this.each(function() + { + var iTimeStamp = (new Date()).getTime(); + if(!$.data(this, "plugin_AnyPicker_" + iTimeStamp)) + { + options.timestamp = iTimeStamp; + oAnyPicker = new AnyPicker(this, options); + $.data(this, "plugin_AnyPicker_" + iTimeStamp, oAnyPicker); + oAnyPicker.init(); + + //console.log("Created AnyPicker Object "); + //console.log(oAnyPicker); + } + else + { + if(sArrDataKeys.length > 0) + { + for(iKey in sArrDataKeys) + { + sKey = sArrDataKeys[iKey]; + if(sKey.search("plugin_AnyPicker_") !== -1) + { + return oAnyPicker[sKey]; + } + } + } + else + console.log("No AnyPicker Object Defined For This Element"); + } + }); + } + }; +})); + +// AnyPicker Constructor +function AnyPicker(element, options) +{ + var apo = this; + + apo.elem = element; + var sLang = (options.lang !== undefined || options.lang !== null) ? options.lang : $.CalenStyle.defaults.lang, + io18n = $.extend(true, {}, $.AnyPicker.defaults.i18n, $.AnyPicker.i18n[sLang], options.i18n), + oDefaults = $.extend(true, {}, $.AnyPicker.defaults); + + io18n = { + i18n: io18n + }; + oDefaults.i18n = {}; + options.i18n = {}; + + apo.setting = $.extend({}, oDefaults, options, io18n); + apo.tmp = $.extend({}, $.AnyPicker.tempDefaults); + + apo.tmp.overlayClass = "ap-overlay-" + apo.setting.timestamp; + apo.tmp.overlaySelector = "." + apo.tmp.overlayClass; + apo.tmp.sOrientation = apo._getDeviceOrientation(); + + //----------- Theme-wise Changes In Settings ------------------- + + if($.CF.isValid(options.headerTitle)) + apo.tmp.headerTitleDefined = true; + + if($.CF.compareStrings(apo.setting.theme, "Android")) + { + if(!$.CF.isValid(options.rowHeight)) + apo.setting.rowHeight = 50; + + if(!$.CF.isValid(options.visibleRows)) + apo.setting.visibleRows = 3; + } + else if($.CF.compareStrings(apo.setting.theme, "iOS")) + { + if(!$.CF.isValid(options.rowHeight)) + apo.setting.rowHeight = 36; + + if(!$.CF.isValid(options.visibleRows)) + apo.setting.visibleRows = 5; + + if(!$.CF.isValid(options.viewSections)) + { + if($.CF.compareStrings(apo.setting.layout, "fixed")) + { + apo.setting.viewSections = { + header: [], + contentTop: [], + contentBottom: [], + footer: ["cancelButton", "headerTitle", "setButton"] + }; + } + else + { + apo.setting.viewSections = { + header: ["cancelButton", "headerTitle", "setButton"], + contentTop: [], + contentBottom: [], + footer: [] + }; + } + } + + if($.AnyPicker.extra.bIsiPad) + apo.tmp.bIsiPad = true; + if(apo.tmp.bIsiPad && $.CF.compareStrings(apo.setting.layout, "popup")) + apo.setting.layout = "popover"; + } + else if($.CF.compareStrings(apo.setting.theme, "Windows")) + { + apo.setting.layout = "popup"; + apo.setting.visibleRows = 5; + apo.setting.rowHeight = 100; + + if(!$.CF.isValid(options.viewSections)) + { + apo.setting.viewSections = { + header: ["headerTitle"], + contentTop: [], + contentBottom: [], + footer: ["setButton", "cancelButton"] + }; + } + + if($.CF.isValid(options.setButton)) + apo.tmp.bModified.set = true; + if($.CF.isValid(options.cancelButton)) + apo.tmp.bModified.cancel = true; + if($.CF.isValid(options.nowButton)) + apo.tmp.bModified.now = true; + if($.CF.isValid(options.clearButton)) + apo.tmp.bModified.clear = true; + } + + //-------------------------------------------------------------- + + apo.tmp.iExt = Math.floor(apo.setting.visibleRows / 2); + apo.tmp.sDir = apo.setting.rtl ? "rtl" : "ltr"; + + $.AnyPicker.extra.dToday = apo._getCurrentDate(); + if(apo.tmp.selectedDate === null) + apo.tmp.selectedDate = $.AnyPicker.extra.dToday; + if(apo.setting.maxYear === 0) + apo.setting.maxYear = $.AnyPicker.extra.dToday.getFullYear(); + if($.CF.isValid(apo.setting.components) && apo.tmp.numOfComp === 0) + apo.tmp.numOfComp = apo.setting.components.length; + + $.AnyPicker.extra.sStartEv = ($.AnyPicker.extra.bHasPointer ? ($.AnyPicker.extra.bHasIE10Pointer ? 'MSPointerDown' : 'pointerdown') : ($.AnyPicker.extra.bIsTouchDevice ? 'touchstart' : 'mousedown touchstart')); + $.AnyPicker.extra.sMoveEv = ($.AnyPicker.extra.bHasPointer ? ($.AnyPicker.extra.bHasIE10Pointer ? 'MSPointerMove' : 'pointermove') : ($.AnyPicker.extra.bIsTouchDevice ? 'touchmove' : 'mousemove touchmove')); + $.AnyPicker.extra.sEndEv = ($.AnyPicker.extra.bHasPointer ? ($.AnyPicker.extra.bHasIE10Pointer ? 'MSPointerUp' : 'pointerup') : ($.AnyPicker.extra.bIsTouchDevice ? 'touchend' : 'mouseup touchend')); + $.AnyPicker.extra.sLeaveEv = ($.AnyPicker.extra.bHasPointer ? ($.AnyPicker.extra.bHasIE10Pointer ? 'MSPointerLeave' : 'pointerleave') : ($.AnyPicker.extra.bIsTouchDevice ? null : 'mouseleave')); + $.AnyPicker.extra.sCancelEv = ($.AnyPicker.extra.bHasPointer ? ($.AnyPicker.extra.bHasIE10Pointer ? 'MSPointerCancel' : 'pointercancel') : null); + $.AnyPicker.extra.sOutEv = ($.AnyPicker.extra.bHasPointer ? ($.AnyPicker.extra.bHasIE10Pointer ? 'MSPointerOut' : 'pointerout') : null); + + //alert("Events : " + $.AnyPicker.extra.sStartEv + " " + $.AnyPicker.extra.sMoveEv + " " + $.AnyPicker.extra.sEndEv + " " + $.AnyPicker.extra.sLeaveEv + " " + $.AnyPicker.extra.sCancelEv + " " + $.AnyPicker.extra.sOutEv); +} + +// --------------------------------- Functions : AnyPicker.Core Start -------------------------------------- + +AnyPicker.prototype = { + + // Public Method + init: function() + { + var apo = this; + + if($.CF.isValid(apo.elem)) + { + apo.tmp.sElemTag = $(apo.elem).prop("tagName").toLowerCase() ; + if(apo.tmp.sElemTag === "input") + apo.tmp.oElemValid.bIsInput = true; + else if(apo.tmp.sElemTag === "ul" || apo.tmp.sElemTag === "ol" || apo.tmp.sElemTag === "dl") + apo.tmp.oElemValid.bIsListItem = true; + else if(apo.tmp.sElemTag === "select") + apo.tmp.oElemValid.bIsSelect = true; + } + + if($.CF.isValid(apo.setting.inputElement)) + { + apo.tmp.sInputElemTag = $(apo.setting.inputElement).prop("tagName").toLowerCase(); + if(apo.tmp.sInputElemTag === "input") + apo.tmp.oInputElemValid.bIsInput = true; + else if(apo.tmp.sInputElemTag === "ul" || apo.tmp.sInputElemTag === "ol" || apo.tmp.sInputElemTag === "dl") + apo.tmp.oInputElemValid.bIsListItem = true; + else if(apo.tmp.sInputElemTag === "select") + apo.tmp.oInputElemValid.bIsSelect = true; + } + else if($.CF.isValid(apo.elem)) + { + apo.setting.inputElement = apo.elem; + apo.tmp.sInputElemTag = apo.tmp.sElemTag; + apo.tmp.oInputElemValid = apo.tmp.oElemValid; + } + + if($.CF.compareStrings(apo.setting.mode, "select")) + { + apo.__setComponentsOfSelect(); + } + else if($.CF.compareStrings(apo.setting.mode, "datetime")) + { + apo.__setComponentsOfDateTimePicker(); + } + else if($.CF.compareStrings(apo.setting.mode, "decimal")) + { + apo.__setComponentsOfDecimalPicker(); + } + + if(apo.tmp.sInputElemTag !== "" && !(apo.tmp.oInputElemValid.bIsListItem || apo.tmp.oInputElemValid.bIsSelect)) + { + var $oInput = $(apo.setting.inputElement); + if(apo.tmp.oInputElemValid.bIsInput) + { + $oInput.off("focus." + apo.setting.timestamp); + $oInput.on("focus." + apo.setting.timestamp, {"apo": apo}, apo._inputElementClicked); + $oInput.on("blur." + apo.setting.timestamp, function(e) + { + if($.AnyPicker.tempDefaults.tabKey) + apo.showOrHidePicker(); + apo.tmp.prevActive = null; + }); + + $oInput.on("keydown." + apo.setting.timestamp, function(e) + { + if((e.keyCode ? e.keyCode : e.which) === "9") + $.AnyPicker.tempDefaults.tabKey = true; + }); + } + else + { + $oInput.off("click." + apo.setting.timestamp); + $oInput.on("click." + apo.setting.timestamp, {"apo": apo}, apo._inputElementClicked); + } + } + + if($.CF.isValid(apo.setting.onInit)) + { + apo.setting.onInit.call(apo); + } + //console.log("END"); //mc + }, + + _inputElementClicked: function(e) + { + e.stopPropagation(); + e.preventDefault(); + + var apo = e.data.apo; + + if(document.activeElement === apo.tmp.prevActive && document.activeElement === apo.setting.inputElement) + return; + apo.tmp.prevActive = document.activeElement; + + // Get Selected Values (Value in the text field or Value set in the inputElement) + if(apo.tmp.sInputElemTag !== "" && !(apo.tmp.oInputElemValid.bIsListItem || apo.tmp.oInputElemValid.bIsSelect)) + { + var $oInput = $(apo.setting.inputElement), sElemValue; + + if(apo.tmp.oInputElemValid.bIsInput) + sElemValue = $oInput.val(); + else + { + var sDataVal = $oInput.attr("data-val"); + if($.CF.isValid(sDataVal)) + sElemValue = sDataVal; + else + sElemValue = $oInput.text(); + } + + if(!$.AnyPicker.tempDefaults.tabKey) + { + apo.showOrHidePicker(sElemValue); + } + else + { + $.AnyPicker.tempDefaults.tabKey = false; + setTimeout(function() + { + apo.showOrHidePicker(sElemValue); + }, 500); + } + } + else + console.log("No InputElement Specified"); + }, + + // Public Method + showOrHidePicker: function(sElemValue) + { + var apo = this; + + var iTempIndex, sLabel, sValue, + sArrValues = [], oArrSelectedValues = []; + + if(sElemValue !== undefined && sElemValue !== null) + { + if($.CF.isValid(apo.setting.parseInput)) + { + if($.CF.compareStrings(apo.setting.mode, "datetime")) + { + apo.setting.selectedDate = apo.setting.parseInput.call(apo, sElemValue); + } + else if($.CF.compareStrings(apo.setting.mode, "decimal")) + { + apo.setting.selectedDecimal = apo.setting.parseInput.call(apo, sElemValue); + } + else if($.CF.compareStrings(apo.setting.mode, "select")) + { + sArrValues = apo.setting.parseInput.call(apo, sElemValue); + + for(iTempIndex = 0; iTempIndex < sArrValues.length; iTempIndex++) + { + sLabel = sArrValues[iTempIndex]; + sValue = apo.__getDataSourceValueFromLabel(sLabel, iTempIndex, true); + oArrSelectedValues.push( + { + component: iTempIndex, + val: sValue, + label: sLabel + }); + } + apo.tmp.selectedValues.values = oArrSelectedValues; + } + } + else + { + if($.CF.compareStrings(apo.setting.mode, "datetime")) + { + apo.setting.selectedDate = sElemValue; + } + else if($.CF.compareStrings(apo.setting.mode, "decimal")) + { + apo.setting.selectedDecimal = sElemValue; + } + else if($.CF.compareStrings(apo.setting.mode, "select")) + { + if(sElemValue !== "") + { + sArrValues = []; oArrSelectedValues = []; + if(apo.tmp.numOfComp > 1) + sArrValues = sElemValue.split(" "); + else + sArrValues.push(sElemValue); + + for(iTempIndex = 0; iTempIndex < sArrValues.length; iTempIndex++) + { + sLabel = sArrValues[iTempIndex]; + sValue = apo.__getDataSourceValueFromLabel(sLabel, iTempIndex, true); + oArrSelectedValues.push( + { + component: iTempIndex, + val: sValue, + label: sLabel + }); + } + } + else + { + for(iTempIndex = 0; iTempIndex < apo.tmp.numOfComp; iTempIndex++) + { + var oCompData = apo.setting.dataSource[iTempIndex].data; + sLabel = oCompData[0].label; + sValue = oCompData[0].val; + oArrSelectedValues.push( + { + component: iTempIndex, + val: sValue, + label: sLabel + }); + } + } + + apo.tmp.selectedValues.values = oArrSelectedValues; + } + } + } + + if($(apo.tmp.overlaySelector).length > 0) + apo._hidePicker(); + else + { + if(!$.CF.isValid(apo.setting.onBeforeShowPicker)) + apo._showPicker(); + else + { + if(apo.setting.onBeforeShowPicker.call(apo)) + apo._showPicker(); + } + } + }, + + _showPicker: function() + { + var apo = this; + + // if($.CF.isValid(apo.setting.onBeforeShowPicker)) + // apo.setting.onBeforeShowPicker.call(apo); + + apo.tmp.sOrientation = apo._getDeviceOrientation(); + + var sTemp = "", + bAddSectionHeader = (($.CF.compareStrings(apo.setting.layout, "popup") || $.CF.compareStrings(apo.setting.layout, "popover")) && apo.setting.viewSections.header.length > 0), + bAddSectionFooter = (($.CF.compareStrings(apo.setting.layout, "popup") || $.CF.compareStrings(apo.setting.layout, "popover")) && apo.setting.viewSections.footer.length > 0), + bAddSectionFooterFixedTop = ($.CF.compareStrings(apo.setting.layout, "fixed") && $.CF.compareStrings(apo.setting.vAlign, "bottom") && apo.setting.viewSections.footer.length > 0), + bAddSectionFooterFixedBottom = ($.CF.compareStrings(apo.setting.layout, "fixed") && $.CF.compareStrings(apo.setting.vAlign, "top") && apo.setting.viewSections.footer.length > 0), + bIsDateTimeField = ($.CF.compareStrings(apo.setting.mode, "datetime") && apo.tmp.sDateTimeDecimalMode === "datetime"), + bIsDecimalField = ($.CF.compareStrings(apo.setting.mode, "decimal") && apo.tmp.sDateTimeDecimalMode === "decimal"), + sLayout = "ap-layout-" + apo.setting.layout, + sTheme = "ap-theme-" + apo.setting.theme.toLowerCase(), + sDir = "ap-dir-" + apo.tmp.sDir; + + if($.CF.compareStrings(apo.setting.layout, "popover")) + { + var iBodyScrollTop = $("body").scrollTop(), + iWinHeight = $(window).height(), + iMinTop = iBodyScrollTop, + iMaxTop = iBodyScrollTop + iWinHeight, + iPopupHeight = $.CF.compareStrings(apo.setting.rowsNavigation, "scroller") ? 300 : 350, + iTooltipTop = $(apo.setting.inputElement).offset().top - iPopupHeight, + bTooltipTop = (iTooltipTop < iMinTop) ? false : true, + iTooltipBottom = $(apo.setting.inputElement).offset().top + $(apo.setting.inputElement).height() + iPopupHeight, + bTooltipBottom = (iTooltipBottom > iMaxTop) ? false : true; + apo.tmp.sTooltip = bTooltipBottom ? "bottom" : bTooltipTop ? "top" : apo.setting.rtl ? "right" : "left"; + } + + sTemp += "
"; + + sTemp += "
"; + + sTemp += "
"; + + if($.CF.isValid(apo.tmp.sTooltip)) + sTemp += ""; + + if(bAddSectionHeader) + { + sTemp += "
"; + + if(bIsDateTimeField && $.CF.compareStrings(apo.setting.theme, "Windows")) + { + sTemp += "
"; + if(apo.setting.rtl) + { + sTemp += "" + apo.setting.i18n.timeSwitch + ""; + sTemp += "" + apo.setting.i18n.dateSwitch + ""; + } + else + { + sTemp += "" + apo.setting.i18n.dateSwitch + ""; + sTemp += "" + apo.setting.i18n.timeSwitch + ""; + } + sTemp += "
"; + + apo.tmp.sDateTimeTab = "time"; + } + + sTemp += "
"; + } + + if(bAddSectionFooterFixedTop) + { + sTemp += ""; + } + + sTemp += "
"; + + if(apo.setting.viewSections.contentTop.length > 0) + sTemp += "
"; + + if(bIsDateTimeField && !$.CF.compareStrings(apo.setting.theme, "Windows")) + { + sTemp += "
"; + if(apo.setting.rtl) + { + sTemp += "" + apo.setting.i18n.timeSwitch + ""; + sTemp += "" + apo.setting.i18n.dateSwitch + ""; + } + else + { + sTemp += "" + apo.setting.i18n.dateSwitch + ""; + sTemp += "" + apo.setting.i18n.timeSwitch + ""; + } + sTemp += "
"; + + apo.tmp.sDateTimeTab = "date"; + } + + sTemp += "
"; + + sTemp += "
"; + + sTemp += "
"; // Close .ap-content-middle + + if(apo.setting.viewSections.contentBottom.length > 0) + sTemp += "
"; + + sTemp += "
"; // Close .ap-content + + if(bAddSectionFooter || bAddSectionFooterFixedBottom) + { + sTemp += ""; + } + + sTemp += "
"; // Close .ap-cont + + sTemp += "
"; // Close .ap-bg + + sTemp += "
"; // Close .ap-overlay + + $(apo.setting.parent).append(sTemp); + + if(apo.setting.layout === "popover") + $("body").addClass("noscroll"); + + if($.AnyPicker.extra.bHasCSSAnimation) + { + $(apo.tmp.overlaySelector).addClass("ap-show"); + $(apo.tmp.overlaySelector).css({"display": "block"}); + if($.CF.compareStrings(apo.setting.layout, "fixed")) + { + if($.CF.compareStrings(apo.setting.vAlign, "top")) + $(apo.tmp.overlaySelector).find(".ap-cont").addClass("ap-top-slide-down"); + else if($.CF.compareStrings(apo.setting.vAlign, "bottom")) + $(apo.tmp.overlaySelector).find(".ap-cont").addClass("ap-bottom-slide-up"); + } + + setTimeout(function() + { + $(apo.tmp.overlaySelector).css({"opacity": 1}); + $(apo.tmp.overlaySelector).removeClass("ap-show"); + if($.CF.compareStrings(apo.setting.layout, "fixed")) + { + if($.CF.compareStrings(apo.setting.vAlign, "top")) + { + $(apo.tmp.overlaySelector).find(".ap-cont").removeClass("ap-top-slide-down"); + $(apo.tmp.overlaySelector + " .ap-cont").css({"top": 0}); + } + else if($.CF.compareStrings(apo.setting.vAlign, "bottom")) + { + $(apo.tmp.overlaySelector).find(".ap-cont").removeClass("ap-bottom-slide-up"); + $(apo.tmp.overlaySelector + " .ap-cont").css({"bottom": 0}); + } + } + }, apo.setting.animationDuration); + } + else + { + $(apo.tmp.overlaySelector).show(0); + } + + if($.CF.isValid(apo.setting.onShowPicker)) + apo.setting.onShowPicker.call(apo); + + apo._adjustPicker(); + apo._addViewSectionComponents(); + apo.__initComponents(); + apo._adjustPicker(); + + apo.tmp.bIsManualDraggingAfterShow = false; + + if($.CF.compareStrings(apo.setting.mode, "datetime") && apo.tmp.sDateTimeDecimalMode === "datetime") + apo._setDateTimeTabs(apo.tmp.sDateTimeTab); + else if($.CF.compareStrings(apo.setting.mode, "decimal") && apo.tmp.sDateTimeDecimalMode === "decimal") + apo._setDecimalTabs(apo.tmp.sDecimalTab); + }, + + _hidePicker: function() + { + var apo = this; + + if($(apo.tmp.overlaySelector).length > 0) + { + if($.CF.isValid(apo.setting.onBeforeHidePicker)) + apo.setting.onBeforeHidePicker.call(apo); + + if($.AnyPicker.extra.bHasCSSAnimation) + { + $(apo.tmp.overlaySelector).addClass("ap-hide"); + if($.CF.compareStrings(apo.setting.layout, "fixed")) + { + if($.CF.compareStrings(apo.setting.vAlign, "top")) + $(apo.tmp.overlaySelector).find(".ap-cont").addClass("ap-top-slide-up"); + else if($.CF.compareStrings(apo.setting.vAlign, "bottom")) + $(apo.tmp.overlaySelector).find(".ap-cont").addClass("ap-bottom-slide-down"); + } + setTimeout(function() + { + $(apo.tmp.overlaySelector).remove(); + }, apo.setting.animationDuration); + } + else + { + $(apo.tmp.overlaySelector).hide(0); + setTimeout(function() + { + $(apo.tmp.overlaySelector).remove(); + }, apo.setting.animationDuration); + } + + if(apo.setting.layout === "popover") + $("body").removeClass("noscroll"); + + apo.tmp.prevActive = null; + + if($.CF.isValid(apo.setting.onHidePicker)) + apo.setting.onHidePicker.call(apo); + } + }, + + _adjustPicker: function(iNumOfComp) + { + var apo = this; + + if($.CF.compareStrings(apo.setting.theme, "Windows")) + { + iNumOfComp = $.CF.isValid(iNumOfComp) ? parseInt(iNumOfComp) : apo.tmp.numOfComp; + + var iAvailableHeight = $(window).height(), + iAvailableWidth = $(window).width(), + bIsPortrait = apo._getDeviceOrientation() === "portrait", + iPadding = 10, iMaxWidth; + + if(bIsPortrait) + apo.setting.visibleRows = 5; + else + apo.setting.visibleRows = 3; + + if(!apo.setting.componentsCoverFullWidth) + { + if(!bIsPortrait) + { + iRowWidth = Math.floor(iAvailableHeight / 3); + iMaxWidth = iRowWidth * iNumOfComp; + iMaxWidth = (iAvailableHeight > iMaxWidth) ? iMaxWidth : iAvailableHeight; + iPadding = (iAvailableWidth - iMaxWidth) / 2; + iAvailableWidth = iAvailableHeight; + } + else + { + iRowWidth = Math.floor(iAvailableWidth / 3); + iMaxWidth = iRowWidth * iNumOfComp; + iPadding = (iAvailableWidth - iMaxWidth) / 2; + } + $(apo.tmp.overlaySelector).find(".ap-content-middle").css({"padding-left": iPadding, "padding-right": iPadding}); + } + + iAvailableWidth -= 16; + var iRowHeight = Math.floor(iAvailableHeight / apo.setting.visibleRows), + iRowWidth = Math.floor(iAvailableWidth / 3); + + if(!apo.setting.componentsCoverFullWidth) + apo.setting.rowHeight = iRowWidth; + else + { + iRowHeight = Math.floor(iAvailableHeight / apo.setting.visibleRows); + apo.setting.rowHeight = iRowHeight; + } + + var iCalculatedHeight = apo.setting.rowHeight * apo.setting.visibleRows, + iContTop = (iAvailableHeight - iCalculatedHeight) / 2, + iContentTop, iContentBottom; + $(apo.tmp.overlaySelector).find(".ap-content").css({"top": iContTop}); + + iContTop += 2; + iContentTop = $(apo.tmp.overlaySelector).find(".ap-header").height() - iContTop; + $(apo.tmp.overlaySelector).find(".ap-content-top").css({"top": iContentTop}); + iContTop -= 2; + iContentBottom = $(apo.tmp.overlaySelector).find(".ap-footer").height() + iContTop; + $(apo.tmp.overlaySelector).find(".ap-content-bottom").css({"bottom": iContentBottom}); + + apo.tmp.iExt = Math.floor(apo.setting.visibleRows / 2); + } + + var $oRelativeTo = $((apo.setting.relativeTo === null) ? apo.setting.inputElement : apo.setting.relativeTo), + iTop = $oRelativeTo.offset().top, + iLeft = $oRelativeTo.offset().left, + iWidth = $oRelativeTo.outerWidth(); + if($.CF.compareStrings(apo.setting.layout, "popover")) + { + var iBodyScrollTop = $("body").scrollTop(), + iWinWidth = $(window).outerWidth(), + iWinHeight = $(window).outerHeight(), + iMinTop = iBodyScrollTop, + iMaxTop = iBodyScrollTop + iWinHeight, + iInputTop = $(apo.setting.inputElement).offset().top - iBodyScrollTop, + iInputHeight = $(apo.setting.inputElement).outerHeight(), + iInputBottom = iInputTop + iInputHeight, + iInputLeft = $(apo.setting.inputElement).offset().left, + iInputWidth = $(apo.setting.inputElement).outerWidth(), + iInputRight = iInputLeft + iInputWidth, + iPopupWidth = $(apo.tmp.overlaySelector).find(".ap-cont").outerWidth(), + iPopupHeight = $(apo.tmp.overlaySelector).find(".ap-cont").outerHeight(), + iPopupTop, iPopupLeft, iPopupBottom, + iTooltipHeight = 10, + iTooltipWidth = 10; + + if(apo.tmp.sTooltip === "top") + { + iPopupTop = iInputTop - iPopupHeight - iTooltipHeight; + iPopupBottom = (iPopupTop < 0) ? 5 : iPopupTop; + iPopupLeft = iInputLeft + 5; + } + else if(apo.tmp.sTooltip === "bottom") + { + iPopupTop = iInputBottom + iTooltipHeight; + iPopupLeft = iInputLeft + 5; + if(apo.tmp.sDir === "rtl") + iPopupLeft = iInputRight - iPopupWidth; + } + else if(apo.tmp.sTooltip === "left") + { + iPopupTop = iInputTop - ((iPopupHeight / 2) - (iInputHeight / 2)); + iPopupTop = (iPopupTop < iMinTop) ? 5 : iPopupTop; + iPopupLeft = iInputLeft + iInputWidth + 5; + } + else if(apo.tmp.sTooltip === "right") + { + iPopupTop = iInputTop - ((iPopupHeight / 2) - (iInputHeight / 2)); + iPopupTop = (iPopupTop < iMinTop) ? 5 : iPopupTop; + iPopupLeft = iInputLeft - (iPopupWidth + iTooltipWidth); + } + $(apo.tmp.overlaySelector).find(".ap-cont").css({"position": "absolute", "left": iPopupLeft, "top": iPopupTop}); + } + else if($.CF.compareStrings(apo.setting.layout, "inline")) + { + $(apo.tmp.overlaySelector).find(".ap-cont").css({"position": "absolute", "width": iWidth, "left": iLeft, "top": iTop}); + } + else if($.CF.compareStrings(apo.setting.layout, "relative")) + { + $oRelativeTo = $((apo.setting.relativeTo === null) ? apo.setting.inputElement : apo.setting.relativeTo); + var iDocLeft = 0, + iDocRight = $(document).outerWidth(), + iContWidth = $(".ap-cont").outerWidth(), + iRelElemWidth = iWidth; + + iWidth = (iRelElemWidth > iContWidth) ? iContWidth : iRelElemWidth; + iTop = iTop + $oRelativeTo.outerHeight(); + + if($.CF.compareStrings(apo.setting.hAlign, "center")) + iLeft = (iRelElemWidth > iWidth) ? (iLeft + (iWidth/2)) : ((iRelElemWidth === iWidth) ? iLeft : (iLeft - (iWidth/2))); + else if($.CF.compareStrings(apo.setting.hAlign, "right")) + iLeft = iLeft - iWidth; + + iLeft = (iLeft < iDocLeft) ? (iDocLeft + 5) : iLeft; + var iRight = iLeft + iWidth; + + if(iRight > iDocRight) + { + if(iLeft > (iDocLeft + 5)) + { + iLeft = iLeft - (iRight - (iDocRight + 5)); + iLeft = (iLeft < iDocLeft) ? (iDocLeft + 5) : iLeft; + iRight = iLeft + iWidth; + iWidth = (iRight > iDocRight) ? (iDocRight - 10) : iWidth; + } + else + { + iWidth = iDocRight - 10; + } + } + + $(apo.tmp.overlaySelector).find(".ap-cont").css({"position": "absolute", "min-width": iWidth, "left": iLeft, "top": iTop}); + } + else if($.CF.compareStrings(apo.setting.layout, "fixed")) + { + if($.CF.compareStrings(apo.setting.vAlign, "top")) + $(apo.tmp.overlaySelector + " .ap-cont").css({"top": -1000}); + else if($.CF.compareStrings(apo.setting.vAlign, "bottom")) + $(apo.tmp.overlaySelector + " .ap-cont").css({"bottom": -1000}); + } + }, + + _addViewSectionComponents: function() + { + var apo = this; + var iTempIndex1, iTempIndex2, + bWindowsTheme = $.CF.compareStrings(apo.setting.theme, "Windows"); + + for(iTempIndex1 = 0; iTempIndex1 < $.AnyPicker.extra.sArrViewSections.length; iTempIndex1++) + { + var sViewSection = $.AnyPicker.extra.sArrViewSections[iTempIndex1]; + var sArrComponents = apo.setting.viewSections[sViewSection]; + if(sArrComponents.length > 0) + { + for(iTempIndex2 = 0; iTempIndex2 < sArrComponents.length; iTempIndex2++) + { + var sComp = sArrComponents[iTempIndex2], + oComp = apo.setting[sComp] || null, + $oCompElem = $(oComp.markup); + if(bWindowsTheme && $.CF.isValid(oComp.markupContentWindows)) + $oCompElem.html(oComp.markupContentWindows); + + if(oComp !== undefined && oComp !== null && oComp !== "") + { + if($.CF.compareStrings(sViewSection, "header")) + { + $(apo.tmp.overlaySelector).find(".ap-header").append($oCompElem); // Append Component + if($.CF.compareStrings(oComp.type, "Button") && $.CF.compareDataType(oComp.action, "function")) + $oCompElem.on("click." + apo.setting.timestamp, {"apo": apo}, oComp.action); // Bind Action + } + else if($.CF.compareStrings(sViewSection, "contentTop")) + { + $(apo.tmp.overlaySelector).find(".ap-content-top").append($oCompElem); // Append Component + if($.CF.compareStrings(oComp.type, "Button") && $.CF.compareDataType(oComp.action, "function")) + $oCompElem.on("click." + apo.setting.timestamp, {"apo": apo}, oComp.action); // Bind Action + } + else if($.CF.compareStrings(sViewSection, "contentBottom")) + { + $(apo.tmp.overlaySelector).find(".ap-content-bottom").append($oCompElem); // Append Component + if($.CF.compareStrings(oComp.type, "Button") && $.CF.compareDataType(oComp.action, "function")) + $oCompElem.on("click." + apo.setting.timestamp, {"apo": apo}, oComp.action); // Bind Action + } + else if($.CF.compareStrings(sViewSection, "footer")) + { + var $oeButtonCont = $(apo.tmp.overlaySelector).find(".ap-button-cont"); + if($oeButtonCont.length > 0) + $oeButtonCont.append($oCompElem); + else + $(apo.tmp.overlaySelector).find(".ap-footer").append($oCompElem); // Append Component + if($.CF.compareStrings(oComp.type, "Button") && $.CF.compareDataType(oComp.action, "function")) + $oCompElem.on("click." + apo.setting.timestamp, {"apo": apo}, oComp.action); // Bind Action + } + + if($.CF.compareStrings(sComp, "headerTitle") && $.CF.compareStrings(oComp.contentBehaviour, "Static")) + $(apo.tmp.overlaySelector).find(".ap-header__title").text(apo.setting.i18n.headerTitle); + + if($.CF.compareStrings(sComp, "setButton")) + { + if(!bWindowsTheme || (bWindowsTheme && apo.tmp.bModified.set)) + $oCompElem.text(apo.setting.i18n.setButton); + else if(bWindowsTheme && !apo.tmp.bModified.set) + $oCompElem.find(".ap-button-text").text(apo.setting.i18n.setButton); + } + else if($.CF.compareStrings(sComp, "clearButton")) + { + if(!bWindowsTheme || (bWindowsTheme && apo.tmp.bModified.clear)) + $oCompElem.text(apo.setting.i18n.clearButton); + else if(bWindowsTheme && !apo.tmp.bModified.clear) + $oCompElem.find(".ap-button-text").text(apo.setting.i18n.clearButton); + } + else if($.CF.compareStrings(sComp, "nowButton")) + { + if(!bWindowsTheme || (bWindowsTheme && apo.tmp.bModified.now)) + $oCompElem.text(apo.setting.i18n.nowButton); + else if(bWindowsTheme && !apo.tmp.bModified.now) + $oCompElem.find(".ap-button-text").text(apo.setting.i18n.nowButton); + } + else if($.CF.compareStrings(sComp, "cancelButton")) + { + if(!bWindowsTheme || (bWindowsTheme && apo.tmp.bModified.cancel)) + $oCompElem.text(apo.setting.i18n.cancelButton); + else if(bWindowsTheme && !apo.tmp.bModified.cancel) + $oCompElem.find(".ap-button-text").text(apo.setting.i18n.cancelButton); + } + + if($.CF.compareStrings(oComp.type, "Button")) + { + if(!$.CF.compareDataType(oComp.action, "function")) + { + if($.CF.compareStrings(sComp, "setButton")) + $oCompElem.on("click." + apo.setting.timestamp, {"apo": apo}, apo._setButtonAction); + else if($.CF.compareStrings(sComp, "clearButton")) + $oCompElem.on("click." + apo.setting.timestamp, {"apo": apo}, apo._clearButtonAction); + else if($.CF.compareStrings(sComp, "nowButton")) + $oCompElem.on("click." + apo.setting.timestamp, {"apo": apo}, apo._nowButtonAction); + else if($.CF.compareStrings(sComp, "cancelButton")) + $oCompElem.on("click." + apo.setting.timestamp, {"apo": apo}, apo._cancelButtonAction); + } + } + } + } + } + } + + if(bWindowsTheme) + { + $(".ap-button-icon, .ap-button-text").click(function(e) + { + $(this).closest(".ap-button").trigger("click"); + }); + } + + $(apo.tmp.overlaySelector).find(".ap-button") + .on("mousedown touchstart", function(e) + { + //e.stopPropagation(); + //e.preventDefault(); + $(this).addClass("ap-button-active"); + }) + .on("mouseup touchend", function(e) + { + //e.stopPropagation(); + //e.preventDefault(); + $(this).removeClass("ap-button-active"); + }); + + $(window).on("blur." + apo.setting.timestamp, function(e) + { + apo.tmp.prevActive = document.activeElement; + }); + + $(apo.tmp.overlaySelector).off("click." + apo.setting.timestamp); + + setTimeout(function() + { + $(apo.tmp.overlaySelector).on("click." + apo.setting.timestamp, function(e) + { + var iDTDiff = Date.now() - apo.tmp.iCompDragStart; + if(!apo.setting.bIsTouched && iDTDiff > 1000) + apo._hidePicker(); + }); + }, 300); + + $(apo.tmp.overlaySelector).find(".ap-cont, .ap-cont *").on("click." + apo.setting.timestamp, function(e) + { + e.stopPropagation(); + }); + + $(apo.tmp.overlaySelector).find(".ap-content-switch-date").click(function(e) + { + e.stopPropagation(); + apo._setDateTimeTabs("date"); + }); + + $(apo.tmp.overlaySelector).find(".ap-content-switch-time").click(function(e) + { + e.stopPropagation(); + apo._setDateTimeTabs("time"); + }); + + $(window).resize(function() + { + apo._adjustOnOrientationChange(); + }); + }, + + _setDateTimeTabs: function(sSelectedTab) + { + var apo = this; + var sDisabledTab = (sSelectedTab === "date") ? "time" : "date"; + apo.tmp.sDateTimeTab = sSelectedTab; + + $(apo.tmp.overlaySelector).find(".ap-content-switch-tab").removeClass("ap-content-switch-selected"); + $(apo.tmp.overlaySelector).find(".ap-content-switch-" + sSelectedTab).addClass("ap-content-switch-selected"); + var $oeDisabledTabs = $(apo.tmp.overlaySelector).find("[data-type='" + sDisabledTab + "']"), + $oeSelectedTabs = $(apo.tmp.overlaySelector).find("[data-type='" + sSelectedTab + "']"); + $oeDisabledTabs.css("display", "none"); + $oeSelectedTabs.css("display", "table-cell"); + + if($.CF.compareStrings(apo.setting.theme, "Windows")) + apo._adjustPicker($oeSelectedTabs.length); + }, + + _setDecimalTabs: function(sSelectedTab) + { + var apo = this; + var sDisabledTab = (sSelectedTab === "date") ? "time" : "date"; + apo.tmp.sDateTimeTab = sSelectedTab; + + $(apo.tmp.overlaySelector).find(".ap-content-switch-tab").removeClass("ap-content-switch-selected"); + $(apo.tmp.overlaySelector).find(".ap-content-switch-" + sSelectedTab).addClass("ap-content-switch-selected"); + var $oeDisabledTabs = $(apo.tmp.overlaySelector).find("[data-type='" + sDisabledTab + "']"), + $oeSelectedTabs = $(apo.tmp.overlaySelector).find("[data-type='" + sSelectedTab + "']"); + $oeDisabledTabs.css("display", "none"); + $oeSelectedTabs.css("display", "table-cell"); + + if($.CF.compareStrings(apo.setting.theme, "Windows")) + apo._adjustPicker($oeSelectedTabs.length); + }, + + _setOutput: function() + { + var apo = this; + var sOutput = "", + selectedValuePlusOne; + + if($.CF.isValid(apo.setting.formatOutput)) + { + sOutput = apo.setting.formatOutput.call(apo, apo.tmp.selectedValues, apo.tmp.bIsManualDraggingAfterShow); + } + else + { + if($.CF.compareStrings(apo.setting.mode, "select")) + { + for(var iCompIndex = 0; iCompIndex < apo.tmp.numOfComp; iCompIndex++) + { + if(iCompIndex !== 0) + sOutput += " "; + sOutput += apo.tmp.selectedValues.values[iCompIndex].label; + } + } + else if($.CF.compareStrings(apo.setting.mode, "datetime")) + { + if (apo.tmp.selectedValues.date >= apo._parseInputDateTime(apo.setting.maxValue) && $.CF.isValid(apo.tmp.oMinMax.max)) + { + apo.tmp.selectedValues.date = apo.tmp.oMinMax.max + } + if (apo.tmp.sDateTimeDecimalMode === "time") + { + selectedValuePlusOne = apo.formatOutputDates(new Date(apo.tmp.selectedValues.date.getTime() + ($.AnyPicker.extra.iMS.m * apo.setting.intervals.m))) + } + sOutput = apo.formatOutputDates(apo.tmp.selectedValues.date, apo.tmp.bIsManualDraggingAfterShow); + } + else if($.CF.compareStrings(apo.setting.mode, "decimal")) + { + if (apo.tmp.selectedValues.decimal > apo.setting.maxValue) + apo.tmp.selectedValues.decimal = apo.setting.maxValue + sOutput = apo.formatOutputDecimals(apo.tmp.selectedValues.decimal, apo.tmp.bIsManualDraggingAfterShow); + } + } + + if(apo.tmp.oElemValid.bIsListItem || apo.tmp.oElemValid.bIsSelect) + { + var sChild, $oChildElem; + if(apo.tmp.oElemValid.bIsListItem) + sChild = "li"; + else if(apo.tmp.oElemValid.bIsSelect) + sChild = "option"; + $(apo.elem).find(sChild).each(function() + { + $oChildElem = $(this); + + var sValue = $oChildElem.attr("value") || $oChildElem.data("value") || $oChildElem.text(); + + if(apo.tmp.selectedValues.values[0].val === sValue) + { + if(apo.tmp.oElemValid.bIsSelect) + $oChildElem.attr("selected", true); + else if(apo.tmp.oElemValid.bIsListItem) + $oChildElem.attr("data-selected", true); + } + else + { + if(apo.tmp.oElemValid.bIsSelect) + $oChildElem.attr("selected", false); + else if(apo.tmp.oElemValid.bIsListItem) + $oChildElem.attr("data-selected", false); + } + }); + } + + if($.CF.isValid(apo.setting.setOutput)) + apo.setting.setOutput.call(apo, sOutput, apo.tmp.selectedValues, apo.tmp.bIsManualDraggingAfterShow, selectedValuePlusOne); + else + { + if(apo.setting.inputElement !== null) + { + var $oInput = $(apo.setting.inputElement); + if(apo.tmp.oInputElemValid.bIsInput) + { + $oInput.val(sOutput); + } + else + { + $oInput.text(sOutput); + } + } + + if($.CF.isValid(apo.setting.onSetOutput)) + apo.setting.onSetOutput.call(apo, sOutput, apo.tmp.selectedValues, apo.tmp.bIsManualDraggingAfterShow, selectedValuePlusOne); + } + }, + + _clearOutput: function() + { + var apo = this; + + var $oInput = $(apo.setting.inputElement); + if(apo.tmp.oInputElemValid.bIsInput) + $oInput.val(""); + else + $oInput.text(""); + }, + + _setButtonAction: function(e) + { + var apo = e.data.apo; + + apo._setOutput(); + apo.showOrHidePicker(); + + if($.CF.isValid(apo.setting.buttonClicked)) + apo.setting.buttonClicked.call(apo, "set"); + }, + + _clearButtonAction: function(e) + { + var apo = e.data.apo; + + apo.tmp.selectedDate = $.AnyPicker.extra.dToday; + if(apo.tmp.sInputElemTag !== "" && !(apo.tmp.oInputElemValid.bIsListItem || apo.tmp.oInputElemValid.bIsSelect)) + { + var $oInput = $(apo.setting.inputElement); + + if(apo.tmp.oInputElemValid.bIsInput) + $oInput.val(""); + else + $oInput.text(""); + } + apo.showOrHidePicker(); + + if($.CF.isValid(apo.setting.buttonClicked)) + apo.setting.buttonClicked.call(apo, "clear"); + }, + + _nowButtonAction: function(e) + { + var apo = e.data.apo; + + if($.CF.compareStrings(apo.setting.mode, "datetime")) + { + apo.tmp.selectedDate = apo._getCurrentDate(); + apo._setSelectedAndInvalidValuesForRows(); + } + else if($.CF.compareStrings(apo.setting.mode, "decimal")) + { + apo.tmp.selectedDecimal = apo._getCurrentDecimal(); + apo._setSelectedAndInvalidValuesForRows(); + } + + if($.CF.isValid(apo.setting.buttonClicked)) + apo.setting.buttonClicked.call(apo, "now"); + }, + + _cancelButtonAction: function(e) + { + var apo = e.data.apo; + apo.showOrHidePicker(); + + if($.CF.isValid(apo.setting.buttonClicked)) + apo.setting.buttonClicked.call(apo, "cancel"); + }, + + _getDeviceOrientation: function() + { + var $window = $(window); + if($window.width() > $window.height()) + return "landscape"; + else + return "portrait"; + }, + + _adjustOnOrientationChange: function() + { + var apo = this; + + var sCurrentOrientation = apo._getDeviceOrientation(); + if(sCurrentOrientation !== apo.tmp.sOrientation) + { + $("body").prepend("
Loading
"); + apo.tmp.sOrientation = sCurrentOrientation; + apo._adjustPicker(); + apo.reloadAllComponents(); + } + } + +}; + +// --------------------------------- Functions : AnyPicker.Core End -------------------------------------- + + + + +// --------------------------------- Global Variables : AnyPicker.PickerComponent Start ----------------------------------- + +//"use strict"; + +$.AnyPicker = $.extend(true, $.AnyPicker, { + + defaults: // Defaults Settings + { + components: null, + dataSource: null, + + showComponentLabel: false, + componentsCoverFullWidth: false, + visibleRows: 3, + maxRows: 0, + rowHeight: 50, + + rowsNavigation: "scroller", + + //------------------ Callback Functions Start -------------------------- + + rowView: null, // (componentNumber, rowNumber, dataSourceRecord) + onChange: null // (componentNumber, rowNumber, selectedValues) + + //------------------ Callback Functions End ---------------------------- + }, + + tempDefaults: // Plugin-level Variables required to maintain state across methods + { + numOfComp: 0, + selectedValues: {}, + + bIsManualDraggingAfterShow: true, + bIsManualDragging: false, + bIsTouched: false, + iTS: 0, + + iPos: 0, + iPosPrev: 0, + iPosStop: 0, + + iOffset: 0, + iOffsetPrev: 0, + + iVelocity: 0, + iAmplitude: 0, + + oVelocityTicker: null, + oScrollTicker: null, + + iMinTopPos: 0, + iMaxTopPos: 0, + oScrollingComp: null, + iScrollingComp: -1, + + iTmConst: 100, + bEnd: false + }, + + extra: // Common Temporary Variables + { + sArrRowsNavigation: ["scroller+buttons", "scroller", "buttons"] + } + +}); + +// --------------------------------- Global Variables : AnyPicker.PickerComponent End -------------------------------------- + +// --------------------------------- Functions : AnyPicker.PickerComponent Start ------------------------------------ + +AnyPicker.prototype = $.extend(AnyPicker.prototype, { + + __initComponents: function() + { + var apo = this; + + if(!apo.tmp.bFirst) + { + if($.CF.compareStrings(apo.setting.mode, "select")) + apo.__setComponentsOfSelect(); + else if($.CF.compareStrings(apo.setting.mode, "datetime")) + apo.__setComponentsOfDateTimePicker(); + else if($.CF.compareStrings(apo.setting.mode, "decimal")) + apo.__setComponentsOfDecimalPicker(); + } + else + apo.tmp.bFirst = false; + + var iNumOfComponents = apo.tmp.numOfComp || apo.setting.components.length; + + if(iNumOfComponents > 0) + { + if(apo.setting.components.length > 0) // Length of actual components array + apo.reloadAllComponents(); + else + console.log("For apo.setting.mode \n 1. Select - \n Please set apo.setting.components 2. DateTime - \n Please enter a valid outputDateTimeFormat 2. Decimal - \n Please enter a valid outputDecimalFormat "); + } + }, + + // Public Method + reloadAllComponents: function() + { + var apo = this; + var iTempIndex; + + $(apo.setting.parent).find(".ap-component-section").html(""); + + $("body").prepend("
"); + + for(iTempIndex = 0; iTempIndex < apo.tmp.numOfComp; iTempIndex++) + { + apo.reloadComponent(iTempIndex, false); + } + + apo.adjustComponents(); + apo.setSelectedAndInvalidValuesForRows(true); + }, + + // Public Method + reloadComponent: function(iComp, bSingleLoad) + { + var apo = this; + var sTemp = ""; + + var iNumRows, iRowIndex, + oSData = apo.setting.dataSource[iComp].data, + bIsSelected = false, sClassSelectedRow, + sCompId = "ap-component-" + iComp, + $oeComp = $(apo.setting.parent).find("#" + sCompId), + oComp = apo.setting.components[iComp], + sType = $.CF.isValid(oComp.type) ? oComp.type : oComp.label, + sWidth = $.CF.isValid(oComp.width) ? ("width: " + oComp.width) : "", + sAlign = apo.setting.rtl ? ($.CF.compareStrings(oComp.textAlign, "left") ? "right" : $.CF.compareStrings(oComp.textAlign, "right") ? "left" : "") : oComp.textAlign, + sTextAlign = $.CF.isValid(sAlign) ? ("text-align: " + sAlign) : ""; + + if($oeComp.length === 0) + sTemp += "
"; + + if(!$.CF.compareStrings(apo.setting.theme, "Windows")) + { + if(apo.setting.showComponentLabel) + sTemp += "
" + oComp.label + "
"; + } + + if($.CF.compareStrings(apo.setting.rowsNavigation, "scroller+buttons") || $.CF.compareStrings(apo.setting.rowsNavigation, "buttons")) + sTemp += "
"; + + sTemp += "
"; + + sTemp += "
"; + + for(iRowIndex = 0; iRowIndex < apo.tmp.iExt; iRowIndex++) + { + sTemp += "
"; + } + + for(iRowIndex = 0; iRowIndex < oSData.length; iRowIndex++) + { + bIsSelected = ($.CF.isValid(oSData[iRowIndex].selected) ? oSData[iRowIndex].selected : false); + sClassSelectedRow = bIsSelected ? "ap-row-selected" : ""; + sTemp += "
"; + + if($.CF.compareStrings(apo.setting.theme, "Windows")) + { + sTemp += "
"; + if(!$.CF.isValid(apo.setting.rowView)) + sTemp += "
"; + } + + if($.CF.isValid(apo.setting.rowView)) + sTemp += apo.setting.rowView.call(apo, iComp, iRowIndex, oSData[iRowIndex]); + else + sTemp += oSData[iRowIndex].label; + + if($.CF.compareStrings(apo.setting.theme, "Windows") && !$.CF.isValid(apo.setting.rowView)) + { + sTemp += "
"; + sTemp += "
"; + if(apo.setting.showComponentLabel) + sTemp += oComp.label; + sTemp += "
"; + } + + if($.CF.compareStrings(apo.setting.theme, "Windows")) + sTemp += "
"; + + sTemp += "
"; + } + + for(iRowIndex = 0; iRowIndex < apo.tmp.iExt; iRowIndex++) + { + sTemp += "
"; + } + + sTemp += "
"; + + sTemp += "
"; + sTemp += "
"; + + sTemp += "
"; + + if($.CF.compareStrings(apo.setting.rowsNavigation, "scroller+buttons") || $.CF.compareStrings(apo.setting.rowsNavigation, "buttons")) + sTemp += "
"; + + if($oeComp.length === 0) + sTemp += "
"; + + if($oeComp.length > 0) + $oeComp.html(sTemp); + else + $(apo.setting.parent).find(".ap-component-section").append(sTemp); + + apo._bindEventsToComponent(iComp); + + if($oeComp.length > 0 || bSingleLoad) + apo.adjustComponents(); + if(bSingleLoad) + apo.setSelectedAndInvalidValuesForRows(true); + }, + + _bindEventsToComponent: function(iComp) + { + var apo = this; + var $oParent = $("#ap-component-" + iComp), + $oCompCont = $oParent.find(".ap-component-cont"), + oData = + { + component: iComp, + apo: apo + }; + + if($.CF.compareStrings(apo.setting.rowsNavigation, "scroller+buttons") || $.CF.compareStrings(apo.setting.rowsNavigation, "scroller")) + { + $oCompCont.on($.AnyPicker.extra.sStartEv + "." + apo.setting.timestamp, oData, apo._onStartDrag); + $oCompCont.on($.AnyPicker.extra.sMoveEv + "." + apo.setting.timestamp, oData, apo._onDrag); + if($.CF.isValid($.AnyPicker.extra.sEndEv)) + $oCompCont.on($.AnyPicker.extra.sEndEv + "." + apo.setting.timestamp, oData, apo._onEndDrag); + if($.CF.isValid($.AnyPicker.extra.sOutEv)) + $oCompCont.on($.AnyPicker.extra.sOutEv + "." + apo.setting.timestamp, oData, apo._onEndDrag); + + if($.AnyPicker.extra.sMouseWheel.length > 0) + { + for(var iEventIndex = 0; iEventIndex < $.AnyPicker.extra.sMouseWheel.length; iEventIndex++) + $oCompCont.on($.AnyPicker.extra.sMouseWheel[iEventIndex] + "." + apo.setting.timestamp, oData, apo._onMouseWheelScroll); + } + } + + if($.CF.compareStrings(apo.setting.rowsNavigation, "scroller+buttons") || $.CF.compareStrings(apo.setting.rowsNavigation, "buttons")) + { + $oParent.find(".ap-component-plus").on("click." + apo.setting.timestamp, oData, apo._onClickButtonMinus); + $oParent.find(".ap-component-minus").on("click." + apo.setting.timestamp, oData, apo._onClickButtonPlus); + } + + $oCompCont.on("keydown." + apo.setting.timestamp, oData, apo._onKeyDown); + $oCompCont.on("keyup." + apo.setting.timestamp, oData, apo._onKeyUp); + }, + + // Public Method + adjustComponents: function() + { + var apo = this; + var $overlaySelector = $(apo.tmp.overlaySelector); + $overlaySelector.find(".ap-component-cont").css({"height": (apo.setting.rowHeight * apo.setting.visibleRows)}); + $overlaySelector.find(".ap-row, .ap-component-selector").css({"height": apo.setting.rowHeight, "line-height": apo.setting.rowHeight + "px"}); + $overlaySelector.find(".ap-row-bg").css({"height": apo.setting.rowHeight - 8}); + + if(!$.CF.compareStrings(apo.setting.theme, "Windows")) + { + var iContWidth = $(".ap-cont").width(), + iContHeight = $(".ap-cont").height(), + iWinWidth = $(window).width(), + iWinHeight = $(window).height(), + iWidth = iWinWidth, + iHeight = iWinHeight, + bWidthChanged = false, bHeightChanged = false; + + if(iContWidth > iWinWidth) + { + bWidthChanged = true; + iWidth = iContWidth + 20; + } + if(iContHeight > iWinHeight) + { + bHeightChanged = true; + iHeight = iContHeight + 20; + } + + if(bWidthChanged || bHeightChanged) + { + $overlaySelector.css({"position": "absolute", "height": iHeight, "width": iWidth}); + + if($.CF.compareStrings(apo.setting.layout, "fixed")) + $(".ap-cont").css({"position": "absolute"}); + } + + if($.CF.compareStrings(apo.setting.layout, "relative")) + { + var $oRelativeTo = $((apo.setting.relativeTo === null) ? apo.setting.inputElement : apo.setting.relativeTo), + $oAPCont = $overlaySelector.find(".ap-cont"), + iTop = $oRelativeTo.offset().top + $oAPCont.height(); + if($.CF.compareStrings(apo.setting.vAlign, "top")) + $oAPCont.css({"top": iTop}); + } + } + + setTimeout(function() + { + $(".ap-loading").remove(); + }, 0); + }, + + _onStartDrag: function(e) + { + var apo = e.data.apo; + + if(!apo.tmp.bIsManualDragging) + { + apo.tmp.bIsManualDraggingAfterShow = true; + apo.tmp.bIsManualDragging = true; + } + apo.tmp.bIsTouched = true; + apo.tmp.bEnd = false; + apo.tmp.iPos = apo._getTouchPosition(e); + apo.tmp.bFromTouchStart = true; + apo._setScrollingData(e); + + if($.CF.compareStrings(apo.setting.theme, "Windows")) + { + var $oComp = $(apo.tmp.overlaySelector).find("#ap-component-" + apo.tmp.iScrollingComp); + + if(apo.tmp.bIsManualDragging) + { + $(apo.tmp.overlaySelector).find(".ap-component").removeClass("ap-component-modifying"); + $oComp.addClass("ap-component-modifying"); + } + } + + if(e.type === "mousedown") + { + $(document).on("mousemove." + apo.setting.timestamp, e.data, apo._onDrag); + $(document).on("mouseup." + apo.setting.timestamp, e.data, apo._onEndDrag); + } + + e.preventDefault(); + e.stopPropagation(); + return false; + }, + + _onDrag: function(e) + { + var apo = e.data.apo; + var iPosNew, iDSDelta, iTSDelta, iTSNDelta, iDSTS, iDir, iDSTSDiff, + iTSNew = Date.now(); + + apo._clearScrollTicker(); + + if(apo.tmp.bIsTouched && (!$.AnyPicker.extra.bHasPointer || $.AnyPicker.extra.bHasPointer && (apo.tmp.bFromTouchStart || (!apo.tmp.bFromTouchStart && (iTSNew - apo.tmp.iTS > 1000))))) + { + iPosNew = apo._getTouchPosition(e); + iTSNew = Date.now(); + iDSDelta = (apo.tmp.iPos - iPosNew); + iDir = iDSDelta / Math.abs(iDSDelta); + + if(iDSDelta > 2 || iDSDelta < -2) + { + if($.CF.compareStrings(apo.setting.theme, "Windows")) + { + var $oComp = $(apo.tmp.overlaySelector).find("#ap-component-" + apo.tmp.iScrollingComp), + $oAllRows = $oComp.find(".ap-row"); + $oAllRows.attr("aria-selected", "false"); + $oAllRows.removeClass("ap-row-selected"); + } + + apo.tmp.iPosPrev = apo.tmp.iPos; + apo.tmp.iPos = iPosNew; + iTSDelta = iTSNew - apo.tmp.iTS; + apo.tmp.iTS = iTSNew; + iDSTS = (iDSDelta / iTSDelta); + apo.tmp.iTotalDS += iDSDelta; + iDSTSDiff = apo.tmp.iPrevDSTS - iDSTS; + + if($.AnyPicker.extra.bHasPointer) + { + if($.AnyPicker.extra.bIsTouchDevice) + { + if(iDSDelta > 10 || iDSDelta < -10) + { + if($.CF.compareStrings(apo.setting.theme, "iOS")) + iDSDelta = apo.setting.visibleRows * 4 * iDSTS; + else + { + if(Math.abs(apo.tmp.iTotalDS) > 100) + { + if(iDSTS > 0.05) + { + if($.CF.compareStrings(apo.setting.theme, "Windows")) + iDSDelta = iDSDelta * iTSDelta * 5; + else + iDSDelta = iDSDelta * iTSDelta * 2; + } + else + { + if(iDir === 1) + iDSDelta = (iDir * apo.setting.rowHeight/2); + else + iDSDelta = (iDir * apo.setting.rowHeight/1.2); + } + } + else if(iDSTS > 0.06 && Math.abs(iDSTSDiff) > 0.08) + { + if($.CF.compareStrings(apo.setting.theme, "Windows")) + iDSDelta = iDSDelta * iTSDelta * 5; + else + iDSDelta = iDSDelta * iTSDelta * 2; + } + else + { + if(iDSDelta > 50 || iDSDelta < -50) + { + if($.CF.compareStrings(apo.setting.theme, "Windows")) + iDSDelta = iDSDelta * iTSDelta * 5; + else + iDSDelta = iDSDelta * iTSDelta * 2; + } + } + } + } + else + { + if(Math.abs(iDSTS) > 0.06 && Math.abs(iDSTSDiff) > 0.08) + { + if($.CF.compareStrings(apo.setting.theme, "Windows")) + iDSDelta = iDSDelta * iTSDelta * 5; + else + iDSDelta = iDSDelta * iTSDelta * 2; + } + else + { + if(iDir === 1) + iDSDelta = (iDir * apo.setting.rowHeight/2); + else + iDSDelta = (iDir * apo.setting.rowHeight/1.2); + } + } + } + else + { + if(iDSDelta < 2 && iDSDelta > -2 && iDSDelta !== 0) + iDSDelta = (iDir * 5); + + if(iDSDelta > 5 || iDSDelta < -5) + iDSDelta = (apo.setting.visibleRows / 10) * 320 * iDSTS; + else + iDSDelta = iDir * apo.setting.rowHeight; + } + } + else + { + if(iDSDelta > 10 || iDSDelta < -10) // 10 + iDSDelta = iDSDelta + apo.setting.visibleRows * 16 * iDSTS; // 80 | 160 + } + apo.tmp.iPrevDSTS = iDSTS; + + apo._scrollToPosition("drag", (apo.tmp.iOffset + iDSDelta), false, "#ap-component-" + apo.tmp.iScrollingComp + " .ap-component-data"); + apo.tmp.bFromTouchStart = false; + } + } + + e.preventDefault(); + e.stopPropagation(); + return false; + }, + + _onEndDrag: function(e) + { + var apo = e.data.apo; + + if(!apo.tmp.bEnd) + { + apo.tmp.bEnd = true; + apo.tmp.bIsTouched = false; + + apo._scrollToPosition("drag", apo.tmp.iOffset, true, "#ap-component-" + apo.tmp.iScrollingComp + " .ap-component-data"); + + if(e.type === "mouseup") + { + $(document).off("mousemove." + apo.setting.timestamp, apo._onDrag); + $(document).off("mouseup." + apo.setting.timestamp, apo._onEndDrag); + } + } + + e.preventDefault(); + e.stopPropagation(); + return false; + }, + + _onMouseWheelScroll: function(e) + { + var apo = e.data.apo; + var oData = e.data, + iDelta; + e = e || window.event; // old IE support + + if(oData.component !== apo.tmp.iScrollingComp) + apo._setScrollingData(e); + apo._clearScrollTicker(); + + iDelta = e.wheelDelta ? (e.wheelDelta / 3) : (e.originalEvent.wheelDelta ? (e.originalEvent.wheelDelta / 3) : (e.detail ? (-e.detail / 3) : 0)); + apo._scrollToPosition("mouseWheel", (apo.tmp.iOffset - (iDelta)), true, "#ap-component-" + apo.tmp.iScrollingComp + " .ap-component-data"); + + e.preventDefault(); + e.stopPropagation(); + return false; + }, + + _onClickButtonPlus: function(e) + { + var apo = e.data.apo; + + e.preventDefault(); + e.stopPropagation(); + + apo._setScrollingData(e); + apo._clearScrollTicker(); + + apo._scrollToPosition("button", (apo.tmp.iOffset + apo.setting.rowHeight), true, "#ap-component-" + apo.tmp.iScrollingComp + " .ap-component-data"); + }, + + _onClickButtonMinus: function(e) + { + var apo = e.data.apo; + + e.preventDefault(); + e.stopPropagation(); + + apo._setScrollingData(e); + apo._clearScrollTicker(); + + apo._scrollToPosition("button", (apo.tmp.iOffset - apo.setting.rowHeight), true, "#ap-component-" + apo.tmp.iScrollingComp + " .ap-component-data"); + }, + + _onKeyDown: function(e) + { + var apo = e.data.apo; + + e.preventDefault(); + e.stopPropagation(); + + apo._setScrollingData(e); + apo._clearScrollTicker(); + + if(e.keyCode === 38) // Up Arrow Key + { + apo._scrollToPosition("key", (apo.tmp.iOffset - apo.setting.rowHeight), true, "#ap-component-" + apo.tmp.iScrollingComp + " .ap-component-data"); + } + else if(e.keyCode === 40) // Down Arrow Key + { + apo._scrollToPosition("key", (apo.tmp.iOffset + apo.setting.rowHeight), true, "#ap-component-" + apo.tmp.iScrollingComp + " .ap-component-data"); + } + }, + + _onKeyUp: function(e) + { + var apo = e.data.apo; + + e.preventDefault(); + e.stopPropagation(); + + apo._unsetScrollingData(); + }, + + _getTouchPosition: function(e) + { + var apo = e.data.apo; + + e = e.originalEvent || e; + return e.changedTouches ? e.changedTouches[0].pageY : e.pageY; + }, + + _setScrollingData: function(e) + { + var apo = e.data.apo; + + apo.tmp.iScrollingComp = parseInt(e.data.component); + apo.tmp.oScrollingComp = $("#ap-component-"+e.data.component).find(".ap-component-data"); + apo.tmp.iMinTopPos = 0; + apo.tmp.iMaxTopPos = ($(apo.tmp.oScrollingComp).find(".ap-row").length * apo.setting.rowHeight) - $(apo.tmp.oScrollingComp).parent().innerHeight(); + apo.tmp.iTS = Date.now(); + apo.tmp.iCompDragStart = apo.tmp.iTS; + apo.tmp.iOffsetStart = Math.abs($(apo.tmp.oScrollingComp).position().top); + apo.tmp.iOffset = apo.tmp.iOffsetStart; + apo.tmp.iOffsetPrev = apo.tmp.iOffsetStart; + apo.tmp.iTimeout = 0; + apo.tmp.iDir = 1; + apo.tmp.iTotalDS = 0; + apo.tmp.iPrevDSTS = 0; + + apo._clearScrollTicker(); + }, + + _unsetScrollingData: function() + { + var apo = this; + + apo.tmp.bIsTouched = false; + apo.tmp.iPos = 0; + apo.tmp.iTS = 0; + + apo.tmp.iOffset = 0; + apo.tmp.iTimeout = 0; + + apo.tmp.iMinTopPos = 0; + apo.tmp.iMaxTopPos = 0; + apo.tmp.oScrollingComp = null; + apo.tmp.iScrollingComp = -1; + apo.tmp.iDir = 0; + + apo._clearScrollTicker(); + + $(document).off("mousemove." + apo.setting.timestamp); + $(document).off("mouseup." + apo.setting.timestamp); + $(document).off("touchend." + apo.setting.timestamp); + }, + + _getScrollingData: function() + { + var apo = this; + var oScrollingData = {}; + + oScrollingData.iScrollingComp = apo.tmp.iScrollingComp; + oScrollingData.oScrollingComp = apo.tmp.oScrollingComp; + oScrollingData.iMinTopPos = apo.tmp.iMinTopPos; + oScrollingData.iMaxTopPos = apo.tmp.iMaxTopPos; + oScrollingData.iTS = apo.tmp.iTS; + oScrollingData.iCompDragStart = apo.tmp.iCompDragStart; + oScrollingData.iOffsetStart = apo.tmp.iOffsetStart; + oScrollingData.iOffset = apo.tmp.iOffset; + oScrollingData.iOffsetPrev = apo.tmp.iOffsetPrev; + oScrollingData.iTimeout = apo.tmp.iTimeout; + oScrollingData.iDir = apo.tmp.iDir; + + return oScrollingData; + }, + + _clearScrollTicker: function() + { + var apo = this; + + clearTimeout(apo.tmp.oScrollTicker); + apo.tmp.oScrollTicker = null; + }, + + /* + + sSource values can be - + + 1. auto + 2. drag + 3. mousewheel + 4. button + 5. key + + */ + _scrollToPosition: function(sSource, iOffsetNew, bStop, sComp) + { + var apo = this; + + var iComp = apo.tmp.iScrollingComp, + iDir = (iOffsetNew < apo.tmp.iOffset) ? 1 : (iOffsetNew === apo.tmp.iOffset) ? apo.tmp.iDir : -1, // Bottom Up : Top Down + iPosMod = iOffsetNew % apo.setting.rowHeight, + iHalfRowHeight = apo.setting.rowHeight / 4, + iPrevOffset = apo.tmp.iOffset, + iTime = 0.1; + + apo.tmp.iDir = iDir; + + if(bStop) + iOffsetNew = (iPosMod !== 0) ? ((iPosMod < iHalfRowHeight) ? (iOffsetNew - iPosMod) : (iOffsetNew + (apo.setting.rowHeight - iPosMod))) : iOffsetNew; + + var iMinPosBounce = apo.tmp.iMinTopPos - apo.setting.rowHeight, + iMaxPosBounce = apo.tmp.iMaxTopPos + apo.setting.rowHeight; + + apo.tmp.iOffset = (iOffsetNew > apo.tmp.iMaxTopPos) ? iMaxPosBounce : (iOffsetNew < apo.tmp.iMinTopPos) ? iMinPosBounce : iOffsetNew; + + if($.AnyPicker.extra.bHasCSS3D) + { + var iDiffOffset = Math.abs(iPrevOffset - apo.tmp.iOffset); + + if(sSource === "drag") + { + if(iDiffOffset < (apo.setting.rowHeight * 6)) + iTime = (iDiffOffset / (apo.setting.rowHeight * 10)); // Increase Divisor value to increase speed + else + { + iTime = (iDiffOffset / (apo.setting.rowHeight * 10)); // Increase Divisor value to increase speed + iTime = (iTime <= 0.2) ? 0.2 : iTime; + } + } + else + iTime = 0.1; + + apo._performTransition(iComp, sComp, apo.tmp.iOffset, (apo.tmp.iTimeout/1000), apo.tmp.iMinTopPos, apo.tmp.iMaxTopPos, iDir, iMinPosBounce, iMaxPosBounce, sSource, bStop); + apo.tmp.iTimeout = (apo.tmp.iTimeout - (Date.now() - apo.tmp.iTS)) + (iTime * 1000); + } + else + apo._performTransition(iComp, sComp, apo.tmp.iOffset, iTime, apo.tmp.iMinTopPos, apo.tmp.iMaxTopPos, iDir, iMinPosBounce, iMaxPosBounce, sSource, bStop); + }, + + _performTransition: function(iComp, sComp, iOffset, iTime, iMinTopPos, iMaxTopPos, iDir, iMinPosBounce, iMaxPosBounce, sSource, bStop) + { + var apo = this; + var oElem = $(apo.tmp.overlaySelector).find(sComp).get(0), + iOffsetNew = apo._getOffset(oElem, true), + iDiffOffset = Math.abs(iOffsetNew - iOffset), + iExpTime = iDiffOffset / (apo.setting.rowHeight * 10); // Increase Divisor value to increase speed + + iTime = (iTime > iExpTime) ? iExpTime : iTime; + iTime = (iTime < 0.1) ? 0.1 : iTime; + iTime = ($.AnyPicker.extra.bHasPointer && apo.tmp.bIsTouched && sSource === "auto") ? 0 : iTime; + + if($.AnyPicker.extra.bHasCSS3D) + { + oElem.style[$.AnyPicker.extra.sCSSTransition] = $.AnyPicker.extra.sCSSTransformStyle + " " + iTime + "s ease-out"; + oElem.style[$.AnyPicker.extra.sCSSTransform] = "translate3d(0px, "+ -iOffset +"px, 0px)"; + } + else + $(oElem).animate({"top": -iOffset}, 100); + + apo.tmp.iOffset = iOffset; + + // --------------------------------------------------------------- + + var oScrollingData = apo._getScrollingData(); + apo._performTransitionAfter(oScrollingData, iMaxPosBounce, iMinPosBounce, sSource, iTime, bStop); + apo._clearScrollTicker(); + }, + + _performTransitionAfter: function(oScrollingData, iMaxPosBounce, iMinPosBounce, sSource, iTime, bStop) + { + var apo = this; + + setTimeout(function() + { + if(bStop && (sSource === "drag" || sSource === "mouseWheel")) + { + apo.tmp.oScrollTicker = 1; + apo._scrollToRow(oScrollingData.iDir, iMaxPosBounce, iMinPosBounce, oScrollingData.iMinTopPos, oScrollingData.iMaxTopPos, sSource); + } + + var oElem = $(oScrollingData.oScrollingComp).get(0), + iOffset = (sSource === "auto") ? oScrollingData.iOffset : -apo._getOffset(oElem, false), + + bLTMin = (iOffset < oScrollingData.iMinTopPos), + bGTMax = (iOffset > oScrollingData.iMaxTopPos), + + iOffsetNew = Math.abs(iOffset); + + if(bLTMin) + iOffset = oScrollingData.iMinTopPos; + else if(bGTMax) + iOffset = oScrollingData.iMaxTopPos; + + if(bLTMin || bGTMax) + { + iTime = Math.abs(iOffsetNew - iOffset) / (apo.setting.rowHeight * 10); + if($.AnyPicker.extra.bHasCSS3D) + { + oElem.style[$.AnyPicker.extra.sCSSTransition] = $.AnyPicker.extra.sCSSTransformStyle + " " + iTime + "s ease-out"; + oElem.style[$.AnyPicker.extra.sCSSTransform] = "translate3d(0px, "+ -Math.abs(iOffset) +"px, 0px)"; + } + else + $(oElem).animate({"top": -Math.abs(iOffset)}, 100); + + oScrollingData.iOffset = iOffset; + iOffsetNew = iOffset; + + apo._skipDisabledRowAfter(oScrollingData, iOffsetNew, sSource, iTime, bStop); + } + else + { + if(bStop || (iOffsetNew === oScrollingData.iMinTopPos || iOffsetNew === oScrollingData.iMaxTopPos)) + apo._skipDisabledRow(sSource, oScrollingData.iScrollingComp, iOffsetNew, oScrollingData.iDir); + } + }, (iTime * 1000)); + }, + + _skipDisabledRowAfter: function(oScrollingData, iOffsetNew, sSource, iTime, bStop) + { + var apo = this; + + setTimeout(function() + { + var iOffsetVal = (sSource === "auto") ? iOffsetNew : oScrollingData.iOffset; + if(bStop || (iOffsetVal === oScrollingData.iMinTopPos || iOffsetVal === oScrollingData.iMaxTopPos)) + apo._skipDisabledRow(sSource, oScrollingData.iScrollingComp, iOffsetVal, oScrollingData.iDir); + }, (iTime * 1000)); + }, + + _getOffset: function(oElem, bAbs) + { + var sMatrix = $(oElem).hasClass("ap-component-data") ? $(oElem).css("transform") : $(oElem).find(".ap-component-data").css("transform"), + iOffset = 0; + + if($.CF.isValid(sMatrix)) + { + if(sMatrix === "none") + iOffset = 0; + else + { + sMatrix = sMatrix.replace("matrix(", ""); + sMatrix = sMatrix.replace(")", ""); + var iArrMatrix = sMatrix.split(", "); + iOffset = (iArrMatrix.length > 6) ? parseInt(iArrMatrix[13]) : parseInt(iArrMatrix[5]); + } + } + + if(bAbs) + return Math.abs(iOffset); + else + return iOffset; + }, + + _scrollToRow: function(iDir, iMaxPosBounce, iMinPosBounce, iMinTopPos, iMaxTopPos, sSource) + { + var apo = this; + + var iPosMod, iOffset, iTime; + if(apo.tmp.oScrollTicker !== null) + { + var oElem = $(apo.tmp.oScrollingComp).get(0); + iOffset = apo._getOffset(oElem, false); + iPosMod = iOffset % apo.setting.rowHeight; + + if(iPosMod !== 0 || (iPosMod === 0 && (iOffset > iMinTopPos || iOffset < -iMaxTopPos))) + { + iOffset = Math.abs(iOffset); + iOffset = (iDir === -1) ? (iOffset + (apo.setting.rowHeight - Math.abs(iPosMod))) : (iOffset + iPosMod); + iOffset = (iOffset > iMaxTopPos) ? iMaxTopPos : (iOffset < iMinTopPos) ? iMinTopPos : iOffset; + + iTime = 0.4; + if($.AnyPicker.extra.bHasCSS3D) + { + oElem.style[$.AnyPicker.extra.sCSSTransition] = $.AnyPicker.extra.sCSSTransformStyle + " " + iTime + "s ease-out"; + oElem.style[$.AnyPicker.extra.sCSSTransform] = "translate3d(0px, "+ -Math.abs(iOffset) +"px, 0px)"; + } + else + $(oElem).animate({"top": -Math.abs(iOffset)}, 100); + apo.tmp.iOffset = iOffset; + } + } + }, + + __scrollToSelectedRow: function() + { + var apo = this; + var iTempIndex; + var e = {}, iTimeout = 0; + + if($.CF.compareStrings(apo.setting.mode, "datetime")) + apo.__setSelectedDateTimeInComponent(); + else if($.CF.compareStrings(apo.setting.mode, "decimal")) + { + apo.__setSelectedDecimalInComponent(); + } + for(iTempIndex = 0; iTempIndex < apo.tmp.numOfComp; iTempIndex++) + { + var oArrSelected = $(apo.tmp.overlaySelector).find("#ap-component-" + iTempIndex + " .ap-row-selected"), + oElemSelected = (oArrSelected.length > 0) ? oArrSelected[0] : null; + if(oElemSelected !== null) + { + var iPosTop = $(oElemSelected).position().top, + iExtraHeight = (apo.tmp.iExt * apo.setting.rowHeight); + iPosTop = (iPosTop === 0) ? iPosTop : (iPosTop - iExtraHeight); + + apo.callScrollToPosition(iTempIndex, apo, iPosTop, iTimeout); + iTimeout += 200; + } + } + }, + + callScrollToPosition: function(iComp, oAPO, iPosTop, iTimeout) + { + var apo = this; + var e = {}; + //setTimeout(function() + //{ + e.data = { component: iComp, apo: oAPO }; + apo._setScrollingData(e); + apo._scrollToPosition("auto", iPosTop, true, "#ap-component-" + iComp + " .ap-component-data"); + //}, iTimeout); + }, + + // Public Method + setSelectedAndInvalidValuesForRows: function(bSetSelected) + { + var apo = this; + + if($.CF.compareStrings(apo.setting.mode, "select")) + apo.__disableInvalidRowsOfSelect(); + else if($.CF.compareStrings(apo.setting.mode, "datetime")) + { + if(bSetSelected) + apo.__setSelectedDateTimeInComponent(); + + $(apo.tmp.overlaySelector).find(".ap-row").removeClass("ap-row-disabled ap-row-invalid ap-row-hidden"); + apo.__disableInvalidRowsOfDateTimePicker(); + apo.__setDaysOfMonthInDatePicker(); + } + else if($.CF.compareStrings(apo.setting.mode, "decimal")) + { + if(bSetSelected) + { + apo.__setSelectedDecimalInComponent(); + } + + $(apo.tmp.overlaySelector).find(".ap-row").removeClass("ap-row-disabled ap-row-invalid ap-row-hidden"); + apo.__disableInvalidRowsOfDecimalPicker(); + } + + if(bSetSelected) + apo.__scrollToSelectedRow(); + }, + + /* + + After the component stops scrolling, + + Unset the values of the non-selected components in - + + 1. apo.setting.dataSource + 2. Set area-selected attribute as false + + set the value of the selected component in - + + 1. apo.setting.dataSource + 2. aria-selected attribute of the selected DOM element + + */ + __changeComponentValue: function(iComp, sNewValue) + { + var apo = this; + var oComp = apo.setting.components[iComp], + oDataSource = apo.setting.dataSource[iComp].data, + iTempIndex, sElemId, $oElem; + + for(iTempIndex = 0; iTempIndex < oDataSource.length; iTempIndex++) + { + sElemId = "#ap-row-" + iComp + "-" + iTempIndex; + $oElem = $(apo.tmp.overlaySelector).find(sElemId); + + if(oDataSource[iTempIndex].val === sNewValue) + { + oDataSource[iTempIndex].selected = true; + $oElem.attr("aria-selected", "true"); + $oElem.addClass("ap-row-selected"); + } + else + { + oDataSource[iTempIndex].selected = false; + $oElem.attr("aria-selected", "false"); + $oElem.removeClass("ap-row-selected"); + } + } + }, + + /* + + If picker component rests on the disabled row after scrolling, + + 1. Find the next enabled row to be selected in direction of scrolling. + 2. If enabled row cannot be found then search for enabled row in the opposite direction + + Once row is found call _scrollToPosition() + + */ + _skipDisabledRow: function(sSource, iComp, iOffset, iDir) + { + var apo = this; + var sElemSel = "#ap-component-" + iComp + " .ap-component-data", + oElem = $(apo.tmp.overlaySelector).find(sElemSel).get(0), + iRow = Math.floor(iOffset / apo.setting.rowHeight), + sPartialId = "#ap-row-" + iComp + "-", + sRowId = sPartialId + iRow, + iTotalRows = $(oElem).find(".ap-row").length - (2 * apo.tmp.iExt), + bIsRowDisabled = $(oElem).find(sRowId).hasClass("ap-row-disabled"), + iEnabledRow = -1, + iDirPrev = 0, e = {}, + bSkippedRow = false; + + if($.CF.isValid(oElem) && bIsRowDisabled) + { + if(iDir === 1) + { + iEnabledRow = apo._findRows(iComp, iRow, iTotalRows, oElem, iDir); + if(iEnabledRow === -1) + { + iDir = -1; + iDirPrev = 1; + } + } + + if(iDir === -1) + { + iEnabledRow = apo._findRows(iComp, iRow, iTotalRows, oElem, iDir); + if(iEnabledRow === -1 && iDirPrev === 0) + { + iDir = 1; + iEnabledRow = apo._findRows(iComp, iRow, iTotalRows, oElem, iDir); + } + } + + var iNewOffset = (iEnabledRow !== -1) ? ($(oElem).find(sPartialId + iEnabledRow).position().top - (apo.tmp.iExt * apo.setting.rowHeight)) : -1; + if(iEnabledRow !== -1 && iOffset !== iNewOffset) + { + bSkippedRow = true; + e.data = { component: iComp, apo: apo }; + apo._setScrollingData(e); + apo._scrollToPosition("auto", iNewOffset, true, sElemSel); + } + else + { + setTimeout(function() + { + apo._actionsOnComponentStop(sSource, iComp, iRow, iOffset, iDir); + }, 200); + } + } + else + { + setTimeout(function() + { + apo._actionsOnComponentStop(sSource, iComp, iRow, iOffset, iDir); + }, 200); + } + }, + + _actionsOnComponentStop: function(sSource, iComp, iRow, iOffset, iDir) + { + var apo = this; + var iTempIndex, bReloaded = false, sHeaderTitle = ""; + + apo.__setAriaSelectedForRowElement(iComp, iOffset, iDir); + apo._getSelectedValueInComponent(null); + + if($.CF.compareStrings(apo.setting.inputChangeEvent, "onChange")) + apo._setOutput(); + + if(apo.tmp.sHeaderTitleType === "DynamicFunction") + { + sHeaderTitle = apo.setting.headerTitle.format.call(apo.tmp.selectedValues); + $(apo.tmp.overlaySelector).find(".ap-header__title").text(sHeaderTitle); + } + else if(apo.tmp.sHeaderTitleType === "DynamicString") + { + if($.CF.compareStrings(apo.setting.mode, "select")) + { + for(var iCompIndex = 0; iCompIndex < apo.tmp.numOfComp; iCompIndex++) + { + if(iCompIndex !== 0) + sHeaderTitle += " "; + sHeaderTitle += apo.tmp.selectedValues.values[iCompIndex].label; + } + } + else if($.CF.compareStrings(apo.setting.mode, "datetime")) + { + sHeaderTitle = apo.formatOutputDates(apo.tmp.selectedValues.date, apo.tmp.sArrHeaderTitleFormat); + } + else if($.CF.compareStrings(apo.setting.mode, "decimal")) + { + sHeaderTitle = apo.formatOutputDecimals(apo.tmp.selectedValues.decimal, apo.tmp.sArrHeaderTitleFormat); + } + + var bSetHeaderTitle = true; + if(!apo.tmp.bIsManualDragging) // !$.CF.compareStrings(apo.setting.theme, "iOS") && + bSetHeaderTitle = false; + if(bSetHeaderTitle) + $(apo.tmp.overlaySelector).find(".ap-header__title").text(sHeaderTitle); + } + + if(sSource !== "auto" && $.CF.isValid(apo.setting.onChange)) + apo.setting.onChange.call(apo, iComp, iRow, apo.tmp.selectedValues, sSource); + + if(!bReloaded) + apo.setSelectedAndInvalidValuesForRows(false); + }, + + /* + + Find rows in the scrolling component before/after a specified Row in a specified direction. + + */ + _findRows: function(iComp, iRow, iTotalRows, oElem, iDir) + { + var apo = this; + var iTempIndex; + + if(iDir === -1) + { + for(iTempIndex = (iRow + 1); iTempIndex < iTotalRows; iTempIndex++) + { + if(! $(oElem).find("#ap-row-" + iComp + "-" + iTempIndex).hasClass("ap-row-disabled")) + return iTempIndex; + } + } + else if(iDir === 1) + { + for(iTempIndex = (iRow - 1); iTempIndex > 0; iTempIndex--) + { + if(! $(oElem).find("#ap-row-" + iComp + "-" + iTempIndex).hasClass("ap-row-disabled")) + return iTempIndex; + } + } + + return -1; + }, + + /* + + Validate selected values to ensure that the values are not specified as disabled values or they do not fall in the disabled values range. + + */ + _validateSelectedValues: function() + { + var apo = this; + + if($.CF.compareStrings(apo.setting.mode, "datetime")) + { + var dNewSelectedDate = apo.__getSelectedDate(false); + apo.__validateSelectedDate(dNewSelectedDate, false); + } + else if($.CF.compareStrings(apo.setting.mode, "decimal")) + { + var dNewSelectedDecimal = apo.__getSelectedDecimal(false); + apo.__validateSelectedDecimal(dNewSelectedDecimal, false); + } + }, + + __setAriaSelectedForRowElement: function(iComp, iOffset, iDir) + { + var apo = this; + var $oElemComp = $(apo.tmp.overlaySelector).find("#ap-component-" + iComp), + iElementIndex; + + if(iOffset === 0) + iOffset = apo._getOffset($oElemComp, true); + + if(iDir === 1) + iElementIndex = Math.floor(iOffset / apo.setting.rowHeight); + else if(iDir === -1) + iElementIndex = Math.ceil(iOffset / apo.setting.rowHeight); + + var $oAllRows = $oElemComp.find(".ap-row"), + $oThisRow = $oElemComp.find("#ap-row-" + iComp + "-" + iElementIndex); + + $oAllRows.attr("aria-selected", "false"); + $oAllRows.removeClass("ap-row-selected"); + + $oThisRow.attr("aria-selected", "true"); + $oThisRow.addClass("ap-row-selected"); + }, + + _getSelectedValueInComponent: function(iComp) + { + var apo = this; + var iTempIndex, + $oSelectedElem, sSelectedValue, sSelectedDisplayValue, + oArrSelectedValues = []; + + apo.tmp.selectedValues = {}; + + if($.CF.isValid(iComp)) + { + $oSelectedElem = $(apo.tmp.overlaySelector).find("#ap-component-" + iComp + " .ap-row-selected"); + + oArrSelectedValues.push( + { + component: iComp, + val: $oSelectedElem.data("value"), + label: $oSelectedElem.data("label") + }); + } + else + { + for(iTempIndex = 0; iTempIndex < apo.tmp.numOfComp; iTempIndex++) + { + $oSelectedElem = $(apo.tmp.overlaySelector).find("#ap-component-" + iTempIndex + " .ap-row-selected"); + + oArrSelectedValues.push( + { + component: iTempIndex, + val: $oSelectedElem.data("value"), + label: $oSelectedElem.data("label") + }); + } + } + + apo.tmp.selectedValues.values = oArrSelectedValues; + + if($.CF.compareStrings(apo.setting.mode, "datetime")) + { + apo.tmp.selectedValues.date = apo.__getSelectedDate(false); + apo.tmp.selectedDate = apo.tmp.selectedValues.date; + } + else if($.CF.compareStrings(apo.setting.mode, "decimal")) + { + apo.tmp.selectedValues.decimal = apo.__getSelectedDecimal(false); + apo.tmp.selectedDecimal = apo.tmp.selectedValues.decimal; + } + }, + + __getDataSourceValueFromLabel: function(sLabel, iInCompIndex, bSetSelected) + { + var apo = this; + var iCompIndex, iTempIndex, + oCompData, oData, sValue = ""; + + if($.CF.isValid(iInCompIndex)) + { + oCompData = apo.setting.dataSource[iInCompIndex].data; + for(iTempIndex = 0; iTempIndex < oCompData.length; iTempIndex++) + { + oData = oCompData[iTempIndex]; + if($.CF.compareStrings(oData.label, sLabel)) + { + sValue = oData.val; + if(bSetSelected) + oData.selected = true; + } + else + { + if(bSetSelected) + oData.selected = false; + } + apo.setting.dataSource[iInCompIndex].data[iTempIndex] = oData; + } + } + else + { + for(iCompIndex = 0; iCompIndex < apo.tmp.numOfComp; iCompIndex++) + { + oCompData = apo.setting.dataSource[iCompIndex].data; + for(iTempIndex = 0; iTempIndex < oCompData.length; iTempIndex++) + { + oData = oCompData[iTempIndex]; + if($.CF.compareStrings(oData.label, sLabel)) + { + if(bSetSelected) + oData.selected = true; + sValue = oData.val; + } + else + { + if(bSetSelected) + oData.selected = false; + } + } + } + } + + return sValue; + }, + + __getValuesOfComponent: function(sValueOf, iComp) + { + var apo = this; + var oValue = null, iCompIndex; + + if(sValueOf === "component") + { + if(apo.setting.components[iComp].component === iComp) + oValue = apo.setting.components[iComp]; + else + { + for(iCompIndex = 0; iCompIndex < apo.tmp.numOfComp; iCompIndex++) + { + if(apo.setting.components[iCompIndex].component === iComp) + oValue = apo.setting.components[iCompIndex]; + } + } + } + else if(sValueOf === "datasource") + { + if(apo.setting.dataSource[iComp].component === iComp) + oValue = apo.setting.dataSource[iComp]; + else + { + for(iCompIndex = 0; iCompIndex < apo.tmp.numOfComp; iCompIndex++) + { + if(apo.setting.dataSource[iCompIndex].component === iComp) + oValue = apo.setting.dataSource[iCompIndex]; + } + } + } + console.log("__getValuesOfComponent oValue: ", oValue) //mc + return oValue; + } + +}); + +// --------------------------------- Functions : AnyPicker.PickerComponent End -------------------------------------- + + + + +// --------------------------------- Functions : AnyPicker.Select Start ------------------------------------ + +//"use strict"; + +AnyPicker.prototype = $.extend(AnyPicker.prototype, { + + __setComponentsOfSelect: function() + { + var apo = this; + + if(apo.setting.dataSource === null) + { + if(apo.tmp.oElemValid.bIsListItem || apo.tmp.oElemValid.bIsSelect) + { + var sChild, $oChildElem; + apo.setting.components = []; + + var oComponent = {}; + oComponent.component = 1; + oComponent.name = $(apo.elem).data("name"); + oComponent.label = $(apo.elem).data("label"); + apo.setting.components.push(oComponent); + + var oArrData = []; + + if(apo.tmp.oElemValid.bIsListItem) + sChild = "li"; + else if(apo.tmp.oElemValid.bIsSelect) + sChild = "option"; + + $(apo.elem).find(sChild).each(function() + { + $oChildElem = $(this); + + var oSelectData = { + + val: $oChildElem.attr("value") || $oChildElem.data("value") || $oChildElem.text(), + label: $oChildElem.text(), + selected: function() + { + if($oChildElem.attr("selected") || $oChildElem.attr("data-selected") !== undefined && $oChildElem.attr("data-selected") === "true") + return true; + else + return false; + }, + disabled: function() + { + if($oChildElem.attr("disabled") || $oChildElem.data("disabled") !== undefined && $oChildElem.data("disabled") === "true") + return true; + else + return false; + } + }; + + if(oSelectData.disabled) + { + oSelectData.selected = false; + } + else if(oSelectData.selected) + { + apo.tmp.selected = { + val: oSelectData.val, + displayVal: oSelectData.displayVal + }; + } + + oArrData.push(oSelectData); + }); + + apo.setting.dataSource = []; + var oData = {}; + oData.component = 1; + oData.data = oArrData; + apo.setting.dataSource.push(oData); + + apo.tmp.numOfComp = 1; + + if($.CF.compareStrings(apo.setting.headerTitle.contentBehaviour, "Dynamic") && $.CF.isValid(apo.setting.headerTitle.format)) + { + if(typeof apo.setting.headerTitle.format === "function") + apo.tmp.sHeaderTitleType = "DynamicFunction"; + else if(typeof apo.setting.headerTitle.format === "string") + { + apo.tmp.sHeaderTitleType = "DynamicString"; + } + } + } + else + console.log("You will have to specify dataSource either as a JSON object or as