الفرق بين المراجعتين ل"Cordova/cordova plugin screen orientation"
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE:إضافة اتجاه الشبكة في كوردوفا}}</noinclude> تصنيف: Cordova تصنيف: Plugin تُستخدم إضا...') |
|||
سطر 1: | سطر 1: | ||
<noinclude>{{DISPLAYTITLE:إضافة اتجاه الشبكة في كوردوفا}}</noinclude> | <noinclude>{{DISPLAYTITLE:إضافة اتجاه الشبكة في كوردوفا}}</noinclude> | ||
[[تصنيف: Cordova]] | [[تصنيف: Cordova]] | ||
− | [[تصنيف: Plugin]] | + | [[تصنيف: Plugin]] |
− | + | تُستخدم إضافة اتجاه الشبكة (<code>cordova-plugin-screen-orientation</code>) لتعيين أو قفل (lock) اتجاه الشاشة بطريقة مُوحّدة في المنصات iOS و أندرويد و منصة ويندوز الكونية (windows-uwp). تعتمد هذه الإضافة على [http://www.w3.org/TR/screen-orientation/ الواجهة البرمجية لاتجاه الشبكة]، حتى تتطابق مع المواصفات الحالية. | |
تضيف هذه الإضافة العناصر التالية إلى كائن الشاشة (<code>window.screen</code>): | تضيف هذه الإضافة العناصر التالية إلى كائن الشاشة (<code>window.screen</code>): | ||
− | <syntaxhighlight lang="javascript">// | + | <syntaxhighlight lang="javascript">// قفل توجيه الجهاز |
.orientation.lock('portrait') | .orientation.lock('portrait') | ||
− | // | + | // تحرير توجيه الجهاز |
.orientation.unlock() | .orientation.unlock() | ||
− | // | + | // الاتجاه الحالي |
.orientation</syntaxhighlight> | .orientation</syntaxhighlight> | ||
− | == التثبيت == | + | == التثبيت == |
− | <syntaxhighlight lang=" | + | يمكن تثبيت هذه الإضافة عبر الأمر التالي:<syntaxhighlight lang="shell">cordova plugin add cordova-plugin-screen-orientation</syntaxhighlight> |
− | == | + | == الاتجاهات المدعومة == |
− | === | + | ===<code>portrait-primary</code>=== |
− | الاتجاه | + | يمثل هذا الاتجاه الوضع العمودي الأولي (primary portrait mode). |
− | === | + | ===<code>portrait-secondary</code>=== |
− | + | الوضع العمودي الثانوي (secondary portrait mode). | |
− | === | + | ===<code>landscape-primary</code>=== |
− | + | الوضع الأفقي الأولي (primary landscape mode). | |
− | === | + | ===<code>landscape-secondary</code>=== |
− | + | الوضع الأفقي الثانوي (secondary landscape mode). | |
− | === | + | ===<code>portrait</code>=== |
− | + | الوضع العمودي الأولي أو الثانوي (sensor). | |
− | === | + | ===<code>landscape</code>=== |
− | + | الوضع الأفقي الأولي أو الثانوي (sensor). | |
− | === | + | ===<code>any</code>=== |
− | تحرير التوجيه، بحيث | + | تحرير التوجيه، بحيث تُدعم جميع الاتجاهات. |
− | ==الاستخدام== | + | ==طريقة الاستخدام== |
− | <syntaxhighlight lang="javascript">// | + | <syntaxhighlight lang="javascript">// تعين الاتجاه إلى أحد الوضعين الأفقيين |
screen.orientation.lock('landscape'); | screen.orientation.lock('landscape'); | ||
− | // | + | // إتاحة إدارة الاتجاه من قِبل المستخدم |
screen.orientation.unlock(); | screen.orientation.unlock(); | ||
− | // | + | // الحصول على الاتجاه الحالي |
console.log('Orientation is ' + screen.orientation.type);</syntaxhighlight> | console.log('Orientation is ' + screen.orientation.type);</syntaxhighlight> | ||
==الأحداث== | ==الأحداث== | ||
− | + | ستُطلق كلٌّ من منصتي أندرويد و iOS الحدث <code>orientationchange</code> من الكائن <code>window</code>. في هذا الإصدار من الإضافة، استخدم الكائن <code>window</code> إذا كنت تريد طريقة للتنبيه لتغيير الاتجاه. | |
− | === | + | === أمثلة === |
<syntaxhighlight lang="javascript">window.addEventListener("orientationchange", function(){ | <syntaxhighlight lang="javascript">window.addEventListener("orientationchange", function(){ | ||
− | console.log(screen.orientation.type); // | + | console.log(screen.orientation.type); // الوضع العمودي مثلا |
});</syntaxhighlight> | });</syntaxhighlight> | ||
− | + | في الشيفرة التالية سنُضيف مُنصتًا (listener) للحدث <code>change</code> في الكائن <code>screen.orientation</code>. <syntaxhighlight lang="javascript">screen.orientation.addEventListener('change', function(){ | |
− | + | console.log(screen.orientation.type); // الوضع العمودي مثلا | |
− | <syntaxhighlight lang="javascript">screen.orientation.addEventListener('change', function(){ | ||
− | console.log(screen.orientation.type); // | ||
}); | }); | ||
− | // | + | // أو |
screen.orientation.onchange = function(){console.log(screen.orientation.type); | screen.orientation.onchange = function(){console.log(screen.orientation.type); | ||
};</syntaxhighlight> | };</syntaxhighlight> | ||
سطر 58: | سطر 56: | ||
== ملاحظات حول أندرويد == | == ملاحظات حول أندرويد == | ||
− | لن تُحدّث الخاصية <code>screen.orientation</code> عندما | + | لن تُحدّث الخاصية <code>screen.orientation</code> عندما [http://www.quirksmode.org/dom/events/orientationchange.html يُدار الهاتف 180 درجة]. |
== ملاحظات حول منصة ويندوز الكونية UWP == | == ملاحظات حول منصة ويندوز الكونية UWP == | ||
− | لن تعرض تطبيقات متجر ويندوز (windows-uwp) تغييرات الاتجاه | + | لن تعرض تطبيقات متجر ويندوز (windows-uwp) تغييرات الاتجاه إلّا إن كان الجهاز مُزودًا بمقياسٍ للتسارع (accelerometer). ستُحفظ الحالة الداخلية للكائن <code>orientation</code>، ولكن لن يتم تدوير الشاشة فعليًا ما لم يكن الجهاز يدعم ذلك. |
+ | |||
+ | == سجل التغييرات == | ||
+ | يمكنك زيارة على [https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-screen-orientation/index.html#Changelog صفحة التوثيق الرسمي] لمطالعة تاريخ التغييرات على هذه الإضافة. | ||
+ | |||
+ | == انظر أيضا == | ||
+ | * إضافة <nowiki/>[[Cordova/cordova plugin device|حالة الجهاز]] | ||
+ | * إضافة [[Cordova/cordova plugin geolocation|تحديد الموقع الجغرافي]] | ||
+ | * [[Cordova/plugins|دليل تطوير الإضافات في كوردوفا]] | ||
==مصادر== | ==مصادر== | ||
*[https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-screen-orientation/index.html صفحة Cordova Screen Orientation Plugin في توثيق كوردوفا الرسمي.] | *[https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-screen-orientation/index.html صفحة Cordova Screen Orientation Plugin في توثيق كوردوفا الرسمي.] |
مراجعة 11:38، 22 ديسمبر 2018
تُستخدم إضافة اتجاه الشبكة (cordova-plugin-screen-orientation
) لتعيين أو قفل (lock) اتجاه الشاشة بطريقة مُوحّدة في المنصات iOS و أندرويد و منصة ويندوز الكونية (windows-uwp). تعتمد هذه الإضافة على الواجهة البرمجية لاتجاه الشبكة، حتى تتطابق مع المواصفات الحالية.
تضيف هذه الإضافة العناصر التالية إلى كائن الشاشة (window.screen
):
// قفل توجيه الجهاز
.orientation.lock('portrait')
// تحرير توجيه الجهاز
.orientation.unlock()
// الاتجاه الحالي
.orientation
التثبيت
يمكن تثبيت هذه الإضافة عبر الأمر التالي:
cordova plugin add cordova-plugin-screen-orientation
الاتجاهات المدعومة
portrait-primary
يمثل هذا الاتجاه الوضع العمودي الأولي (primary portrait mode).
portrait-secondary
الوضع العمودي الثانوي (secondary portrait mode).
landscape-primary
الوضع الأفقي الأولي (primary landscape mode).
landscape-secondary
الوضع الأفقي الثانوي (secondary landscape mode).
portrait
الوضع العمودي الأولي أو الثانوي (sensor).
landscape
الوضع الأفقي الأولي أو الثانوي (sensor).
any
تحرير التوجيه، بحيث تُدعم جميع الاتجاهات.
طريقة الاستخدام
// تعين الاتجاه إلى أحد الوضعين الأفقيين
screen.orientation.lock('landscape');
// إتاحة إدارة الاتجاه من قِبل المستخدم
screen.orientation.unlock();
// الحصول على الاتجاه الحالي
console.log('Orientation is ' + screen.orientation.type);
الأحداث
ستُطلق كلٌّ من منصتي أندرويد و iOS الحدث orientationchange
من الكائن window
. في هذا الإصدار من الإضافة، استخدم الكائن window
إذا كنت تريد طريقة للتنبيه لتغيير الاتجاه.
أمثلة
window.addEventListener("orientationchange", function(){
console.log(screen.orientation.type); // الوضع العمودي مثلا
});
في الشيفرة التالية سنُضيف مُنصتًا (listener) للحدث change
في الكائن screen.orientation
.
screen.orientation.addEventListener('change', function(){
console.log(screen.orientation.type); // الوضع العمودي مثلا
});
// أو
screen.orientation.onchange = function(){console.log(screen.orientation.type);
};
ملاحظات حول أندرويد
لن تُحدّث الخاصية screen.orientation
عندما يُدار الهاتف 180 درجة.
ملاحظات حول منصة ويندوز الكونية UWP
لن تعرض تطبيقات متجر ويندوز (windows-uwp) تغييرات الاتجاه إلّا إن كان الجهاز مُزودًا بمقياسٍ للتسارع (accelerometer). ستُحفظ الحالة الداخلية للكائن orientation
، ولكن لن يتم تدوير الشاشة فعليًا ما لم يكن الجهاز يدعم ذلك.
سجل التغييرات
يمكنك زيارة على صفحة التوثيق الرسمي لمطالعة تاريخ التغييرات على هذه الإضافة.