def endsWith(self, search_value: Union[str, primitives.JsDataModel], length: Optional[Union[int, primitives.JsDataModel]] = None, js_funcs: Optional[Union[list, str]] = None): """ Description: ------------ The endsWith() method determines whether a string ends with the characters of a specified string. Related Pages: https//www.w3schools.com/jsref/jsref_endswith.asp Attributes: ---------- :param Union[str, primitives.JsDataModel] search_value: The string to search for. :param Optional[Union[int, primitives.JsDataModel]] length: Optional. Specify the length of the string to search. If omitted, the default value is the length of the string. :param Optional[Union[list, str]] js_funcs: Javascript functions. :return: A Boolean. Returns true if the string ends with the value, otherwise it returns false """ from epyk.core.js.primitives import JsBoolean search_value = JsUtils.jsConvertData(search_value, js_funcs) if length is not None: return JsBoolean.JsBoolean("%s.endsWith(%s, %s)" % (self.varId, search_value, length), is_py_data=False) return JsBoolean.JsBoolean("%s.endsWith(%s)" % (self.varId, search_value), is_py_data=False)
def startsWith(self, search_value: Union[str, primitives.JsDataModel], start: Union[int, primitives.JsDataModel] = 0, js_funcs: Optional[Union[list, str]] = None, jsObj=None): """ Description: ------------ The startsWith() method determines whether a string begins with the characters of a specified string. This function might not work with older browser, so to guarantee a good compatibility the jsObj must be defined. Related Pages: https//www.w3schools.com/jsref/jsref_startswith.asp Attributes: ---------- :param str Union[str, primitives.JsDataModel] search_value: The string to search for. :param Union[int, primitives.JsDataModel] start: Optional. Default 0. At which position to start the search. :param Optional[Union[list, str]] js_funcs: Javascript functions. :param jsObj: :return: A Boolean. Returns true if the string starts with the value, otherwise it returns false """ from epyk.core.js.primitives import JsBoolean # Add a polyfill to ensure the browser compatibility if jsObj is not None: jsObj._addImport("babel-polyfill") search_value = JsUtils.jsConvertData(search_value, js_funcs) return JsBoolean.JsBoolean("%s.startsWith(%s, %s)" % (self.varId, search_value, start), is_py_data=False)
def ctrlKey(self): """ The ctrlKey property returns a Boolean value that indicates whether or not the "CTRL" key was pressed when a mouse event was triggered. https://www.w3schools.com/jsref/event_ctrlkey.asp """ return JsBoolean.JsBoolean("event.ctrlKey", isPyData=False)
def includes(self, element: Union[primitives.JsDataModel, str], start: int = 0): """ Description: ----------- The includes() method determines whether an array contains a specified element. This method returns true if the array contains the element, and false if not. Note: The includes() method is case sensitive. Related Pages: https://www.w3schools.com/jsref/jsref_includes_array.asp Attributes: ---------- :param Union[primitives.JsDataModel, str] element: Object. The element to search for. :param int start: Optional. Default 0. At which position in the array to start the search. """ from epyk.core.js.primitives import JsBoolean return JsBoolean.JsBoolean( "%s.includes(%s, %s)" % (self.varId, JsUtils.jsConvertData(element, None), start), is_py_data=False)
def contains(self, js_obj, data: primitives.JsDataModel): """ Description: ----------- Prototype Extension Alternative to the includes function and compatible with all the browsers Usage:: jsObj.objects.array.new([2, 2, -3, -3], "MyArray") jsObj.objects.array.get("MyArray").contains(2) Attributes: ---------- :param js_obj: The Python Javascript base object. :param primitives.JsDataModel data: The object to look for in the array. :return: A Python Javascript boolean. """ from epyk.core.js.primitives import JsBoolean js_obj.extendProto(self, "contains", ''' var i = this.length; while (i--){if (this[i] === obj){return true}}; return false ''', pmts=["data"]) return JsBoolean.JsBoolean( "%s.contains(%s)" % (self.varId, JsUtils.jsConvertData(data, None)), is_py_data=False)
def onLine(self): """ The onLine property returns true if the browser is online Related Pages: https://www.w3schools.com/js/js_window_navigator.asp """ return JsBoolean.JsBoolean("navigator.onLine", isPyData=False)
def startswith(self, val: Union[str, primitives.JsDataModel], position: int = None): """ Description: ------------ Proxy to the Python method startswith. Attributes: ---------- :param Union[str, primitives.JsDataModel] val: The Python value. :param int position: :return: Always False as this is dedicated to be a Javascript Object. """ from epyk.core.js.primitives import JsBoolean val = JsUtils.jsConvertData(val, None) if position is None: return JsBoolean.JsBoolean("%s.startswith(%s)" % (self.varId, val), is_py_data=False) return JsBoolean.JsBoolean("%s.startswith(%s, %s)" % (self.varId, val, position), is_py_data=False)
def javaEnabled(self): """ The javaEnabled() method returns a Boolean value that specifies whether the browser has Java enabled. Related Pages: https://www.w3schools.com/jsref/met_nav_javaenabled.asp :return: """ return JsBoolean.JsBoolean("navigator.javaEnabled()", isPyData=False)
def ctrlKey(self): """ Description: ------------ The ctrlKey property returns a Boolean value that indicates whether or not the "CTRL" key was pressed when a touch event was triggered. Related Pages: https://www.w3schools.com/jsref/event_touch_ctrlkey.asp """ return JsBoolean.JsBoolean("event.ctrlKey", isPyData=False)
def isWeedend(self): """ Description: ----------- Usage:: jsObj.objects.date.get("dateTest").isWeedend """ from epyk.core.js.primitives import JsBoolean return JsBoolean.JsBoolean("(%(varId)s.getDay() === 6) || (%(varId)s.getDay() === 0)" % {"varId": self.varId}, isPyData=False)
def scrollEndPage(self, window_id: str = "window"): """ Description: ------------ The scrollEndPage property indicates if the page is scrolled to the end. Attributes: ---------- :param str window_id: Optional. The window reference. """ return JsBoolean.JsBoolean("(%s.scrollY + %s.innerHeight > document.body.clientHeight)? true: false" % ( window_id, window_id), is_py_data=False)
def isInViewPort(self) -> JsObjects.JsObject.JsObject: """ Description: ----------- Check if the component is in the visible part of the page (the viewport). :return: A Javascript boolean """ flag = JsBoolean.JsBoolean("!(rect.bottom < 0 || rect.top - viewHeight >= 0)", js_code="visibleFlag", set_var=True, is_py_data=False) flag._js.insert(0, self.component.js.viewHeight.setVar('viewHeight')) flag._js.insert(0, self.getBoundingClientRect().setVar("rect")) return JsFncs.JsAnonymous(flag.r).return_("visibleFlag").call()
def isInViewPort(self): """ Description: ----------- Check if the component is in the visible part of the page (the viewpport) :rtype: JsObject.JsObject :return: A Javascript boolean """ bool = JsBoolean.JsBoolean("!(rect.bottom < 0 || rect.top - viewHeight >= 0)", varName="visibleFlag", setVar=True, isPyData=False) bool._js.insert(0, self._report.js.viewHeight.setVar('viewHeight')) bool._js.insert(0, self.getBoundingClientRect().setVar("rect")) return JsFncs.JsAnonymous(bool.r).return_("visibleFlag").call()
def endsWith(self, searchvalue, length=None, jsFnc=None): """ The endsWith() method determines whether a string ends with the characters of a specified string. Documentation: https://www.w3schools.com/jsref/jsref_endswith.asp :param searchvalue: Required. The string to search for :param length: Optional. Specify the length of the string to search. If omitted, the default value is the length of the string :return: A Boolean. Returns true if the string ends with the value, otherwise it returns false """ from epyk.core.js.primitives import JsBoolean searchvalue = JsUtils.jsConvertData(searchvalue, jsFnc) if length is not None: return JsBoolean.JsBoolean("%s.endsWith(%s, %s)" % (self.varId, searchvalue, length), isPyData=False) return JsBoolean.JsBoolean("%s.endsWith(%s)" % (self.varId, searchvalue), isPyData=False)
def isNaN(self): """ Check whether the value is NaN Example string.parseFloat().isNaN() Documentation: https://www.w3schools.com/jsref/jsref_isnan_number.asp :return: A Javascript boolean """ from epyk.core.js.primitives import JsBoolean return JsBoolean.JsBoolean("Number.isNaN(%s)" % self.varId, isPyData=False)
def isFinite(self): """ Check whether a value is a finite number Example jsObj.objects.number.get("MyNumber").isFinite() Documentation https://www.w3schools.com/jsref/jsref_isfinite_number.asp :return: A Javascript boolean """ from epyk.core.js.primitives import JsBoolean return JsBoolean.JsBoolean("Number.isFinite(%s)" % self.varId, isPyData=False)
def isArray(self): """ The isArray() method determines whether an object is an array. Example jsObj.objects.get("MyObject").isArray() Documentation https://www.w3schools.com/jsref/jsref_isarray.asp :return: A Javascript Boolean """ from epyk.core.js.primitives import JsBoolean return JsBoolean.JsBoolean("Array.isArray(%s)" % self.varId, isPyData=False, setVar=False)
def effectAllowed(self, flag: Union[bool, primitives.JsDataModel] = False): """ Description: ----------- Related Pages: https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/effectAllowed """ if flag == False: return JsBoolean.JsBoolean("%s.effectAllowed" % self.varId) if flag not in [None, 'move', 'link', 'copy']: raise ValueError("") flag = JsUtils.jsConvertData(flag, None) return JsFncs.JsFunction("%s.effectAllowed = %s" % (self.varId, flag))
def some(self, jsFnc): """ The some() method checks if any of the elements in an array pass a test (provided as a function). Example Documentation https://www.w3schools.com/jsref/jsref_some.asp :param jsFnc: function(currentValue, index, arr) Required. A function to be run for each element in the array. :return: A Javascript Boolean """ from epyk.core.js.primitives import JsBoolean return JsBoolean.JsBoolean("%s.some(%s)" % (self.varId, jsFnc), isPyData=False)
def dropEffect(self, flag=False): """ Description: ----------- Related Pages: https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/dropEffect """ if flag == False: return JsBoolean.JsBoolean("%s.dropEffect" % self.varId) if flag not in [None, 'move', 'link', 'copy']: raise Exception("") flag = JsUtils.jsConvertData(flag, None) return JsFncs.JsFunction("%s.dropEffect = %s" % (self.varId, flag))
def isPointInPath(self, x: float, y: float): """ Description: ------------ The isPointInPath() method returns true if the specified point is in the current path, otherwise false. Related Pages: https://www.w3schools.com/tags/canvas_ispointinpath.asp Attributes: ---------- :param float x: The x-coordinate to test. :param float y: The y-coordinate to test. """ return JsBoolean.JsBoolean("%s.isPointInPath(%s, %s)" % (self.varId, x, y), is_py_data=False)
def isSealed(self): """ The Object.seal() method seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable. Values of present properties can still be changed as long as they are writable Example jsObj.objects.get("MyObject").isSealed() Documentation https://medium.com/@wlodarczyk_j/object-freeze-vs-object-seal-ba6d7553a436 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal :return: A Javascript Boolean """ from epyk.core.js.primitives import JsBoolean self._sealed = True return JsBoolean.JsBoolean("Object.isSealed(%s)" % self.varId, isPyData=False)
def isFrozen(self): """ The Object.isFrozen() determines if an object is frozen. Example jsObj.objects.get("MyObject").isFrozen() Documentation https://medium.com/@wlodarczyk_j/object-freeze-vs-object-seal-ba6d7553a436 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen :return: A Python Javascript Boolean """ if self.varName is None: raise Exception("Cannot freeze an object without variable name") from epyk.core.js.primitives import JsBoolean return JsBoolean.JsBoolean("Object.isFrozen(%s)" % self.varName, isPyData=False)
def isNaN(self): """ Description: ------------ Check whether the value is NaN Usage:: string.parseFloat().isNaN() Related Pages: https//www.w3schools.com/jsref/jsref_isnan_number.asp :return: A Javascript boolean """ from epyk.core.js.primitives import JsBoolean return JsBoolean.JsBoolean("Number.isNaN(%s)" % self.varId, isPyData=False)
def isFinite(self): """ Description: ------------ Check whether a value is a finite number Usage:: jsObj.objects.number.get("MyNumber").isFinite() Related Pages: https://www.w3schools.com/jsref/jsref_isfinite_number.asp :return: A Javascript boolean """ from epyk.core.js.primitives import JsBoolean return JsBoolean.JsBoolean("Number.isFinite(%s)" % self.varId, isPyData=False)
def some_(self, js_funcs: Union[list, str]): """ Description: ----------- The some() method checks if any of the elements in an array pass a test (provided as a function). Related Pages: https://www.w3schools.com/jsref/jsref_some.asp Attributes: ---------- :param js_funcs: function(currentValue, index, arr) A function to be run for each element in the array. :return: A Javascript Boolean """ from epyk.core.js.primitives import JsBoolean return JsBoolean.JsBoolean("%s.some(%s)" % (self.varId, js_funcs), is_py_data=False)
def isArray(self): """ Description: ------------ The isArray() method determines whether an object is an array. Usage:: jsObj.objects.get("MyObject").isArray() Related Pages: https://www.w3schools.com/jsref/jsref_isarray.asp :return: A Javascript Boolean """ from epyk.core.js.primitives import JsBoolean return JsBoolean.JsBoolean("Array.isArray(%s)" % self.varId, is_py_data=False, set_var=False)
def startsWith(self, searchvalue, start=0, jsFnc=None, jsObj=None): """ The startsWith() method determines whether a string begins with the characters of a specified string. This function might not work with older browser, so to guarantee a good compatibility the jsObj must be defined. Documentation: https://www.w3schools.com/jsref/jsref_startswith.asp :param searchvalue: Required. The string to search for :param start: Optional. Default 0. At which position to start the search :return: A Boolean. Returns true if the string starts with the value, otherwise it returns false """ from epyk.core.js.primitives import JsBoolean if jsObj is not None: # Add a polyfill to ensure the browser compatibility jsObj._addImport("babel-polyfill") searchvalue = JsUtils.jsConvertData(searchvalue, jsFnc) return JsBoolean.JsBoolean("%s.startsWith(%s, %s)" % (self.varId, searchvalue, start), isPyData=False)
def includes(self, searchvalue, start=0, jsFnc=None, jsObj=None): """ The includes() method determines whether a string contains the characters of a specified string. This function might not work with older browser, so to guarantee a good compatibility the jsObj must be defined. Related Pages: https//www.w3schools.com/jsref/jsref_includes.asp :param searchvalue: Required. The string to search for :param start: Optional. Default 0. At which position to start the search :param jsObj: Optional. The base Javascript object to add the pollyfill to the Javascript imports :return: A Boolean. Returns true if the string contains the value, otherwise it returns false """ from epyk.core.js.primitives import JsBoolean searchvalue = JsUtils.jsConvertData(searchvalue, jsFnc) if jsObj is not None: # Add a polyfill to ensure the browser compatibility jsObj._addImport("babel-polyfill") return JsBoolean.JsBoolean("%s.includes(%s, %s)" % (self.varId, searchvalue, start), isPyData=False)