تثبيت الويدجت
طرق مختلفة لإضافة ويدجت SalonBookIt إلى موقعك.
عبر CDN (موصى به)
أبسط طريقة هي تحميل الويدجت مباشرة من CDN الخاص بنا:
HTML
<!-- في نهاية body -->
<script src="https://app.salonbookit.com/static/widget/v1/salonbookit-widget.min.js"></script>
الإصدارات
CDN يخدم دائماً أحدث إصدار مستقر. لتثبيت إصدار معين، استخدم /widget/v1.2.3/salonbookit-widget.min.js
الملفات المتاحة
| الملف | الحجم | الوصف |
|---|---|---|
salonbookit-widget.min.js |
~25KB | سكريبت مضغوط (إنتاج) |
salonbookit-widget.js |
~50KB | سكريبت غير مضغوط (تطوير) |
salonbookit-widget.css |
~10KB | الأنماط (مضمنة بالفعل في JS) |
عبر NPM قريباً
قيد التطوير
حزمة NPM @salonbookit/widget ستكون متاحة قريباً. في الوقت الحالي، استخدم CDN أو تنزيل الملفات.
عندما تكون متاحة، يمكنك تثبيتها هكذا:
Terminal
npm install @salonbookit/widget
JavaScript
import SalonBookIt from '@salonbookit/widget';
SalonBookIt.init({
apiKey: 'مفتاح_API_الخاص_بك',
container: '#salonbookit-widget'
});
استضافة ذاتية
يمكنك تنزيل الويدجت واستضافته على خادمك الخاص:
- تنزيل أحدث إصدار من salonbookit.com/downloads/widget
- استخرج الملفات في مجلد الأصول الخاص بك
- أشر إلى السكريبت في HTML الخاص بك
HTML
<script src="/assets/js/salonbookit-widget.min.js"></script>
التحديثات
عند الاستضافة الذاتية، أنت مسؤول عن تحديث الويدجت. نوصي بمراجعة التحديثات شهرياً.
منصات CMS
WordPress
أضف الكود في كتلة HTML مخصصة أو في footer القالب:
PHP (functions.php)
function salonbookit_widget_scripts() {
wp_enqueue_script(
'salonbookit-widget',
'https://app.salonbookit.com/static/widget/v1/salonbookit-widget.min.js',
array(),
'1.0',
true
);
}
add_action('wp_enqueue_scripts', 'salonbookit_widget_scripts');
Wix
- اذهب إلى Settings → Custom Code
- أضف كوداً مخصصاً جديداً
- الصق كود الويدجت
- Selecciona "Body - End"
Squarespace
- اذهب إلى Settings → Advanced → Code Injection
- Pega el código en la sección "Footer"
- أضف كتلة HTML حيث تريد عرض الويدجت
Shopify
- اذهب إلى Online Store → Themes → Edit Code
- افتح
theme.liquid - أضف السكريبت قبل
</body>
أطر JavaScript
React
JSX
import { useEffect, useRef } from 'react';
function BookingWidget({ apiKey }) {
const containerRef = useRef(null);
useEffect(() => {
// تحميل السكريبت إذا لم يكن موجوداً
if (!window.SalonBookIt) {
const script = document.createElement('script');
script.src = 'https://app.salonbookit.com/static/widget/v1/salonbookit-widget.min.js';
script.async = true;
script.onload = () => initWidget();
document.body.appendChild(script);
} else {
initWidget();
}
function initWidget() {
window.SalonBookIt.init({
apiKey: apiKey,
container: containerRef.current,
onBookingComplete: (booking) => {
console.log('تم إنشاء الحجز:', booking);
}
});
}
return () => {
// Cleanup إذا لزم الأمر
};
}, [apiKey]);
return <div ref={containerRef} />;
}
export default BookingWidget;
Vue.js
Vue
<template>
<div ref="widgetContainer"></div>
</template>
<script>
export default {
name: 'BookingWidget',
props: {
apiKey: {
type: String,
required: true
}
},
mounted() {
this.loadWidget();
},
methods: {
loadWidget() {
if (window.SalonBookIt) {
this.initWidget();
} else {
const script = document.createElement('script');
script.src = 'https://app.salonbookit.com/static/widget/v1/salonbookit-widget.min.js';
script.onload = () => this.initWidget();
document.body.appendChild(script);
}
},
initWidget() {
window.SalonBookIt.init({
apiKey: this.apiKey,
container: this.$refs.widgetContainer,
onBookingComplete: (booking) => {
this.$emit('booking-complete', booking);
}
});
}
}
}
</script>
حل المشاكل
الويدجت لا يظهر
- تحقق من وجود الحاوية في DOM قبل استدعاء
init() - تحقق من وحدة تحكم المتصفح للأخطاء
- تأكد من أن مفتاح API صحيح
خطأ CORS
تأكد من أن نطاقك في قائمة الأصول المسموح بها لمفتاح API في لوحة التحكم.
السكريبت لا يحمّل
- تحقق من عنوان CDN
- تحقق من عدم وجود حاجبات سكريبتات
- راجع تبويب Network في أدوات المطور