slideshow.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522
  1. /**
  2. * The slideshow dialog definition.
  3. * Copyright (c) 2003-2013, Cricri042. All rights reserved.
  4. * Targeted for "ad-gallery" JavaScript : http://adgallery.codeplex.com/
  5. * And "Fancybox" : http://fancyapps.com/fancybox/
  6. */
  7. /**
  8. * Debug : var_dump
  9. *
  10. * @var: Var
  11. * @level: Level max
  12. *
  13. */
  14. function removeDomainFromUrl(string) {
  15. "use strict";
  16. return string.replace(/^https?:\/\/[^\/]+/i, '');
  17. }
  18. var IMG_PARAM = {URL:0, TITLE:1, ALT:2, WIDTH:3, HEIGHT:4},
  19. pluginPath = '//lib.amic.ru/js/'; //removeDomainFromUrl(CKEDITOR.plugins.get( 'slideshow' ).path),
  20. BASE_PATH = removeDomainFromUrl(CKEDITOR.basePath),
  21. //SCRIPT_JQUERY = "https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js",
  22. SCRIPT_JQUERY = pluginPath+"3rdParty/jquery.min.js",
  23. SCRIPT_ADDGAL = pluginPath+"3rdParty/ad-gallery/jquery.ad-gallery.min.js",
  24. CSS_ADDGAL = pluginPath+"3rdParty/ad-gallery/jquery.ad-gallery.css",
  25. SCRIPT_FANCYBOX = pluginPath+'3rdParty/fancybox2/jquery.fancybox.pack.js?v=2.1.5',
  26. CSS_FANCYBOX = pluginPath+"3rdParty/fancybox2/jquery.fancybox.css?v=2.1.5";
  27. function var_dump(_var, _level) {
  28. "use strict";
  29. var dumped_text = "";
  30. if(!_level) {
  31. _level = 0;
  32. }
  33. //The padding given at the beginning of the line.
  34. var level_padding = "";
  35. var j;
  36. for(j=0; j<_level+1; j+=1) {
  37. level_padding += " ";
  38. }
  39. if(typeof(_var) == 'object') { //Array/Hashes/Objects
  40. var item;
  41. var value;
  42. for(item in _var) {
  43. if (_var.hasOwnProperty(item)) {
  44. value = _var[item];
  45. if(typeof(value) == 'object') { // If it is an array,
  46. dumped_text += level_padding + "'" + item + "' ...\n";
  47. dumped_text += var_dump(value, _level+1);
  48. } else {
  49. dumped_text += level_padding +"'"+ item +"' => \""+ value +"\"\n";
  50. }
  51. }
  52. }
  53. } else { //Stings/Chars/Numbers etc.
  54. dumped_text = "===>"+ _var +"<===("+ typeof(_var) +")";
  55. }
  56. return dumped_text;
  57. }
  58. var listItem = function( node ) {
  59. "use strict";
  60. return node.type == CKEDITOR.NODE_ELEMENT && node.is( 'li' );
  61. };
  62. var ULItem = function( node ) {
  63. "use strict";
  64. return node.type == CKEDITOR.NODE_ELEMENT && node.is( 'ul' );
  65. };
  66. var iFrameItem = function( node ) {
  67. "use strict";
  68. return node.type == CKEDITOR.NODE_ELEMENT && node.is( 'iframe' );
  69. };
  70. Array.prototype.pushUnique = function (item){
  71. "use strict";
  72. var i;
  73. for ( i = 0; i < this.length ; i+=1 ) {
  74. if (this[i][0] == item[0]) {
  75. return -1;
  76. }
  77. }
  78. this.push(item);
  79. return this.length - 1;
  80. };
  81. Array.prototype.updateVal = function (item, data){
  82. "use strict";
  83. var i;
  84. for ( i = 0; i < this.length ; i+=1 ) {
  85. if (this[i][0] == item) {
  86. this[i] = [item, data];
  87. return true;
  88. }
  89. }
  90. this[i] = [item, data];
  91. return false;
  92. };
  93. Array.prototype.getVal = function (item){
  94. "use strict";
  95. var i;
  96. for ( i = 0; i < this.length ; i+=1 ) {
  97. if (this[i][0] == item) {
  98. return this[i][1];
  99. }
  100. }
  101. return null;
  102. };
  103. // Our dialog definition.
  104. CKEDITOR.dialog.add( 'slideshowDialog', function( editor ) {
  105. "use strict";
  106. var lang = editor.lang.slideshow;
  107. //----------------------------------------------------------------------------------------------------
  108. // COMBO STUFF
  109. //----------------------------------------------------------------------------------------------------
  110. // Add a new option to a CHKBOX object (combo or list).
  111. function addOption( combo, optionText, optionValue, documentObject, index )
  112. {
  113. combo = getSelect( combo );
  114. var oOption;
  115. if ( documentObject ) {
  116. oOption = documentObject.createElement( "OPTION" );
  117. } else {
  118. oOption = document.createElement( "OPTION" );
  119. }
  120. if ( combo && oOption && oOption.getName() == 'option' )
  121. {
  122. if ( CKEDITOR.env.ie ) {
  123. if ( !isNaN( parseInt( index, 10) ) ) {
  124. combo.$.options.add( oOption.$, index );
  125. } else {
  126. combo.$.options.add( oOption.$ );
  127. }
  128. oOption.$.innerHTML = optionText.length > 0 ? optionText : '';
  129. oOption.$.value = optionValue;
  130. } else {
  131. if ( index !== null && index < combo.getChildCount() ) {
  132. combo.getChild( index < 0 ? 0 : index ).insertBeforeMe( oOption );
  133. } else {
  134. combo.append( oOption );
  135. }
  136. oOption.setText( optionText.length > 0 ? optionText : '' );
  137. oOption.setValue( optionValue );
  138. }
  139. } else {
  140. return false;
  141. }
  142. return oOption;
  143. }
  144. // Remove all selected options from a CHKBOX object.
  145. function removeSelectedOptions( combo )
  146. {
  147. combo = getSelect( combo );
  148. // Save the selected index
  149. var iSelectedIndex = getSelectedIndex( combo );
  150. // Remove all selected options.
  151. var i;
  152. for ( i = combo.getChildren().count() - 1 ; i >= 0 ; i-=1 )
  153. {
  154. if ( combo.getChild( i ).$.selected ) {
  155. combo.getChild( i ).remove();
  156. }
  157. }
  158. // Reset the selection based on the original selected index.
  159. setSelectedIndex( combo, iSelectedIndex );
  160. }
  161. //Modify option from a CHKBOX object.
  162. function modifyOption( combo, index, title, value )
  163. {
  164. combo = getSelect( combo );
  165. if ( index < 0 ) {
  166. return false;
  167. }
  168. var child = combo.getChild( index );
  169. child.setText( title );
  170. child.setValue( value );
  171. return child;
  172. }
  173. function removeAllOptions( combo )
  174. {
  175. combo = getSelect( combo );
  176. while ( combo.getChild( 0 ) && combo.getChild( 0 ).remove() )
  177. { /*jsl:pass*/ }
  178. }
  179. // Moves the selected option by a number of steps (also negative).
  180. function changeOptionPosition( combo, steps, documentObject, dialog )
  181. {
  182. combo = getSelect( combo );
  183. var iActualIndex = getSelectedIndex( combo );
  184. if ( iActualIndex < 0 ) {
  185. return false;
  186. }
  187. var iFinalIndex = iActualIndex + steps;
  188. iFinalIndex = ( iFinalIndex < 0 ) ? 0 : iFinalIndex;
  189. iFinalIndex = ( iFinalIndex >= combo.getChildCount() ) ? combo.getChildCount() - 1 : iFinalIndex;
  190. if ( iActualIndex == iFinalIndex ) {
  191. return false;
  192. }
  193. var re = /(^IMG_\d+)/;
  194. // Modify sText in final index
  195. var oOption = combo.getChild( iFinalIndex ),
  196. sText = oOption.getText(),
  197. sValue = oOption.getValue();
  198. sText = sText.replace(re, "IMG_"+iActualIndex);
  199. modifyOption( combo, iFinalIndex, sText, sValue );
  200. // do the move
  201. oOption = combo.getChild( iActualIndex );
  202. sText = oOption.getText();
  203. sValue = oOption.getValue();
  204. oOption.remove();
  205. // alert(sText+ " / "+ sValue);
  206. // var result = re.exec(sText);
  207. sText = sText.replace(re, "IMG_"+iFinalIndex);
  208. // alert(sText);
  209. oOption = addOption( combo, sText, sValue, ( !documentObject ) ? null : documentObject, iFinalIndex );
  210. setSelectedIndex( combo, iFinalIndex );
  211. // update dialog.imagesList
  212. var valueActual = dialog.imagesList[iActualIndex];
  213. var valueFinal = dialog.imagesList[iFinalIndex];
  214. dialog.imagesList[iActualIndex] = valueFinal;
  215. dialog.imagesList[iFinalIndex] = valueActual;
  216. return oOption;
  217. }
  218. function getSelectedIndex( combo )
  219. {
  220. combo = getSelect( combo );
  221. return combo ? combo.$.selectedIndex : -1;
  222. }
  223. function setSelectedIndex( combo, index )
  224. {
  225. combo = getSelect( combo );
  226. if ( index < 0 ) {
  227. return null;
  228. }
  229. var count = combo.getChildren().count();
  230. combo.$.selectedIndex = ( index >= count ) ? ( count - 1 ) : index;
  231. return combo;
  232. }
  233. function getOptions( combo )
  234. {
  235. combo = getSelect( combo );
  236. return combo ? combo.getChildren() : false;
  237. }
  238. function getSelect( obj )
  239. {
  240. if ( obj && obj.domId && obj.getInputElement().$ ) {
  241. return obj.getInputElement();
  242. } else if ( obj && obj.$ ) {
  243. return obj;
  244. }
  245. return false;
  246. }
  247. function unselectAll(dialog) {
  248. var editBtn = dialog.getContentElement( 'slideshowinfoid', 'editselectedbtn');
  249. var deleteBtn = dialog.getContentElement( 'slideshowinfoid', 'removeselectedbtn');
  250. editBtn = getSelect( editBtn );
  251. editBtn.hide();
  252. deleteBtn = getSelect( deleteBtn );
  253. deleteBtn.hide();
  254. var comboList = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  255. comboList = getSelect( comboList );
  256. var i;
  257. for ( i = comboList.getChildren().count() - 1 ; i >= 0 ; i-=1 )
  258. {
  259. comboList.getChild( i ).$.selected = false;
  260. }
  261. }
  262. function unselectIfNotUnique(combo) {
  263. var dialog = combo.getDialog();
  264. var selectefItem = null;
  265. combo = getSelect( combo );
  266. var cnt = 0;
  267. var editBtn = dialog.getContentElement( 'slideshowinfoid', 'editselectedbtn');
  268. var deleteBtn = dialog.getContentElement( 'slideshowinfoid', 'removeselectedbtn');
  269. var i, child;
  270. for ( i = combo.getChildren().count() - 1 ; i >= 0 ; i-=1 )
  271. {
  272. child = combo.getChild( i );
  273. if ( child.$.selected ) {
  274. cnt++;
  275. selectefItem = child;
  276. }
  277. }
  278. if (cnt > 1) {
  279. unselectAll(dialog);
  280. return null;
  281. } else if (cnt == 1) {
  282. editBtn = getSelect( editBtn );
  283. editBtn.show();
  284. deleteBtn = getSelect( deleteBtn );
  285. deleteBtn.show();
  286. displaySelected(dialog);
  287. return selectefItem;
  288. }
  289. return null;
  290. }
  291. function displaySelected (dialog) {
  292. if (dialog.openCloseStep == true) {
  293. return;
  294. }
  295. var previewCombo = dialog.getContentElement( 'slideshowinfoid', 'framepreviewid');
  296. if ( previewCombo.isVisible()) {
  297. previewSlideShow(dialog);
  298. } else {
  299. editeSelected(dialog);
  300. }
  301. }
  302. function selectFirstIfNotUnique(combo) {
  303. var dialog = combo.getDialog();
  304. combo = getSelect( combo );
  305. var firstSelectedInd = 0;
  306. var i, child, selectefItem;
  307. for ( i = 0; i < combo.getChildren().count() ; i+=1 )
  308. {
  309. child = combo.getChild( i );
  310. if ( child.$.selected ) {
  311. selectefItem = child;
  312. firstSelectedInd = i;
  313. break;
  314. }
  315. }
  316. setSelectedIndex(combo, firstSelectedInd);
  317. displaySelected(dialog);
  318. }
  319. function getSlectedIndex(dialog) {
  320. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  321. return getSelectedIndex( combo );
  322. }
  323. //----------------------------------------------------------------------------------------------------
  324. //----------------------------------------------------------------------------------------------------
  325. function removePlaceHolderImg(dialog) {
  326. var urlPlaceHolder = BASE_PATH + 'plugins/slideshow/icons/placeholder.png' ;
  327. if ((dialog.imagesList.length == 1) && (dialog.imagesList[0][IMG_PARAM.URL] == urlPlaceHolder)) {
  328. // Remove the place Holder Image
  329. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  330. combo = getSelect( combo );
  331. var i = 0;
  332. // Remove image from image Array
  333. dialog.imagesList.splice(i, 1);
  334. // Remove image from combo image list
  335. combo.getChild( i ).remove();
  336. }
  337. }
  338. function updateImgList(dialog) {
  339. removePlaceHolderImg(dialog);
  340. var preview = dialog.previewImage;
  341. var url = preview.$.src;
  342. var ratio = preview.$.width / preview.$.height;
  343. var w = 50;
  344. var h = 50;
  345. if (ratio > 1) {
  346. h = h/ratio;
  347. } else {
  348. w = w*ratio;
  349. }
  350. var oOption;
  351. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  352. var ind = dialog.imagesList.pushUnique([url, '', '', w.toFixed(0), h.toFixed(0)]);
  353. if (ind >= 0) {
  354. oOption = addOption( combo, 'IMG_'+ind + ' : ' + url.substring(url.lastIndexOf('/')+1), url, dialog.getParentEditor().document );
  355. // select index 0
  356. setSelectedIndex(combo, ind);
  357. // Update dialog
  358. displaySelected(dialog);
  359. }
  360. }
  361. function editeSelected(dialog) {
  362. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  363. var iSelectedIndex = getSelectedIndex( combo );
  364. var value = dialog.imagesList[iSelectedIndex];
  365. combo = dialog.getContentElement( 'slideshowinfoid', 'imgtitleid');
  366. combo = getSelect( combo );
  367. combo.setValue(value[1]);
  368. combo = dialog.getContentElement( 'slideshowinfoid', 'imgdescid');
  369. combo = getSelect( combo );
  370. combo.setValue(value[2]);
  371. combo = dialog.getContentElement( 'slideshowinfoid', 'imgpreviewid');
  372. combo = getSelect( combo );
  373. //console.log( "VALUE IMG -> " + value[iSelectedIndex] );
  374. var imgHtml = '<div style="text-align:center;"> <img src="'+ value[0] +
  375. '" title="' + value[1] +
  376. '" alt="' + value[2] +
  377. '" style=" max-height: 200px; max-width: 350px;' + '"> </div>';
  378. combo.setHtml(imgHtml);
  379. var previewCombo = dialog.getContentElement( 'slideshowinfoid', 'framepreviewid');
  380. var imgCombo = dialog.getContentElement( 'slideshowinfoid', 'imgparamsid');
  381. previewCombo = getSelect( previewCombo );
  382. previewCombo.hide();
  383. imgCombo = getSelect( imgCombo );
  384. imgCombo.show();
  385. }
  386. function removeSelected(dialog) {
  387. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  388. combo = getSelect( combo );
  389. var someRemoved = false;
  390. // Remove all selected options.
  391. var i;
  392. for ( i = combo.getChildren().count() - 1 ; i >= 0 ; i-- )
  393. {
  394. if ( combo.getChild( i ).$.selected ) {
  395. // Remove image from image Array
  396. dialog.imagesList.splice(i, 1);
  397. // Remove image from combo image list
  398. combo.getChild( i ).remove();
  399. someRemoved = true;
  400. }
  401. }
  402. if (someRemoved) {
  403. if (dialog.imagesList.length == 0) {
  404. var url = BASE_PATH + 'plugins/slideshow/icons/placeholder.png' ;
  405. var oOption = addOption( combo, 'IMG_0' + ' : ' + url.substring(url.lastIndexOf('/')+1) , url, dialog.getParentEditor().document );
  406. dialog.imagesList.pushUnique([url, lang.imgTitle, lang.imgDesc, '50', '50']);
  407. }
  408. // select index 0
  409. setSelectedIndex(combo, 0);
  410. // Update dialog
  411. displaySelected(dialog);
  412. }
  413. }
  414. function upDownSelected(dialog, offset) {
  415. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  416. combo = getSelect( combo );
  417. var iSelectedIndex = getSelectedIndex( combo );
  418. if (combo.getChildren().count() == 1) {
  419. return;
  420. }
  421. if ((offset == -1) && (iSelectedIndex == 0)) {
  422. return;
  423. }
  424. if ((offset == 1) && (iSelectedIndex == combo.getChildren().count()-1)) {
  425. return;
  426. }
  427. //alert(iSelectedIndex+" / "+combo.getChildren().count() + " / "+ offset);
  428. changeOptionPosition( combo, offset, dialog.getParentEditor().document, dialog );
  429. updateFramePreview(dialog);
  430. }
  431. // To automatically get the dimensions of the poster image
  432. var onImgLoadEvent = function() {
  433. // Image is ready.
  434. var preview = this.previewImage;
  435. preview.removeListener( 'load', onImgLoadEvent );
  436. preview.removeListener( 'error', onImgLoadErrorEvent );
  437. preview.removeListener( 'abort', onImgLoadErrorEvent );
  438. //console.log( "previewImage -> " + preview );
  439. updateImgList(this);
  440. };
  441. var onImgLoadErrorEvent = function() {
  442. // Error. Image is not loaded.
  443. var preview = this.previewImage;
  444. preview.removeListener( 'load', onImgLoadEvent );
  445. preview.removeListener( 'error', onImgLoadErrorEvent );
  446. preview.removeListener( 'abort', onImgLoadErrorEvent );
  447. };
  448. function updateTitle(dialog, val) {
  449. dialog.imagesList[getSlectedIndex(dialog)][IMG_PARAM.TITLE] = val;
  450. editeSelected(dialog);
  451. }
  452. function updateDescription(dialog, val) {
  453. dialog.imagesList[getSlectedIndex(dialog)][IMG_PARAM.ALT] = val;
  454. editeSelected(dialog);
  455. }
  456. function previewSlideShow(dialog) {
  457. var previewCombo = dialog.getContentElement( 'slideshowinfoid', 'framepreviewid');
  458. var imgCombo = dialog.getContentElement( 'slideshowinfoid', 'imgparamsid');
  459. imgCombo = getSelect( imgCombo );
  460. imgCombo.hide();
  461. previewCombo = getSelect( previewCombo );
  462. previewCombo.show();
  463. updateFramePreview(dialog);
  464. }
  465. function feedFrame(frame, data) {
  466. frame.open();
  467. frame.writeln( data );
  468. frame.close();
  469. }
  470. // function unprotectRealComments( html )
  471. // {
  472. // return html.replace( /<!--\{cke_protected\}\{C\}([\s\S]+?)-->/g,
  473. // function( match, data )
  474. // {
  475. // return decodeURIComponent( data );
  476. // });
  477. // };
  478. //
  479. // function unprotectSource( html, editor )
  480. // {
  481. // return html.replace( /<!--\{cke_protected\}([\s\S]+?)-->/g, function( match, data )
  482. // {
  483. // return decodeURIComponent( data );
  484. // });
  485. // }
  486. function updateFramePreview(dialog) {
  487. var width = 436;
  488. var height = 300;
  489. if ( dialog.params.getVal('showthumbid') == true) {
  490. height -= 120;
  491. } else if ( dialog.params.getVal('showcontrolid') == true) {
  492. height -= 30;
  493. }
  494. if (dialog.imagesList.length == 0) {
  495. return;
  496. }
  497. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  498. var iSelectedIndex = getSelectedIndex( combo );
  499. if (iSelectedIndex < 0) {
  500. iSelectedIndex = 0;
  501. }
  502. combo = dialog.getContentElement( 'slideshowinfoid', 'framepreviewid');
  503. var strVar="";
  504. strVar += "<head>";
  505. strVar += '<script src="'+SCRIPT_JQUERY+'" type="text/javascript"></script>';
  506. strVar += "<script type=\"text\/javascript\" src=\""+SCRIPT_ADDGAL+"\"><\/script>";
  507. strVar += "<link rel=\"stylesheet\" type=\"text\/css\" href=\""+CSS_ADDGAL+"\" \/>";
  508. if ( dialog.params.getVal('openOnClickId') == true) {
  509. strVar += "<link rel=\"stylesheet\" type=\"text\/css\" href=\""+CSS_FANCYBOX+"\" \/>";
  510. strVar += "<script type=\"text\/javascript\" src=\""+SCRIPT_FANCYBOX+"\"><\/script>";
  511. strVar += "<script type=\"text\/javascript\">";
  512. strVar += createScriptFancyBoxRun(dialog);
  513. strVar += "<\/script>";
  514. }
  515. strVar += "<script type=\"text\/javascript\">";
  516. strVar += createScriptAdGalleryRun(dialog, iSelectedIndex, width, height);
  517. strVar += "<\/script>";
  518. strVar += "<\/head>";
  519. strVar += "<body>";
  520. var domGallery = createDOMdGalleryRun(dialog);
  521. strVar += domGallery.getOuterHtml();
  522. strVar += "<\/body>";
  523. strVar += "";
  524. combo = getSelect( combo );
  525. var theFrame = combo.getFirst( iFrameItem );
  526. if (theFrame) {
  527. theFrame.remove();
  528. }
  529. var ifr = null;
  530. var w = width+60;
  531. var h = height;
  532. if ( dialog.params.getVal('showthumbid') == true) {
  533. h += 120;
  534. } else if ( dialog.params.getVal('showcontrolid') == true) {
  535. h += 30;
  536. }
  537. var iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +
  538. ' style="width:'+w+'px;height:'+h+'px;background:azure; "'+
  539. ' class="cke_pasteframe"' +
  540. ' frameborder="10" ' +
  541. ' allowTransparency="false"' +
  542. // ' src="' + 'data:text/html;charset=utf-8,' + strVar + '"' +
  543. ' role="region"' +
  544. ' scrolling="no"' +
  545. '></iframe>' );
  546. iframe.setAttribute('name', 'totoFrame');
  547. iframe.setAttribute('id', 'totoFrame');
  548. iframe.on( 'load', function( event ) {
  549. if (ifr != null) {
  550. return;
  551. }
  552. ifr = this.$;
  553. var iframedoc;
  554. if (ifr.contentDocument) {
  555. iframedoc = ifr.contentDocument;
  556. } else if (ifr.contentWindow) {
  557. iframedoc = ifr.contentWindow.document;
  558. }
  559. if (iframedoc){
  560. // Put the content in the iframe
  561. feedFrame(iframedoc, strVar);
  562. } else {
  563. //just in case of browsers that don't support the above 3 properties.
  564. //fortunately we don't come across such case so far.
  565. alert('Cannot inject dynamic contents into iframe.');
  566. }
  567. });
  568. combo.append(iframe);
  569. }
  570. function initImgListFromDOM(dialog, slideShowContainer) {
  571. var i, image, src;
  572. var imgW, imgH;
  573. var ratio, w, h, ind;
  574. var arr = slideShowContainer.$.getElementsByTagName("img");
  575. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  576. for (i = 0; i < arr.length; i+=1) {
  577. image = arr[i];
  578. src = image.src;
  579. // IE Seems sometime to return 0 !!, So natural Width and Height seems OK
  580. // If not just pput 50, Not as good but not so bad !!
  581. imgW = image.width;
  582. if (imgW == 0) {
  583. imgW = image.naturalWidth;
  584. }
  585. if (imgW == 0) {
  586. imgW = 50;
  587. imgH = 50;
  588. } else {
  589. imgH = image.height;
  590. if (imgH == 0) {
  591. imgH = image.naturalHeight;
  592. }
  593. if (imgH == 0) {
  594. imgW = 50;
  595. imgH = 50;
  596. }
  597. }
  598. ratio = imgW / imgH;
  599. w = 50;
  600. h = 50;
  601. if (ratio > 1) {
  602. h = h/ratio;
  603. } else {
  604. w = w*ratio;
  605. }
  606. ind = dialog.imagesList.pushUnique([src, image.title, image.alt, w, h]);
  607. var oOption;
  608. if (ind >= 0) {
  609. oOption = addOption( combo, 'IMG_'+ind + ' : ' + src.substring(src.lastIndexOf('/')+1), src, dialog.getParentEditor().document );
  610. }
  611. }
  612. // select index 0
  613. setSelectedIndex(combo, 0);
  614. // Update dialog
  615. displaySelected(dialog);
  616. }
  617. function initImgListFromFresh(dialog) {
  618. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  619. var url = BASE_PATH + 'plugins/slideshow/icons/placeholder.png' ;
  620. var oOption = addOption( combo, 'IMG_0' + ' : ' + url.substring(url.lastIndexOf('/')+1) , url, dialog.getParentEditor().document );
  621. dialog.imagesList.pushUnique([url, lang.imgTitle, lang.imgDesc, '50', '50']);
  622. // select index 0
  623. setSelectedIndex(combo, 0);
  624. // Update dialog
  625. displaySelected(dialog);
  626. }
  627. function commitSlideShow(dialog) {
  628. dialog.slideshowDOM.setAttribute('data-'+this.id, this.getValue());
  629. }
  630. function loadValue() {
  631. var dialog = this.getDialog();
  632. if (dialog.newSlideShowMode) {
  633. // New fresh SlideShow so let's put dom data attributes from dialog default values
  634. dialog.slideshowDOM.setAttribute('data-'+this.id, this.getValue());
  635. switch ( this.type ) {
  636. case 'checkbox':
  637. break;
  638. case 'text':
  639. break;
  640. case 'select':
  641. break;
  642. default:
  643. break;
  644. }
  645. } else {
  646. // Loaded SlideShow, so update Dialog values from DOM data attributes
  647. switch ( this.type ) {
  648. case 'checkbox':
  649. this.setValue(dialog.slideshowDOM.getAttribute('data-'+this.id) == 'true');
  650. break;
  651. case 'text':
  652. this.setValue(dialog.slideshowDOM.getAttribute('data-'+this.id));
  653. break;
  654. case 'select':
  655. this.setValue(dialog.slideshowDOM.getAttribute('data-'+this.id));
  656. break;
  657. default:
  658. break;
  659. }
  660. }
  661. }
  662. function commitValue() {
  663. var dialog = this.getDialog();
  664. dialog.params.updateVal(this.id, this.getValue());
  665. switch ( this.type ) {
  666. case 'checkbox':
  667. break;
  668. case 'text':
  669. break;
  670. case 'select':
  671. break;
  672. default:
  673. break;
  674. }
  675. displaySelected(dialog);
  676. }
  677. function cleanAll(dialog) {
  678. if ( dialog.previewImage )
  679. {
  680. dialog.previewImage.removeListener( 'load', onImgLoadEvent );
  681. dialog.previewImage.removeListener( 'error', onImgLoadErrorEvent );
  682. dialog.previewImage.removeListener( 'abort', onImgLoadErrorEvent );
  683. dialog.previewImage.remove();
  684. dialog.previewImage = null; // Dialog is closed.
  685. }
  686. dialog.imagesList = null;
  687. dialog.params = null;
  688. dialog.slideshowDOM = null;
  689. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  690. removeAllOptions(combo);
  691. dialog.openCloseStep = false;
  692. }
  693. function randomChars(len) {
  694. var chars = '';
  695. while (chars.length < len) {
  696. chars += Math.random().toString(36).substring(2);
  697. }
  698. // Remove unnecessary additional characters.
  699. return chars.substring(0, len);
  700. }
  701. var numbering = function( id ) {
  702. //return CKEDITOR.tools.getNextId() + '_' + id;
  703. return 'cke_' + randomChars(8) + '_' + id;
  704. };
  705. function getImagesContainerBlock(dialog, dom) {
  706. var obj = dom.getElementsByTag("ul");
  707. if (obj == null) {
  708. return null;
  709. }
  710. if (obj.count() == 1) {
  711. return obj.getItem(0);
  712. }
  713. return null;
  714. }
  715. function createScriptAdGalleryRun(dialog, iSelectedIndex, width, height) {
  716. var slideshowid = dialog.params.getVal('slideshowid'),
  717. galleryId = 'ad-gallery_' + slideshowid,
  718. strVar = '(function($) {',
  719. strHook = '';
  720. strVar += "$(function() {";
  721. // if (width == 0) width = "false";
  722. if (height == 0) {
  723. height = dialog.params.getVal('pictheightid');
  724. }
  725. // if (width == 0) width = dialog.params.getVal('pictWidthtid');
  726. // if (height == 0) height = "false";
  727. // if (width <= 1) width = "false";
  728. if (width == 0) {
  729. width = "false";
  730. }
  731. if (dialog.params.getVal('showtitleid') == false) {
  732. strHook = ", hooks: { displayDescription: function(image) {}}";
  733. }
  734. var params = "loader_image: '"+pluginPath+"3rdParty/ad-gallery/loader.gif'," +
  735. " width:" + width + ", height:" + height +
  736. ", start_at_index: " + iSelectedIndex +
  737. ", animation_speed: " + dialog.params.getVal('animspeedid') + strHook +
  738. ", update_window_hash: false, effect: '" + dialog.params.getVal('transitiontypeid') +
  739. "',";
  740. //alert(params);
  741. var slideShowParams = " slideshow: { enable: true, autostart: " + dialog.params.getVal('autostartid') +
  742. ", start_label: '" + lang.labelStart + "'" +
  743. ", stop_label: '" + lang.labelStop + "'" +
  744. ", speed: " + dialog.params.getVal('speedid') * 1000 +
  745. "}";
  746. strVar += " var galleries = $('#"+galleryId+"').adGallery({" + params + slideShowParams + "});";
  747. strVar += "});";
  748. strVar += "})(jQuery);";
  749. return strVar;
  750. }
  751. function createScriptFancyBoxRun(dialog) {
  752. var slideshowid = dialog.params.getVal('slideshowid'),
  753. galleryId = 'ad-gallery_' + slideshowid,
  754. str = '(function($) {';
  755. // str += "$(document).ready(function() {";
  756. str += "$(function() {";
  757. str += "$(\"#"+galleryId+"\").on(\"click\",\".ad-image\",function(){";
  758. str += "var imgObj =$(this).find(\"img\");";
  759. str += "var isrc=imgObj.attr(\"src\");";
  760. str += "var ititle=null;";
  761. str += "var idesc=null;";
  762. str += "var iname=isrc.split('/');";
  763. str += "iname=iname[iname.length-1];";
  764. str += "var imgdescid=$(this).find(\".ad-image-description\");";
  765. str += "if(imgdescid){";
  766. str += "ititle=$(this).find(\".ad-description-title\");";
  767. str += "if(ititle)ititle=ititle.text();";
  768. str += "if(ititle!='')ititle='<big>'+ititle+'</big>';";
  769. str += "idesc=$(this).find(\"span\");";
  770. str += "if(idesc)idesc=idesc.text();";
  771. str += "if(idesc!=''){";
  772. str += "if(ititle!='')ititle=ititle+'<br>';";
  773. str += "idesc='<i>'+idesc+'</i>';";
  774. str += "}";
  775. str += "}";
  776. str += "$.fancybox.open({";
  777. str += "href:isrc,";
  778. str += "beforeLoad:function(){";
  779. str += "this.title=ititle+idesc;";
  780. str += "},";
  781. str += "});";
  782. str += "});";
  783. str += "});";
  784. str += "})(jQuery);";
  785. return str;
  786. }
  787. function feedUlWithImages(dialog, ulObj) {
  788. var i, liObj, aObj, newImgDOM;
  789. for ( i = 0; i < dialog.imagesList.length ; i+=1 ) {
  790. liObj = ulObj.append( 'li' );
  791. liObj.setAttribute( 'contenteditable', 'false');
  792. aObj = liObj.append( 'a' );
  793. aObj.setAttribute( 'href', removeDomainFromUrl(dialog.imagesList[i][IMG_PARAM.URL]) );
  794. aObj.setAttribute('contenteditable', 'false');
  795. newImgDOM = aObj.append('img');
  796. newImgDOM.setAttribute( 'src', removeDomainFromUrl(dialog.imagesList[i][IMG_PARAM.URL]) );
  797. newImgDOM.setAttribute( 'title', dialog.imagesList[i][IMG_PARAM.TITLE]);
  798. newImgDOM.setAttribute( 'alt', dialog.imagesList[i][IMG_PARAM.ALT]);
  799. newImgDOM.setAttribute( 'contenteditable', 'false');
  800. newImgDOM.setAttribute('width', dialog.imagesList[i][IMG_PARAM.WIDTH]);
  801. newImgDOM.setAttribute('height', dialog.imagesList[i][IMG_PARAM.HEIGHT]);
  802. }
  803. }
  804. function createDOMdGalleryRun(dialog) {
  805. var slideshowid = dialog.params.getVal('slideshowid');
  806. var galleryId = 'ad-gallery_' + slideshowid;
  807. var displayThumbs = 'display: block;';
  808. var displayControls = 'display: block;';
  809. if ( dialog.params.getVal('showthumbid') == false) {
  810. displayThumbs = 'display: none;';
  811. }
  812. if ( dialog.params.getVal('showcontrolid') == false) {
  813. displayControls = 'visibility: hidden;';
  814. }
  815. var slideshowDOM = editor.document.createElement( 'div' );
  816. slideshowDOM.setAttribute('id', slideshowid );
  817. slideshowDOM.setAttribute( 'class', 'slideshowPlugin');
  818. slideshowDOM.setAttribute( 'contenteditable', 'false');
  819. var galleryDiv = slideshowDOM.append('div');
  820. galleryDiv.setAttribute( 'class', 'ad-gallery');
  821. galleryDiv.setAttribute( 'contenteditable', 'false');
  822. galleryDiv.setAttribute( 'id', galleryId);
  823. var wrapperObj = galleryDiv.append('div');
  824. wrapperObj.setAttribute( 'class', 'ad-image-wrapper');
  825. wrapperObj.setAttribute( 'contenteditable', 'false');
  826. var controlObj = galleryDiv.append('div');
  827. controlObj.setAttribute( 'class', 'ad-controls');
  828. controlObj.setAttribute( 'contenteditable', 'false');
  829. controlObj.setAttribute( 'style', displayControls);
  830. var navObj = galleryDiv.append('div');
  831. navObj.setAttribute( 'class', 'ad-nav');
  832. navObj.setAttribute( 'style', displayThumbs);
  833. navObj.setAttribute( 'contenteditable', 'false');
  834. var thumbsObj = navObj.append('div');
  835. thumbsObj.setAttribute( 'class', 'ad-thumbs');
  836. thumbsObj.setAttribute( 'contenteditable', 'false');
  837. var ulObj = thumbsObj.append('ul');
  838. ulObj.setAttribute('class', 'ad-thumb-list');
  839. ulObj.setAttribute( 'contenteditable', 'false');
  840. feedUlWithImages(dialog, ulObj);
  841. return slideshowDOM;
  842. }
  843. function ClickOkBtn(dialog) {
  844. var extraStyles = {},
  845. extraAttributes = {};
  846. dialog.openCloseStep = true;
  847. // Invoke the commit methods of all dialog elements, so the dialog.params array get Updated.
  848. dialog.commitContent(dialog);
  849. // Create a new DOM
  850. var slideshowDOM = createDOMdGalleryRun(dialog);
  851. // Add data tags to dom
  852. var i;
  853. for ( i = 0; i < dialog.params.length ; i+=1 ) {
  854. slideshowDOM.data(dialog.params[i][0], dialog.params[i][1]);
  855. }
  856. var scriptjQuery = CKEDITOR.document.createElement( 'script', {
  857. attributes: {
  858. type: 'text/javascript',
  859. src: SCRIPT_JQUERY
  860. }
  861. });
  862. slideshowDOM.append(scriptjQuery);
  863. // Add javascript for ""ad-gallery"
  864. // Be sure the path is correct and file is available !!
  865. var scriptAdGallery = CKEDITOR.document.createElement( 'script', {
  866. attributes: {
  867. type: 'text/javascript',
  868. src: SCRIPT_ADDGAL
  869. }
  870. });
  871. slideshowDOM.append(scriptAdGallery);
  872. if ( dialog.params.getVal('openOnClickId') == true) {
  873. // Dynamically add CSS for "fancyBox"
  874. // Be sure the path is correct and file is available !!
  875. var scriptFancyBoxCss = CKEDITOR.document.createElement( 'script', {
  876. attributes: {
  877. type: 'text/javascript'
  878. }
  879. });
  880. scriptFancyBoxCss.setText("(function($) { $('head').append('<link rel=\"stylesheet\" href=\""+CSS_FANCYBOX+"\" type=\"text/css\" />'); })(jQuery);");
  881. slideshowDOM.append(scriptFancyBoxCss);
  882. // Add javascript for ""fancyBox"
  883. // Be sure the path is correct and file is available !!
  884. var scriptFancyBox = CKEDITOR.document.createElement( 'script', {
  885. attributes: {
  886. type: 'text/javascript',
  887. src: SCRIPT_FANCYBOX
  888. }
  889. });
  890. slideshowDOM.append(scriptFancyBox);
  891. // Add RUN javascript for "fancybox"
  892. var scriptFancyboxRun = CKEDITOR.document.createElement( 'script', {
  893. attributes: {
  894. type: 'text/javascript'
  895. }
  896. });
  897. scriptFancyboxRun.setText(createScriptFancyBoxRun(dialog));
  898. slideshowDOM.append(scriptFancyboxRun);
  899. }
  900. // Dynamically add CSS for "ad-gallery"
  901. // Be sure the path is correct and file is available !!
  902. var scriptAdGalleryCss = CKEDITOR.document.createElement( 'script', {
  903. attributes: {
  904. type: 'text/javascript'
  905. }
  906. });
  907. scriptAdGalleryCss.setText("(function($) { $('head').append('<link rel=\"stylesheet\" href=\""+CSS_ADDGAL+"\" type=\"text/css\" />'); })(jQuery);");
  908. slideshowDOM.append(scriptAdGalleryCss);
  909. // Add RUN javascript for "ad-Gallery"
  910. var scriptAdGalleryRun = CKEDITOR.document.createElement( 'script', {
  911. attributes: {
  912. type: 'text/javascript'
  913. }
  914. });
  915. scriptAdGalleryRun.setText(createScriptAdGalleryRun(dialog, 0, 0, 0));
  916. slideshowDOM.append(scriptAdGalleryRun);
  917. if (dialog.imagesList.length) {
  918. extraStyles.backgroundImage = 'url("' + dialog.imagesList[0][IMG_PARAM.URL] + '")';
  919. }
  920. extraStyles.backgroundSize = '50%';
  921. extraStyles.display = 'block';
  922. // Create a new Fake Image
  923. var newFakeImage = editor.createFakeElement( slideshowDOM, 'cke_slideShow', 'slideShow', false );
  924. newFakeImage.setAttributes( extraAttributes );
  925. newFakeImage.setStyles( extraStyles );
  926. if ( dialog.fakeImage )
  927. {
  928. newFakeImage.replace( dialog.fakeImage );
  929. editor.getSelection().selectElement( newFakeImage );
  930. }
  931. else
  932. {
  933. editor.insertElement( newFakeImage );
  934. }
  935. cleanAll(dialog);
  936. dialog.hide();
  937. return true;
  938. }
  939. return {
  940. // Basic properties of the dialog window: title, minimum size.
  941. title : lang.dialogTitle,
  942. width: 500,
  943. height: 600,
  944. resizable: CKEDITOR.DIALOG_RESIZE_NONE,
  945. buttons: [
  946. CKEDITOR.dialog.okButton( editor, {
  947. label: 'OkCK',
  948. style : 'display:none;'
  949. }),
  950. CKEDITOR.dialog.cancelButton,
  951. {
  952. id: 'myokbtnid',
  953. type: 'button',
  954. label: 'OK',
  955. title: lang.validModif,
  956. accessKey: 'C',
  957. disabled: false,
  958. onClick: function()
  959. {
  960. // code on click
  961. ClickOkBtn(this.getDialog());
  962. }
  963. }
  964. ],
  965. // Dialog window contents definition.
  966. contents: [
  967. {
  968. // Definition of the Basic Settings dialog (page).
  969. id: 'slideshowinfoid',
  970. label: 'Basic Settings',
  971. align : 'center',
  972. // The tab contents.
  973. elements: [
  974. {
  975. type : 'text',
  976. id : 'id',
  977. style : 'display:none;',
  978. onLoad : function()
  979. {
  980. this.getInputElement().setAttribute( 'readOnly', true );
  981. }
  982. },
  983. {
  984. type: 'text',
  985. id: 'txturlid',
  986. style : 'display:none;',
  987. label: lang.imgList,
  988. onChange: function() {
  989. var dialog = this.getDialog(),
  990. newUrl = this.getValue();
  991. if ( newUrl.length > 0 ) { //Prevent from load before onShow
  992. var preview = dialog.previewImage;
  993. preview.on( 'load', onImgLoadEvent, dialog );
  994. preview.on( 'error', onImgLoadErrorEvent, dialog );
  995. preview.on( 'abort', onImgLoadErrorEvent, dialog );
  996. preview.setAttribute( 'src', newUrl );
  997. }
  998. }
  999. },
  1000. {
  1001. type : 'button',
  1002. id : 'browse',
  1003. hidden : 'true',
  1004. style : 'display:inline-block;margin-top:0px;',
  1005. filebrowser :
  1006. {
  1007. action : 'Browse',
  1008. target: 'slideshowinfoid:txturlid',
  1009. url: editor.config.filebrowserImageBrowseUrl || editor.config.filebrowserBrowseUrl
  1010. },
  1011. label : lang.imgAdd
  1012. },
  1013. // {
  1014. // type : 'button',
  1015. // id : 'browseDir',
  1016. // style : 'display:inline-block;margin-top:0px;',
  1017. // label : "toto",
  1018. // onClick : function() {
  1019. // previewSlideShow(this.getDialog());
  1020. // }
  1021. // },
  1022. {
  1023. type: 'vbox',
  1024. align: 'center',
  1025. children: [
  1026. {
  1027. type: 'html',
  1028. align : 'center',
  1029. id: 'framepreviewtitleid',
  1030. style: 'font-family: Amaranth; color: #1E66EB; font-size: 20px; font-weight: bold;',
  1031. html: lang.previewMode
  1032. },
  1033. {
  1034. type: 'html',
  1035. id: 'framepreviewid',
  1036. align : 'center',
  1037. style : 'width:500px;height:320px',
  1038. html: ''
  1039. },
  1040. {
  1041. type: 'hbox',
  1042. id: 'imgparamsid',
  1043. style : 'display:none;width:500px;',
  1044. height: '325px',
  1045. children :
  1046. [
  1047. {
  1048. type : 'vbox',
  1049. align : 'center',
  1050. width : '400px',
  1051. children :
  1052. [
  1053. {
  1054. type : 'text',
  1055. id : 'imgtitleid',
  1056. label : lang.imgTitle,
  1057. onChange: function() {
  1058. updateTitle(this.getDialog(), this.getValue());
  1059. },
  1060. onBlur: function() {
  1061. updateTitle(this.getDialog(), this.getValue());
  1062. }
  1063. },
  1064. {
  1065. type : 'text',
  1066. id : 'imgdescid',
  1067. label : lang.imgDesc,
  1068. onChange: function() {
  1069. updateDescription(this.getDialog(), this.getValue());
  1070. },
  1071. onBlur: function() {
  1072. updateDescription(this.getDialog(), this.getValue());
  1073. }
  1074. },
  1075. {
  1076. type : 'html',
  1077. id : 'imgpreviewid',
  1078. style : 'width:400px;height:200px;',
  1079. html: '<div>xx</div>'
  1080. }
  1081. ]
  1082. }
  1083. ]
  1084. },
  1085. {
  1086. type : 'hbox',
  1087. align: 'center',
  1088. height: 110,
  1089. widths: [ '25%', '50%'],
  1090. children :
  1091. [
  1092. {
  1093. type : 'vbox',
  1094. children :
  1095. [
  1096. {
  1097. type : 'checkbox',
  1098. id : 'autostartid',
  1099. label : lang.autoStart,
  1100. 'default' : 'checked',
  1101. style : 'margin-top:15px;',
  1102. onChange : commitValue,
  1103. commit : commitValue,
  1104. setup : loadValue
  1105. },
  1106. {
  1107. type : 'checkbox',
  1108. id : 'showtitleid',
  1109. label : lang.showTitle,
  1110. 'default' : 'checked',
  1111. onChange : commitValue,
  1112. commit : commitValue,
  1113. setup : loadValue
  1114. },
  1115. {
  1116. type : 'checkbox',
  1117. id : 'showcontrolid',
  1118. label : lang.showControls,
  1119. 'default' : 'checked',
  1120. onChange : commitValue,
  1121. commit : commitValue,
  1122. setup : loadValue
  1123. },
  1124. {
  1125. type : 'checkbox',
  1126. id : 'showthumbid',
  1127. label : lang.showThumbs,
  1128. 'default' : 'checked',
  1129. onChange : commitValue,
  1130. commit : commitValue,
  1131. setup : loadValue
  1132. },
  1133. {
  1134. type : 'checkbox',
  1135. id : 'openOnClickId',
  1136. label : lang.openOnClick,
  1137. 'default' : 'checked',
  1138. onChange : commitValue,
  1139. commit : commitValue,
  1140. setup : loadValue
  1141. }
  1142. ]
  1143. },
  1144. {
  1145. type: 'select',
  1146. id: 'imglistitemsid',
  1147. label: lang.picturesList,
  1148. multiple: false,
  1149. style : 'height:125px;width:250px',
  1150. items: [],
  1151. onChange : function( api ) {
  1152. //unselectIfNotUnique(this);
  1153. selectFirstIfNotUnique(this);
  1154. }
  1155. },
  1156. {
  1157. type : 'vbox',
  1158. children :
  1159. [
  1160. {
  1161. type : 'button',
  1162. id : 'previewbtn',
  1163. style : 'margin-top:15px;margin-left:25px;',
  1164. label : lang.previewMode,
  1165. onClick : function() {
  1166. previewSlideShow(this.getDialog());
  1167. }
  1168. },
  1169. {
  1170. type : 'button',
  1171. id : 'removeselectedbtn',
  1172. style : 'margin-left:25px;',
  1173. //style : 'display:none;',
  1174. label : lang.imgDelete,
  1175. onClick : function() {
  1176. removeSelected(this.getDialog());
  1177. }
  1178. },
  1179. {
  1180. type : 'button',
  1181. id : 'editselectedbtn',
  1182. style : 'margin-left:25px;',
  1183. //style : 'display:none;',
  1184. label : lang.imgEdit,
  1185. onClick : function() {
  1186. editeSelected(this.getDialog());
  1187. }
  1188. },
  1189. {
  1190. type : 'hbox',
  1191. children :
  1192. [
  1193. {
  1194. type : 'button',
  1195. id : 'upselectedbtn',
  1196. style : 'width:32px; margin-left:25px;',
  1197. //style : 'display:none;',
  1198. label : lang.arrowUp,
  1199. onClick : function() {
  1200. upDownSelected(this.getDialog(), -1);
  1201. }
  1202. },
  1203. {
  1204. type : 'button',
  1205. id : 'downselectedbtn',
  1206. style : 'width:32px;',
  1207. //style : 'margin-left:5px;',
  1208. //style : 'display:none;',
  1209. label : lang.arrowDown,
  1210. onClick : function() {
  1211. upDownSelected(this.getDialog(), 1);
  1212. }
  1213. }
  1214. ]
  1215. }
  1216. ]
  1217. }
  1218. ]
  1219. },
  1220. {
  1221. type : 'hbox',
  1222. children :
  1223. [
  1224. // {
  1225. // type : 'text',
  1226. // id : 'pictWidthtid',
  1227. // label : lang.pictWidth,
  1228. // maxLength : 3,
  1229. // style : 'width:100px;',
  1230. // 'default' : '300',
  1231. // onChange : function( api ) {
  1232. // var intRegex = /^\d+$/;
  1233. // if(intRegex.test(this.getValue()) == false) {
  1234. // console.log("setValue0: ", this.getValue());
  1235. // this.setValue(300);
  1236. // } else {
  1237. // console.log("setValue1: ", this.getValue());
  1238. // }
  1239. // this.getDialog().params.updateVal(this.id, this.getValue());
  1240. // displaySelected(this.getDialog());
  1241. // },
  1242. // commit : commitValue,
  1243. // setup : loadValue,
  1244. // },
  1245. {
  1246. type : 'text',
  1247. id : 'pictheightid',
  1248. label : lang.pictHeight,
  1249. maxLength : 3,
  1250. style : 'width:100px;',
  1251. 'default' : '300',
  1252. onChange : function( api ) {
  1253. var intRegex = /^\d+$/;
  1254. if(intRegex.test(this.getValue()) == false) {
  1255. this.setValue(300);
  1256. }
  1257. this.getDialog().params.updateVal(this.id, this.getValue());
  1258. displaySelected(this.getDialog());
  1259. },
  1260. commit : commitValue,
  1261. setup : loadValue
  1262. },
  1263. {
  1264. type : 'text',
  1265. id : 'speedid',
  1266. label : lang.displayTime,
  1267. maxLength : 3,
  1268. style : 'width:100px;',
  1269. 'default' : '5',
  1270. onChange : function( api ) {
  1271. var intRegex = /^\d+$/;
  1272. if(intRegex.test(this.getValue()) == false) {
  1273. this.setValue(5);
  1274. }
  1275. this.getDialog().params.updateVal(this.id, this.getValue());
  1276. displaySelected(this.getDialog());
  1277. },
  1278. commit : commitValue,
  1279. setup : loadValue
  1280. },
  1281. {
  1282. type : 'text',
  1283. id : 'animspeedid',
  1284. label : lang.transitionTime,
  1285. style : 'width:100px;',
  1286. maxLength : 4,
  1287. 'default' : '500',
  1288. onChange : function( api ) {
  1289. var intRegex = /^\d+$/;
  1290. if(intRegex.test(this.getValue()) == false) {
  1291. this.setValue(500);
  1292. }
  1293. this.getDialog().params.updateVal(this.id, this.getValue());
  1294. displaySelected(this.getDialog());
  1295. },
  1296. commit : commitValue,
  1297. setup : loadValue
  1298. },
  1299. {
  1300. type : 'select',
  1301. id : 'transitiontypeid',
  1302. label : lang.transition,
  1303. // add-gallery effects 'slide-vert', 'resize', 'fade', 'none' or false
  1304. // effect: 'slide-hori',
  1305. items : [ [ lang.tr1, 'none' ], [ lang.tr2, 'resize' ], [ lang.tr3, 'slide-vert' ], [ lang.tr4, 'slide-hori' ], [lang.tr5, 'fade'] ],
  1306. 'default' : 'resize',
  1307. style : 'width:100px;',
  1308. commit : commitValue,
  1309. setup : loadValue,
  1310. onChange : commitValue
  1311. }
  1312. ]
  1313. }
  1314. ]
  1315. }
  1316. ]
  1317. }
  1318. ],
  1319. onLoad: function() {
  1320. },
  1321. // Invoked when the dialog is loaded.
  1322. onShow: function() {
  1323. this.dialog = this;
  1324. this.slideshowDOM = null;
  1325. this.openCloseStep = true;
  1326. this.fakeImage = null;
  1327. var slideshowDOM = null;
  1328. this.imagesList = [];
  1329. this.params = [];
  1330. // To get dimensions of poster image
  1331. this.previewImage = editor.document.createElement( 'img' );
  1332. this.okRefresh = true;
  1333. var fakeImage = this.getSelectedElement();
  1334. if ( fakeImage && fakeImage.data( 'cke-real-element-type' ) && fakeImage.data( 'cke-real-element-type' ) == 'slideShow' )
  1335. {
  1336. this.fakeImage = fakeImage;
  1337. slideshowDOM = editor.restoreRealElement( fakeImage );
  1338. }
  1339. // Create a new <slideshow> slideshowDOM if it does not exist.
  1340. if ( !slideshowDOM) {
  1341. this.params.push(['slideshowid', numbering( 'slideShow' )]);
  1342. // Insert placeHolder image
  1343. initImgListFromFresh(this);
  1344. // Invoke the commit methods of all dialog elements, so the dialog.params array get Updated.
  1345. this.commitContent(this);
  1346. // console.log( "Params New -> " + this.params );
  1347. // console.log( "Images New -> " + this.imagesList );
  1348. } else {
  1349. this.slideshowDOM = slideshowDOM;
  1350. // Get the reference of the slideSjow Images Container
  1351. var slideShowContainer = getImagesContainerBlock(this, slideshowDOM);
  1352. if (slideShowContainer == null) {
  1353. alert("BIG Problem slideShowContainer !!");
  1354. return false;
  1355. }
  1356. var slideshowid = slideshowDOM.getAttribute('id');
  1357. if (slideshowid == null) {
  1358. alert("BIG Problem slideshowid !!");
  1359. return false;
  1360. }
  1361. this.params.push(['slideshowid', slideshowid]);
  1362. // a DOM has been found updatet images List and Dialog box from this DOM
  1363. initImgListFromDOM(this, slideShowContainer);
  1364. // Init params Array from DOM
  1365. // Copy all attributes to an array.
  1366. var domDatas = slideshowDOM.$.dataset;
  1367. var param;
  1368. for ( param in domDatas ) {
  1369. this.params.push( [ param, domDatas[ param ] ] );
  1370. }
  1371. // Invoke the setup methods of all dialog elements, to set dialog elements values with DOM input data.
  1372. this.setupContent(this, true);
  1373. //updateFramePreview(this);
  1374. this.newSlideShowMode = false;
  1375. // console.log( "Params Old -> " + this.params );
  1376. // console.log( "Images Old -> " + this.imagesList );
  1377. }
  1378. this.openCloseStep = false;
  1379. previewSlideShow(this);
  1380. },
  1381. // This method is invoked once a user clicks the OK button, confirming the dialog.
  1382. // I just will return false, as the real OK Button has been redefined
  1383. // -This was the only way I found to avoid dialog popup to close when hitting the keyboard "ENTER" Key !!
  1384. onOk: function() {
  1385. // var okr = this.okRefresh;
  1386. // if (this.okRefresh == true) {
  1387. // console.log('OKOKOK 0 :'+this.okRefresh);
  1388. // this.okRefresh = false;
  1389. // this.commitContent(this);
  1390. // myVar = setTimeout(
  1391. // function(obj){
  1392. // obj.okRefresh = true;
  1393. // },500, this);
  1394. // }
  1395. return false;
  1396. },
  1397. onHide: function() {
  1398. cleanAll(this);
  1399. }
  1400. };
  1401. });