$_bx Library Documentation
The $_bx library is the core JavaScript API for coob.app plugin development. It provides a comprehensive set of methods for plugin-state management, UI interactions, file uploads, messaging, and sys
🔧 Core Properties
state
state
Type:
Object
Description: The main plugin state object containing all plugin data
Usage:
$_bx.state.propertyName
global
global
Type:
Object
Description: Global system state including user info, answer status, and UI controls
Properties:
answerRequired
: Boolean - whether answer is requiredassignmentRequired
: Boolean - whether assignment is requiredhasAnswer
: Boolean - whether answer is presentanswerMessage
: String - feedback messageuser
: Object - user information (id, firstName, lastName, email, avatar)saveButtonEnabled
: Boolean - save button state
📊 State Management Methods
getState()
getState()
Returns:
Object
- complete plugin stateDescription: Retrieves the current plugin state
Usage:
const state = $_bx.getState()
get(key)
get(key)
Parameters:
key
(String) - dot-notation path to state propertyReturns:
Any
- value at the specified pathDescription: Gets a nested state property using dot notation
Usage:
const value = $_bx.get('nested.property')
push(key, value)
push(key, value)
Parameters:
key
(String) - state property namevalue
(Any) - value to set
Returns:
Promise
- event emission promiseDescription: Sets a state property and emits change events
Events:
before_push
,change_${key}
,after_push
Usage:
$_bx.push('title', 'New Title')
clean(key)
clean(key)
Parameters:
key
(String) - state property nameReturns:
Promise
- event emission promiseDescription: Clears a state property by setting it to empty string
Events:
before_clean
,after_clean
Usage:
$_bx.clean('content')
async saveState()
async saveState()
Returns:
Promise<void>
Description: Saves the current state to the system (syllabus mode only)
Events:
before_save_state
,after_save_state
Usage:
await $_bx.saveState()
putState()
putState()
Description: Sends state to parent system with settings
Events:
before_put_state
,after_put_state
Usage:
$_bx.putState()
⚙️ Settings Management
getSettings(key = null)
getSettings(key = null)
Parameters:
key
(String, optional) - specific setting keyReturns:
Object|Any
- settings object or specific setting valueDescription: Retrieves plugin settings from state._settings
Usage:
const allSettings = $_bx.getSettings(); const specificSetting = $_bx.getSettings('theme');
🎯 Answer & Assessment Methods
isCorrect()
isCorrect()
Returns:
Boolean
- whether the answer is correctDescription: Checks if the current answer is marked as correct
Usage:
if ($_bx.isCorrect()) { ... }
answerSubmit()
answerSubmit()
Returns:
Promise<Object>
- submission resultDescription: Submits the current answer for evaluation
Events:
before_submit
,after_submit
Usage:
try { const result = await $_bx.answerSubmit(); console.log('Submission successful:', result); } catch (error) { console.error('Submission failed:', error); }
isAnswerRequired()
isAnswerRequired()
Returns:
Boolean
- whether answer is requiredDescription: Checks if the plugin requires an answer
Usage:
if ($_bx.isAnswerRequired()) { ... }
isAssignmentRequired()
isAssignmentRequired()
Returns:
Boolean
- whether assignment is requiredDescription: Checks if the plugin requires an assignment submission
Usage:
if ($_bx.isAssignmentRequired()) { ... }
hasAnswer()
hasAnswer()
Returns:
Boolean
- whether answer is presentDescription: Checks if user has provided an answer
Usage:
if ($_bx.hasAnswer()) { ... }
answerMessage()
answerMessage()
Returns:
String
- feedback messageDescription: Gets the current answer feedback message
Usage:
const message = $_bx.answerMessage()
parseMessage()
parseMessage()
Returns:
Object
- parsed message with type and contentDescription: Parses answer message to extract type and content
Returns:
{type: 'success|feedback|wrong|info', content: String}
Usage:
const parsed = $_bx.parseMessage()
isPendingApproval()
isPendingApproval()
Returns:
Boolean
- whether answer is pending approvalDescription: Checks if answer requires manual approval
Usage:
if ($_bx.isPendingApproval()) { ... }
👤 User & System Information
getUser()
getUser()
Returns:
Object
- user informationDescription: Gets current user information
Properties:
{id, firstName, lastName, email, avatar}
Usage:
const user = $_bx.getUser()
getComponentID()
getComponentID()
Returns:
String
- component identifierDescription: Gets the current component ID
Usage:
const id = $_bx.getComponentID()
getResponseId()
getResponseId()
Returns:
String
- response identifierDescription: Gets the current response ID
Usage:
const responseId = $_bx.getResponseId()
mode()
mode()
Returns:
String
- 'light' or 'dark'Description: Gets current theme mode
Usage:
const mode = $_bx.mode()
language()
language()
Returns:
String
- language code (e.g., 'en', 'ru')Description: Gets current language setting
Usage:
const lang = $_bx.language()
isSyllabus()
isSyllabus()
Returns:
Boolean
- whether in syllabus modeDescription: Checks if component is in syllabus/editing mode
Usage:
if ($_bx.isSyllabus()) { ... }
🎨 Theme & UI Methods
isDark()
isDark()
Returns:
Boolean
- whether dark theme is activeDescription: Checks if dark mode is enabled
Usage:
if ($_bx.isDark()) { ... }
isLight()
isLight()
Returns:
Boolean
- whether light theme is activeDescription: Checks if light mode is enabled
Usage:
if ($_bx.isLight()) { ... }
setSaveButtonEnabled(value)
setSaveButtonEnabled(value)
Parameters:
value
(Boolean) - enable/disable save buttonDescription: Controls the save button state
Usage:
$_bx.setSaveButtonEnabled(false)
isSaveButtonEnabled()
isSaveButtonEnabled()
Returns:
Boolean
- save button stateDescription: Checks if save button is enabled
Usage:
if ($_bx.isSaveButtonEnabled()) { ... }
📤 Messaging & Communication
sendMessage(e)
sendMessage(e)
Parameters:
e
(String|Object) - message to sendDescription: Sends message to parent window
Usage:
$_bx.sendMessage(JSON.stringify({type: 'custom', data: 'value'}))
event()
event()
Returns:
EventEmitter
- event emitter instanceDescription: Gets the event emitter for custom events
Usage:
$_bx.event().on('custom_event', (data) => { console.log('Custom event:', data); }); $_bx.event().emit('custom_event', {data: 'value'});
📁 File Upload Methods
uploadFile(blob, onProgress, originalFileName)
uploadFile(blob, onProgress, originalFileName)
Parameters:
blob
(Blob) - file to uploadonProgress
(Function, optional) - progress callbackoriginalFileName
(String, optional) - original filename
Returns:
Promise<Object>
- upload resultDescription: Uploads a file and returns file information
Usage:
const result = await $_bx.uploadFile(fileBlob, (progress) => { console.log('Upload progress:', progress); }, 'document.pdf'); // Returns: {fileURL, fileSize, fileID}
uploadImage(blob)
uploadImage(blob)
Parameters:
blob
(Blob) - image file to uploadReturns:
Promise<String>
- image URLDescription: Uploads an image and returns the URL
Usage:
const imageUrl = await $_bx.uploadImage(imageBlob)
uploadVideo(blob, onProgress)
⚠️ DEPRECATED
uploadVideo(blob, onProgress)
⚠️ DEPRECATEDParameters:
blob
(Blob) - video file to uploadonProgress
(Function, optional) - progress callback
Returns:
Promise<Object>
- upload resultDescription: Uploads a video (deprecated, use uploadTVideo)
Usage:
const result = await $_bx.uploadVideo(videoBlob)
uploadTVideo(blob, mimeType, onProgress)
uploadTVideo(blob, mimeType, onProgress)
Parameters:
blob
(Blob) - video file to uploadmimeType
(String) - video MIME typeonProgress
(Function, optional) - progress callback
Returns:
Promise<Object>
- upload resultDescription: Uploads a video with MIME type specification
Usage:
const result = await $_bx.uploadTVideo(videoBlob, 'video/mp4', (progress) => { console.log('Video upload progress:', progress); }); // Returns: {videoURL, thumbnail, videoID}
fetchFile(fileId)
fetchFile(fileId)
Parameters:
fileId
(String) - file identifierReturns:
Promise<Object>
- file informationDescription: Retrieves file information by ID
Usage:
const file = await $_bx.fetchFile('file_123')
🖥️ UI & Display Methods
refreshHeight()
refreshHeight()
Description: Automatically adjusts iframe height based on content
Usage:
$_bx.refreshHeight()
fixView()
fixView()
Description: Requests view fix from parent system
Usage:
$_bx.fixView()
contentLoaded()
contentLoaded()
Description: Notifies system that content has loaded
Usage:
$_bx.contentLoaded()
scroll(scrollTop)
scroll(scrollTop)
Parameters:
scrollTop
(Number) - scroll positionDescription: Sends scroll position to parent system
Usage:
$_bx.scroll(500)
💬 Message Box & Modal Methods
showMessageBox(variant, message)
showMessageBox(variant, message)
Parameters:
variant
(String) - 'success', 'error', 'warning', 'info'message
(String) - message text
Description: Shows a message box with specified variant
Usage:
$_bx.showMessageBox('success', 'Operation completed!')
showModal(title, message)
showModal(title, message)
Parameters:
title
(String) - modal titlemessage
(String) - modal message
Description: Shows a modal dialog
Usage:
$_bx.showModal('Confirm', 'Are you sure?')
dangerouslyShowModal(title, html)
dangerouslyShowModal(title, html)
Parameters:
title
(String) - modal titlehtml
(String) - HTML content
Description: Shows a modal with custom HTML content
Usage:
$_bx.dangerouslyShowModal('Custom', '<div>Custom HTML</div>')
showSuccessMessage(message)
showSuccessMessage(message)
Parameters:
message
(String) - success messageDescription: Shows a success message box
Usage:
$_bx.showSuccessMessage('Saved successfully!')
showErrorMessage(message)
showErrorMessage(message)
Parameters:
message
(String) - error messageDescription: Shows an error message box and throws error
Usage:
$_bx.showErrorMessage('Operation failed!')
showWarningMessage(message)
showWarningMessage(message)
Parameters:
message
(String) - warning messageDescription: Shows a warning message box
Usage:
$_bx.showWarningMessage('Please check your input')
showInfoMessage(message)
showInfoMessage(message)
Parameters:
message
(String) - info messageDescription: Shows an info message box
Usage:
$_bx.showInfoMessage('Please wait...')
⚙️ Settings & Configuration
isShowSettings()
isShowSettings()
Returns:
Boolean
- whether settings dialog should be shownDescription: Checks if plugin has settings configuration
Usage:
if ($_bx.isShowSettings()) { ... }
showSettings()
showSettings()
Description: Opens the settings dialog (syllabus mode only)
Usage:
$_bx.showSettings()
showAbout()
showAbout()
Description: Shows plugin information dialog (syllabus mode only)
Usage:
$_bx.showAbout()
🔄 System Control Methods
reset()
reset()
Description: Resets the plugin state (syllabus mode only)
Usage:
$_bx.reset()
_doubleClickEdit()
_doubleClickEdit()
Description: Triggers double-click edit mode
Usage:
$_bx._doubleClickEdit()
_onClick()
_onClick()
Description: Triggers click event
Usage:
$_bx._onClick()
⏰ Lifecycle & Ready Methods
onReady(callback)
onReady(callback)
Parameters:
callback
(Function) - function to execute when readyDescription: Executes callback when DOM and data are ready
Usage:
$_bx.onReady((element) => { console.log('Plugin is ready:', element); });
waitForElement(elementId, callback)
waitForElement(elementId, callback)
Parameters:
elementId
(String) - element ID to wait forcallback
(Function) - function to execute when element is found
Description: Waits for specific element to appear in DOM
Usage:
$_bx.waitForElement('my-element', (element) => { console.log('Element found:', element); });
📝 Usage Examples
Basic State Management
// Get state
const state = $_bx.getState();
// Set state property
$_bx.push('title', 'My Plugin Title');
// Get nested property
const content = $_bx.get('content.text');
// Save state
await $_bx.saveState();
File Upload
// Upload file with progress
const fileInput = document.getElementById('file-input');
const file = fileInput.files[0];
if (file) {
try {
const result = await $_bx.uploadFile(file, (progress) => {
console.log(`Upload progress: ${progress}%`);
});
console.log('File uploaded:', result.fileURL);
} catch (error) {
console.error('Upload failed:', error);
}
}
Answer Submission
// Submit answer
try {
const result = await $_bx.answerSubmit();
if ($_bx.isCorrect()) {
$_bx.showSuccessMessage('Correct answer!');
} else {
const message = $_bx.answerMessage();
$_bx.showInfoMessage(message);
}
} catch (error) {
$_bx.showErrorMessage('Submission failed');
}
Event Handling
// Listen for state changes
$_bx.event().on('change_title', (data) => {
console.log('Title changed from', data.old_value, 'to', data.new_value);
});
// Listen for before save
$_bx.event().on('before_save_state', (data) => {
console.log('Saving state:', data);
});
Theme Detection
// Check theme and apply styles
if ($_bx.isDark()) {
document.body.classList.add('dark-theme');
} else {
document.body.classList.add('light-theme');
}
// Check language
const lang = $_bx.language();
if (lang === 'ru') {
// Apply Russian translations
}
⚠️ Important Notes
Syllabus Mode: Some methods only work in syllabus/editing mode (
isSyllabus()
returns true)Async Operations: File uploads and answer submission are asynchronous
Error Handling: Always wrap async operations in try-catch blocks
Event Cleanup: Remove event listeners when components are destroyed
Height Management: Call
refreshHeight()
after dynamic content changesState Validation: Validate state before saving or submitting
🔄 Version History
Current Version: 1.0
Last Updated: 2024
Deprecated Methods:
uploadVideo()
- useuploadTVideo()
instead
This documentation covers all public methods and properties of the $_bx library. For internal implementation details, refer to the source code.
Last updated