Fragment

Fragments. Fragment

Codestrate Fragment representing a tag in codestrates.

Members

auto :boolean

Description:
  • The auto attribute of this fragment, toggles automatic behaviour on/off
Source:
The auto attribute of this fragment, toggles automatic behaviour on/off
Type:
  • boolean

raw :string

Description:
  • The raw representation of this fragment, can be used to set/get the raw value.
Source:
The raw representation of this fragment, can be used to set/get the raw value.
Type:
  • string
Examples
//Get the raw value of a fragment
let fragmentValue = myFragment.raw;
//Set the raw value of a fragment
myFragment.raw = myNewFragmentValue;

(readonly) type :string

Description:
  • The type of this fragment
Source:
The type of this fragment
Type:
  • string

Methods

getDomPath()

Description:
  • Returns a dompath for finding this fragment
Source:

registerOnAutoChangedHandler(callback)

Description:
  • Register a callback to run when auto attribute changes on fragment
Source:
Example
Fragment.one("#myFragment").registerOnAutoChangedHandler((fragment, auto)=>{
    //Fragment auto attribute changed
});
Parameters:
Name Type Description
callback Fragments.Fragment~autoChangedCallback The callback to run when auto changes

registerOnClassChangedHandler(callback)

Description:
  • Register a callback to run when the classes of this fragment changes
Source:
Example
Fragment.one("#myFragment").registerOnClassChangedHandler((classes)=>{
    //Some classes changed on this fragment
});
Parameters:
Name Type Description
callback Fragments.Fragment~fragmentClassChangedCallback The callback to run when classes change on the fragment

registerOnFragmentChangedHandler(callback)

Description:
  • Register a callback to be run when this fragments content changes.
Source:
Example
Fragment.one("#myFragment").registerOnFragmentChangedHandler((context)=>{
    //Fragment has changed
});
Parameters:
Name Type Description
callback Fragments.Fragment~fragmentChangedCallback The callback that is run when fragment content changes

registerOnFragmentUnloadedHandler(callback)

Description:
  • Register a callback to run when this fragment is unloaded
Source:
Example
Fragment.one("#myFragment").registerOnFragmentUnloadedHandler(()=>{
    //Fragment is unloaded
});
Parameters:
Name Type Description
callback Fragments.Fragment~fragmentUnloadedCallback The callback to run when the fragment is unloaded

registerOnTextDeletedHandler(callback)

Description:
  • Register a callback to run when text is deleted from this fragment
Source:
Example
Fragment.one("#myFragment").registerOnTextDeletedHandler((position, value)=>{
    //Text "value" has been deleted from this fragment at "position"
});
Parameters:
Name Type Description
callback Fragments.Fragment~textDeletedCallback The callback to run when text is deleted

registerOnTextInsertedHandler(callback)

Description:
  • Register a callback to run when text is inserted into this fragment
Source:
Example
Fragment.one("#myFragment").registerOnTextInsertedHandler((position, value)=>{
    //Text "value" has been inserted into this fragment at "position"
});
Parameters:
Name Type Description
callback Fragments.Fragment~textInsertedCallback The callback to run when text is inserted

(async, abstract) require(optionsopt) → {*}

Description:
  • Require this fragment and return the result. What require does depends on what type of fragment it is.
Source:
Example
let result = await Fragment.one("#myFragment").require()
Parameters:
Name Type Attributes Description
options json <optional>
The options to pass to require
Returns:
result of the require action
Type
*

unRegisterOnAutoChangedHandler(callback)

Description:
  • Unregister a callback handler
Source:
Parameters:
Name Type Description
callback Fragments.Fragment~autoChangedCallback The callback to unregister

unRegisterOnFragmentChangedHandler(callback)

Description:
  • Unregister a callback handler
Source:
Parameters:
Name Type Description
callback Fragments.Fragment~fragmentChangedCallback The callback to unregister

unRegisterOnFragmentUnloadedHandler(callback)

Description:
  • Unregister a callback handler
Source:
Parameters:
Name Type Description
callback Fragments.Fragment~fragmentUnloadedCallback The callback to unregister

unload()

Description:
  • Tell this fragment to unload itself
Source:
Example
Fragment.one("#myFragment").unload();

(static) create(type) → {Fragments.Fragment}

Description:
  • Create a fragment of the given type. If no Fragment is registered for the given type, null is returned.
Source:
Example
let myJSFragment = Fragment.create("text/javascript");
Parameters:
Name Type Description
type string the type of fragment to create
Returns:
the created fragment, or null
Type
Fragments.Fragment

(static) find(query) → {Array.<Fragments.Fragment>}

Description:
  • Finds all fragments based on a given query
Source:
Example
let fragments = Fragment.find(".someClass");
Parameters:
Name Type Description
query string | cQuery | Array | Node The query used to find fragments. Can be a css selector, a cQuery object, a dom element or an array of dom elements.
Returns:
The found fragments
Type
Array.<Fragments.Fragment>

(static) one(query) → {Fragments.Fragment}

Description:
  • Returns the first fragment that is found from the given query This is the equivalent of taking the first result of Fragment.find(query)
Source:
Example
let myFragment = Fragment.one("#myFragment");
Parameters:
Name Type Description
query string | cQuery | Array | Node The query used to find fragments. Can be a css selector, a cQuery object, a dom element or an array of dom elements.
Returns:
- the found fragment, or null if none could be found
Type
Fragments.Fragment

Type Definitions

autoChangedCallback(fragment, auto)

Source:
Parameters:
Name Type Description
fragment Fragments.Fragment The fragment
auto boolean The new value of auto

fragmentChangedCallback(context)

Source:
Parameters:
Name Type Description
context Fragment | Object The context that called the callback

fragmentClassChangedCallback(classes)

Source:
Parameters:
Name Type Description
classes Array.<string> The classes that changed

fragmentUnloadedCallback(fragment)

Source:
Parameters:
Name Type Description
fragment Fragments.Fragment The fragment that called the callback

textDeletedCallback(position, value)

Source:
Parameters:
Name Type Description
position number The position where the text was deleted
value string The value of deleted text

textInsertedCallback(position, value)

Source:
Parameters:
Name Type Description
position number The position where the text was inserted
value string The value of inserted text