slideshow.js.bak 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615
  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 = 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/images/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/images/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. var jqueryStr = '<script src="'+SCRIPT_JQUERY+'" type="text/javascript"></script>';
  505. strVar += "<head>";
  506. // if (editor.config.slideshowDoNotLoadJquery && (editor.config.slideshowDoNotLoadJquery == true)) {
  507. // jqueryStr = '';
  508. // }
  509. strVar += jqueryStr;
  510. strVar += "<script type=\"text\/javascript\" src=\""+SCRIPT_ADDGAL+"\"><\/script>";
  511. strVar += "<link rel=\"stylesheet\" type=\"text\/css\" href=\""+CSS_ADDGAL+"\" \/>";
  512. if ( dialog.params.getVal('openOnClickId') == true) {
  513. strVar += "<link rel=\"stylesheet\" type=\"text\/css\" href=\""+CSS_FANCYBOX+"\" \/>";
  514. strVar += "<script type=\"text\/javascript\" src=\""+SCRIPT_FANCYBOX+"\"><\/script>";
  515. strVar += "<script type=\"text\/javascript\">";
  516. strVar += createScriptFancyBoxRun(dialog);
  517. strVar += "<\/script>";
  518. }
  519. strVar += "<script type=\"text\/javascript\">";
  520. strVar += createScriptAdGalleryRun(dialog, iSelectedIndex, width, height);
  521. strVar += "<\/script>";
  522. strVar += "<\/head>";
  523. strVar += "<body>";
  524. var domGallery = createDOMdGalleryRun(dialog);
  525. strVar += domGallery.getOuterHtml();
  526. strVar += "<\/body>";
  527. strVar += "";
  528. combo = getSelect( combo );
  529. var theFrame = combo.getFirst( iFrameItem );
  530. if (theFrame) {
  531. theFrame.remove();
  532. }
  533. var ifr = null;
  534. var w = width+60;
  535. var h = height;
  536. if ( dialog.params.getVal('showthumbid') == true) {
  537. h += 120;
  538. } else if ( dialog.params.getVal('showcontrolid') == true) {
  539. h += 30;
  540. }
  541. var iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +
  542. ' style="width:'+w+'px;height:'+h+'px;background:azure; "'+
  543. ' class="cke_pasteframe"' +
  544. ' frameborder="10" ' +
  545. ' allowTransparency="false"' +
  546. // ' src="' + 'data:text/html;charset=utf-8,' + strVar + '"' +
  547. ' role="region"' +
  548. ' scrolling="no"' +
  549. '></iframe>' );
  550. iframe.setAttribute('name', 'totoFrame');
  551. iframe.setAttribute('id', 'totoFrame');
  552. iframe.on( 'load', function( event ) {
  553. if (ifr != null) {
  554. return;
  555. }
  556. ifr = this.$;
  557. var iframedoc;
  558. if (ifr.contentDocument) {
  559. iframedoc = ifr.contentDocument;
  560. } else if (ifr.contentWindow) {
  561. iframedoc = ifr.contentWindow.document;
  562. }
  563. if (iframedoc){
  564. // Put the content in the iframe
  565. feedFrame(iframedoc, strVar);
  566. } else {
  567. //just in case of browsers that don't support the above 3 properties.
  568. //fortunately we don't come across such case so far.
  569. alert('Cannot inject dynamic contents into iframe.');
  570. }
  571. });
  572. combo.append(iframe);
  573. }
  574. function initImgListFromDOM(dialog, slideShowContainer) {
  575. var i, image, src;
  576. var imgW, imgH;
  577. var ratio, w, h, ind;
  578. var arr = slideShowContainer.$.getElementsByTagName("img");
  579. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  580. for (i = 0; i < arr.length; i+=1) {
  581. image = arr[i];
  582. src = image.src;
  583. // IE Seems sometime to return 0 !!, So natural Width and Height seems OK
  584. // If not just pput 50, Not as good but not so bad !!
  585. imgW = image.width;
  586. if (imgW == 0) {
  587. imgW = image.naturalWidth;
  588. }
  589. if (imgW == 0) {
  590. imgW = 50;
  591. imgH = 50;
  592. } else {
  593. imgH = image.height;
  594. if (imgH == 0) {
  595. imgH = image.naturalHeight;
  596. }
  597. if (imgH == 0) {
  598. imgW = 50;
  599. imgH = 50;
  600. }
  601. }
  602. ratio = imgW / imgH;
  603. w = 50;
  604. h = 50;
  605. if (ratio > 1) {
  606. h = h/ratio;
  607. } else {
  608. w = w*ratio;
  609. }
  610. ind = dialog.imagesList.pushUnique([src, image.title, image.alt, w, h]);
  611. var oOption;
  612. if (ind >= 0) {
  613. oOption = addOption( combo, 'IMG_'+ind + ' : ' + src.substring(src.lastIndexOf('/')+1), src, dialog.getParentEditor().document );
  614. }
  615. }
  616. // select index 0
  617. setSelectedIndex(combo, 0);
  618. // Update dialog
  619. displaySelected(dialog);
  620. }
  621. function initImgListFromFresh(dialog) {
  622. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  623. var url = BASE_PATH + 'plugins/slideshow/images/placeholder.png' ;
  624. var oOption = addOption( combo, 'IMG_0' + ' : ' + url.substring(url.lastIndexOf('/')+1) , url, dialog.getParentEditor().document );
  625. dialog.imagesList.pushUnique([url, lang.imgTitle, lang.imgDesc, '50', '50']);
  626. // select index 0
  627. setSelectedIndex(combo, 0);
  628. // Update dialog
  629. displaySelected(dialog);
  630. }
  631. function commitSlideShow(dialog) {
  632. dialog.slideshowDOM.setAttribute('data-'+this.id, this.getValue());
  633. }
  634. function loadValue() {
  635. var dialog = this.getDialog();
  636. if (dialog.newSlideShowMode) {
  637. // New fresh SlideShow so let's put dom data attributes from dialog default values
  638. dialog.slideshowDOM.setAttribute('data-'+this.id, this.getValue());
  639. switch ( this.type ) {
  640. case 'checkbox':
  641. break;
  642. case 'text':
  643. break;
  644. case 'select':
  645. break;
  646. default:
  647. break;
  648. }
  649. } else {
  650. // Loaded SlideShow, so update Dialog values from DOM data attributes
  651. switch ( this.type ) {
  652. case 'checkbox':
  653. this.setValue(dialog.slideshowDOM.getAttribute('data-'+this.id) == 'true');
  654. break;
  655. case 'text':
  656. this.setValue(dialog.slideshowDOM.getAttribute('data-'+this.id));
  657. break;
  658. case 'select':
  659. this.setValue(dialog.slideshowDOM.getAttribute('data-'+this.id));
  660. break;
  661. default:
  662. break;
  663. }
  664. }
  665. }
  666. function commitValue() {
  667. var dialog = this.getDialog();
  668. dialog.params.updateVal(this.id, this.getValue());
  669. switch ( this.type ) {
  670. case 'checkbox':
  671. break;
  672. case 'text':
  673. break;
  674. case 'select':
  675. break;
  676. default:
  677. break;
  678. }
  679. displaySelected(dialog);
  680. }
  681. function cleanAll(dialog) {
  682. if ( dialog.previewImage )
  683. {
  684. dialog.previewImage.removeListener( 'load', onImgLoadEvent );
  685. dialog.previewImage.removeListener( 'error', onImgLoadErrorEvent );
  686. dialog.previewImage.removeListener( 'abort', onImgLoadErrorEvent );
  687. dialog.previewImage.remove();
  688. dialog.previewImage = null; // Dialog is closed.
  689. }
  690. dialog.imagesList = null;
  691. dialog.params = null;
  692. dialog.slideshowDOM = null;
  693. var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid');
  694. removeAllOptions(combo);
  695. dialog.openCloseStep = false;
  696. }
  697. function randomChars(len) {
  698. var chars = '';
  699. while (chars.length < len) {
  700. chars += Math.random().toString(36).substring(2);
  701. }
  702. // Remove unnecessary additional characters.
  703. return chars.substring(0, len);
  704. }
  705. var numbering = function( id ) {
  706. //return CKEDITOR.tools.getNextId() + '_' + id;
  707. return 'cke_' + randomChars(8) + '_' + id;
  708. };
  709. function getImagesContainerBlock(dialog, dom) {
  710. var obj = dom.getElementsByTag("ul");
  711. if (obj == null) {
  712. return null;
  713. }
  714. if (obj.count() == 1) {
  715. return obj.getItem(0);
  716. }
  717. return null;
  718. }
  719. function createScriptAdGalleryRun(dialog, iSelectedIndex, width, height) {
  720. var slideshowid = dialog.params.getVal('slideshowid'),
  721. galleryId = 'ad-gallery_' + slideshowid,
  722. strVar = '(function($) {',
  723. strHook = '';
  724. strVar += "$(function() {";
  725. // if (width == 0) width = "false";
  726. if (height == 0) {
  727. height = dialog.params.getVal('pictheightid');
  728. }
  729. // if (width == 0) width = dialog.params.getVal('pictWidthtid');
  730. // if (height == 0) height = "false";
  731. // if (width <= 1) width = "false";
  732. if (width == 0) {
  733. width = "false";
  734. }
  735. if (dialog.params.getVal('showtitleid') == false) {
  736. strHook = ", hooks: { displayDescription: function(image) {}}";
  737. }
  738. var params = "loader_image: '"+pluginPath+"3rdParty/ad-gallery/loader.gif'," +
  739. " width:" + width + ", height:" + height +
  740. ", start_at_index: " + iSelectedIndex +
  741. ", animation_speed: " + dialog.params.getVal('animspeedid') + strHook +
  742. ", update_window_hash: false, effect: '" + dialog.params.getVal('transitiontypeid') +
  743. "',";
  744. //alert(params);
  745. var slideShowParams = " slideshow: { enable: true, autostart: " + dialog.params.getVal('autostartid') +
  746. ", start_label: '" + lang.labelStart + "'" +
  747. ", stop_label: '" + lang.labelStop + "'" +
  748. ", speed: " + dialog.params.getVal('speedid') * 1000 +
  749. "}";
  750. strVar += " var galleries = $('#"+galleryId+"').adGallery({" + params + slideShowParams + "});";
  751. strVar += "});";
  752. strVar += "})(jQuery);";
  753. return strVar;
  754. }
  755. // function createScriptFancyBoxRun(dialog) {
  756. // var slideshowid = dialog.params.getVal('slideshowid'),
  757. // galleryId = 'ad-gallery_' + slideshowid,
  758. // str = '(function($) {';
  759. //// str += "$(document).ready(function() {";
  760. // str += "$(function() {";
  761. // str += "$(\"#"+galleryId+"\").on(\"click\",\".ad-image\",function(){";
  762. // str += "var imgObj =$(this).find(\"img\");";
  763. // str += "var isrc=imgObj.attr(\"src\");";
  764. // str += "var ititle=null;";
  765. // str += "var idesc=null;";
  766. // str += "var iname=isrc.split('/');";
  767. // str += "iname=iname[iname.length-1];";
  768. // str += "var imgdescid=$(this).find(\".ad-image-description\");";
  769. // str += "if(imgdescid){";
  770. // str += "ititle=$(this).find(\".ad-description-title\");";
  771. // str += "if(ititle)ititle=ititle.text();";
  772. // str += "if(ititle!='')ititle='<big>'+ititle+'</big>';";
  773. // str += "idesc=$(this).find(\"span\");";
  774. // str += "if(idesc)idesc=idesc.text();";
  775. // str += "if(idesc!=''){";
  776. // str += "if(ititle!='')ititle=ititle+'<br>';";
  777. // str += "idesc='<i>'+idesc+'</i>';";
  778. // str += "}";
  779. // str += "}";
  780. // str += "$.fancybox.open({";
  781. // str += "href:isrc,";
  782. // str += "beforeLoad:function(){";
  783. // str += "this.title=ititle+idesc;";
  784. // str += "},";
  785. // str += "});";
  786. // str += "});";
  787. // str += "});";
  788. // str += "})(jQuery);";
  789. //
  790. // return str;
  791. // }
  792. function createScriptFancyBoxRun(dialog) {
  793. var slideshowid = dialog.params.getVal('slideshowid'),
  794. galleryId = 'ad-gallery_' + slideshowid,
  795. str = '(function($) {';
  796. str += "$(function() {";
  797. str += "$(\"#"+galleryId+"\").on(\"click\",\".ad-image\",function(){";
  798. str += "var imgObj =$(this).find(\"img\");";
  799. str += "var isrc=imgObj.attr(\"src\");";
  800. str += "var ititle=null;";
  801. str += "var idesc=null;";
  802. str += "var iname=isrc.split('/');";
  803. str += "iname=iname[iname.length-1];";
  804. str += "var imgdescid=$(this).find(\".ad-image-description\");";
  805. str += "if(imgdescid){";
  806. str += "ititle=$(this).find(\".ad-description-title\");";
  807. str += "if(ititle)ititle=ititle.text();";
  808. str += "if(ititle!='')ititle='<big>'+ititle+'</big>';";
  809. str += "idesc=$(this).find(\"span\");";
  810. str += "if(idesc)idesc=idesc.text();";
  811. // str += 'console.log("idesc:", idesc);';
  812. str += "if (idesc.indexOf('IMAGE_LINK_') >= 0) {";
  813. str += "idesc = '';";
  814. str += "}";
  815. str += "if(idesc!=''){";
  816. str += "if(ititle!='')ititle=ititle+'<br>';";
  817. str += "idesc='<i>'+idesc+'</i>';";
  818. str += "}";
  819. str += "}";
  820. str += "$.fancybox.open({";
  821. str += "href:isrc,";
  822. str += "beforeLoad:function(){";
  823. str += "this.title=ititle+idesc;";
  824. str += "},";
  825. str += "});";
  826. str += "});";
  827. str += "});";
  828. str += "})(jQuery);";
  829. return str;
  830. }
  831. function createScriptLinkRun(dialog) {
  832. var slideshowid = dialog.params.getVal('slideshowid'),
  833. galleryId = 'ad-gallery_' + slideshowid,
  834. str = '(function($) {';
  835. str += "$(function() {";
  836. str += "$(\"#"+galleryId+"\").on(\"click\",\".ad-image\",function(){";
  837. str += "var imgObj =$(this).find(\"img\");";
  838. str += "var isrc=imgObj.attr(\"src\");";
  839. str += "var ititle=null;";
  840. str += "var idesc=null;";
  841. str += "var iname=isrc.split('/');";
  842. str += "iname=iname[iname.length-1];";
  843. str += "var imgdescid=$(this).find(\".ad-image-description\");";
  844. str += "if(imgdescid){";
  845. str += "ititle=$(this).find(\".ad-description-title\");";
  846. str += "if(ititle)ititle=ititle.text();";
  847. str += "idesc=$(this).find(\"span\");";
  848. // str += "console.log('desc0', idesc);";
  849. str += "if(idesc)idesc=idesc.text();";
  850. str += "if(idesc!=''){";
  851. // str += "console.log('desc1', idesc);";
  852. // str += "if (idesc.indexOf('LIEN:') == 0) {";
  853. // str += "idesc = idesc.substring(5);}";
  854. // str += "window.open(idesc);"
  855. // str += "}";
  856. str += "var url=window.location.href.trim();";
  857. str += "if (idesc.indexOf('IMAGE_LINK_TAB:') >= 0) {";
  858. str += " idesc = idesc.substring(15).trim();";
  859. str += " if (url != idesc) window.open(idesc,'_blank');";
  860. str += "} else if (idesc.indexOf('IMAGE_LINK_PAR:') >= 0) {";
  861. str += " idesc = idesc.substring(15).trim();";
  862. str += " if (url != idesc) window.open(idesc,'_self');";
  863. str += "}";
  864. str += "}";
  865. str += "}";
  866. str += "});";
  867. str += "});";
  868. str += "})(jQuery);";
  869. return str;
  870. }
  871. function feedUlWithImages(dialog, ulObj) {
  872. var i, liObj, aObj, newImgDOM;
  873. for ( i = 0; i < dialog.imagesList.length ; i+=1 ) {
  874. liObj = ulObj.append( 'li' );
  875. liObj.setAttribute( 'contenteditable', 'false');
  876. aObj = liObj.append( 'a' );
  877. aObj.setAttribute( 'href', removeDomainFromUrl(dialog.imagesList[i][IMG_PARAM.URL]) );
  878. aObj.setAttribute('contenteditable', 'false');
  879. newImgDOM = aObj.append('img');
  880. newImgDOM.setAttribute( 'src', removeDomainFromUrl(dialog.imagesList[i][IMG_PARAM.URL]) );
  881. newImgDOM.setAttribute( 'title', dialog.imagesList[i][IMG_PARAM.TITLE]);
  882. newImgDOM.setAttribute( 'alt', dialog.imagesList[i][IMG_PARAM.ALT]);
  883. newImgDOM.setAttribute( 'contenteditable', 'false');
  884. newImgDOM.setAttribute('width', dialog.imagesList[i][IMG_PARAM.WIDTH]);
  885. newImgDOM.setAttribute('height', dialog.imagesList[i][IMG_PARAM.HEIGHT]);
  886. }
  887. }
  888. function createDOMdGalleryRun(dialog) {
  889. var slideshowid = dialog.params.getVal('slideshowid');
  890. var galleryId = 'ad-gallery_' + slideshowid;
  891. var displayThumbs = 'display: block;';
  892. var displayControls = 'display: block;';
  893. if ( dialog.params.getVal('showthumbid') == false) {
  894. displayThumbs = 'display: none;';
  895. }
  896. if ( dialog.params.getVal('showcontrolid') == false) {
  897. displayControls = 'visibility: hidden;';
  898. }
  899. var slideshowDOM = editor.document.createElement( 'div' );
  900. slideshowDOM.setAttribute('id', slideshowid );
  901. slideshowDOM.setAttribute( 'class', 'slideshowPlugin');
  902. slideshowDOM.setAttribute( 'contenteditable', 'false');
  903. var galleryDiv = slideshowDOM.append('div');
  904. galleryDiv.setAttribute( 'class', 'ad-gallery');
  905. galleryDiv.setAttribute( 'contenteditable', 'false');
  906. galleryDiv.setAttribute( 'id', galleryId);
  907. var wrapperObj = galleryDiv.append('div');
  908. wrapperObj.setAttribute( 'class', 'ad-image-wrapper');
  909. wrapperObj.setAttribute( 'contenteditable', 'false');
  910. var controlObj = galleryDiv.append('div');
  911. controlObj.setAttribute( 'class', 'ad-controls');
  912. controlObj.setAttribute( 'contenteditable', 'false');
  913. controlObj.setAttribute( 'style', displayControls);
  914. var navObj = galleryDiv.append('div');
  915. navObj.setAttribute( 'class', 'ad-nav');
  916. navObj.setAttribute( 'style', displayThumbs);
  917. navObj.setAttribute( 'contenteditable', 'false');
  918. var thumbsObj = navObj.append('div');
  919. thumbsObj.setAttribute( 'class', 'ad-thumbs');
  920. thumbsObj.setAttribute( 'contenteditable', 'false');
  921. var ulObj = thumbsObj.append('ul');
  922. ulObj.setAttribute('class', 'ad-thumb-list');
  923. ulObj.setAttribute( 'contenteditable', 'false');
  924. feedUlWithImages(dialog, ulObj);
  925. return slideshowDOM;
  926. }
  927. function ClickOkBtn(dialog) {
  928. var extraStyles = {},
  929. extraAttributes = {};
  930. dialog.openCloseStep = true;
  931. // Invoke the commit methods of all dialog elements, so the dialog.params array get Updated.
  932. dialog.commitContent(dialog);
  933. // Create a new DOM
  934. var slideshowDOM = createDOMdGalleryRun(dialog);
  935. // Add data tags to dom
  936. var i;
  937. for ( i = 0; i < dialog.params.length ; i+=1 ) {
  938. slideshowDOM.data(dialog.params[i][0], dialog.params[i][1]);
  939. }
  940. if (!(editor.config.slideshowDoNotLoadJquery && (editor.config.slideshowDoNotLoadJquery == true))) {
  941. var scriptjQuery = CKEDITOR.document.createElement( 'script', {
  942. attributes: {
  943. type: 'text/javascript',
  944. src: SCRIPT_JQUERY
  945. }
  946. });
  947. slideshowDOM.append(scriptjQuery);
  948. }
  949. // Add javascript for ""ad-gallery"
  950. // Be sure the path is correct and file is available !!
  951. var scriptAdGallery = CKEDITOR.document.createElement( 'script', {
  952. attributes: {
  953. type: 'text/javascript',
  954. src: SCRIPT_ADDGAL
  955. }
  956. });
  957. slideshowDOM.append(scriptAdGallery);
  958. if ( dialog.params.getVal('openOnClickId') == true) {
  959. // Dynamically add CSS for "fancyBox"
  960. // Be sure the path is correct and file is available !!
  961. var scriptFancyBoxCss = CKEDITOR.document.createElement( 'script', {
  962. attributes: {
  963. type: 'text/javascript'
  964. }
  965. });
  966. scriptFancyBoxCss.setText("(function($) { $('head').append('<link rel=\"stylesheet\" href=\""+CSS_FANCYBOX+"\" type=\"text/css\" />'); })(jQuery);");
  967. slideshowDOM.append(scriptFancyBoxCss);
  968. // Add javascript for ""fancyBox"
  969. // Be sure the path is correct and file is available !!
  970. var scriptFancyBox = CKEDITOR.document.createElement( 'script', {
  971. attributes: {
  972. type: 'text/javascript',
  973. src: SCRIPT_FANCYBOX
  974. }
  975. });
  976. slideshowDOM.append(scriptFancyBox);
  977. // Add RUN javascript for "fancybox"
  978. var scriptFancyboxRun = CKEDITOR.document.createElement( 'script', {
  979. attributes: {
  980. type: 'text/javascript'
  981. }
  982. });
  983. scriptFancyboxRun.setText(createScriptFancyBoxRun(dialog));
  984. slideshowDOM.append(scriptFancyboxRun);
  985. }
  986. // Add RUN javascript for "link"
  987. var scriptLinkRun = CKEDITOR.document.createElement( 'script', {
  988. attributes: {
  989. type: 'text/javascript'
  990. }
  991. });
  992. scriptLinkRun.setText(createScriptLinkRun(dialog));
  993. slideshowDOM.append(scriptLinkRun);
  994. // Dynamically add CSS for "ad-gallery"
  995. // Be sure the path is correct and file is available !!
  996. var scriptAdGalleryCss = CKEDITOR.document.createElement( 'script', {
  997. attributes: {
  998. type: 'text/javascript'
  999. }
  1000. });
  1001. scriptAdGalleryCss.setText("(function($) { $('head').append('<link rel=\"stylesheet\" href=\""+CSS_ADDGAL+"\" type=\"text/css\" />'); })(jQuery);");
  1002. slideshowDOM.append(scriptAdGalleryCss);
  1003. // Add RUN javascript for "ad-Gallery"
  1004. var scriptAdGalleryRun = CKEDITOR.document.createElement( 'script', {
  1005. attributes: {
  1006. type: 'text/javascript'
  1007. }
  1008. });
  1009. scriptAdGalleryRun.setText(createScriptAdGalleryRun(dialog, 0, 0, 0));
  1010. slideshowDOM.append(scriptAdGalleryRun);
  1011. if (dialog.imagesList.length) {
  1012. extraStyles.backgroundImage = 'url("' + dialog.imagesList[0][IMG_PARAM.URL] + '")';
  1013. }
  1014. extraStyles.backgroundSize = '50%';
  1015. extraStyles.display = 'block';
  1016. // Create a new Fake Image
  1017. var newFakeImage = editor.createFakeElement( slideshowDOM, 'cke_slideShow', 'slideShow', false );
  1018. newFakeImage.setAttributes( extraAttributes );
  1019. newFakeImage.setStyles( extraStyles );
  1020. if ( dialog.fakeImage )
  1021. {
  1022. newFakeImage.replace( dialog.fakeImage );
  1023. editor.getSelection().selectElement( newFakeImage );
  1024. }
  1025. else
  1026. {
  1027. editor.insertElement( newFakeImage );
  1028. }
  1029. cleanAll(dialog);
  1030. dialog.hide();
  1031. return true;
  1032. }
  1033. return {
  1034. // Basic properties of the dialog window: title, minimum size.
  1035. title : lang.dialogTitle,
  1036. width: 500,
  1037. height: 600,
  1038. resizable: CKEDITOR.DIALOG_RESIZE_NONE,
  1039. buttons: [
  1040. CKEDITOR.dialog.okButton( editor, {
  1041. label: 'OkCK',
  1042. style : 'display:none;'
  1043. }),
  1044. CKEDITOR.dialog.cancelButton,
  1045. {
  1046. id: 'myokbtnid',
  1047. type: 'button',
  1048. label: 'OK',
  1049. title: lang.validModif,
  1050. accessKey: 'C',
  1051. disabled: false,
  1052. onClick: function()
  1053. {
  1054. // code on click
  1055. ClickOkBtn(this.getDialog());
  1056. }
  1057. }
  1058. ],
  1059. // Dialog window contents definition.
  1060. contents: [
  1061. {
  1062. // Definition of the Basic Settings dialog (page).
  1063. id: 'slideshowinfoid',
  1064. label: 'Basic Settings',
  1065. align : 'center',
  1066. // The tab contents.
  1067. elements: [
  1068. {
  1069. type : 'text',
  1070. id : 'id',
  1071. style : 'display:none;',
  1072. onLoad : function()
  1073. {
  1074. this.getInputElement().setAttribute( 'readOnly', true );
  1075. }
  1076. },
  1077. {
  1078. type: 'text',
  1079. id: 'txturlid',
  1080. style : 'display:none;',
  1081. label: lang.imgList,
  1082. onChange: function() {
  1083. var dialog = this.getDialog(),
  1084. newUrl = this.getValue();
  1085. if ( newUrl.length > 0 ) { //Prevent from load before onShow
  1086. var preview = dialog.previewImage;
  1087. preview.on( 'load', onImgLoadEvent, dialog );
  1088. preview.on( 'error', onImgLoadErrorEvent, dialog );
  1089. preview.on( 'abort', onImgLoadErrorEvent, dialog );
  1090. preview.setAttribute( 'src', newUrl );
  1091. }
  1092. }
  1093. },
  1094. {
  1095. type : 'button',
  1096. id : 'browse',
  1097. hidden : 'true',
  1098. style : 'display:inline-block;margin-top:0px;',
  1099. filebrowser :
  1100. {
  1101. action : 'Browse',
  1102. target: 'slideshowinfoid:txturlid',
  1103. url: editor.config.filebrowserImageBrowseUrl || editor.config.filebrowserBrowseUrl
  1104. },
  1105. label : lang.imgAdd
  1106. },
  1107. // {
  1108. // type : 'button',
  1109. // id : 'browseDir',
  1110. // style : 'display:inline-block;margin-top:0px;',
  1111. // label : "toto",
  1112. // onClick : function() {
  1113. // previewSlideShow(this.getDialog());
  1114. // }
  1115. // },
  1116. {
  1117. type: 'vbox',
  1118. align: 'center',
  1119. children: [
  1120. {
  1121. type: 'html',
  1122. align : 'center',
  1123. id: 'framepreviewtitleid',
  1124. style: 'font-family: Amaranth; color: #1E66EB; font-size: 20px; font-weight: bold;',
  1125. html: lang.previewMode
  1126. },
  1127. {
  1128. type: 'html',
  1129. id: 'framepreviewid',
  1130. align : 'center',
  1131. style : 'width:500px;height:320px',
  1132. html: ''
  1133. },
  1134. {
  1135. type: 'hbox',
  1136. id: 'imgparamsid',
  1137. style : 'display:none;width:500px;',
  1138. height: '325px',
  1139. children :
  1140. [
  1141. {
  1142. type : 'vbox',
  1143. align : 'center',
  1144. width : '400px',
  1145. children :
  1146. [
  1147. {
  1148. type : 'text',
  1149. id : 'imgtitleid',
  1150. label : lang.imgTitle,
  1151. onChange: function() {
  1152. updateTitle(this.getDialog(), this.getValue());
  1153. },
  1154. onBlur: function() {
  1155. updateTitle(this.getDialog(), this.getValue());
  1156. }
  1157. },
  1158. {
  1159. type : 'text',
  1160. id : 'imgdescid',
  1161. label : lang.imgDesc,
  1162. onChange: function() {
  1163. updateDescription(this.getDialog(), this.getValue());
  1164. },
  1165. onBlur: function() {
  1166. updateDescription(this.getDialog(), this.getValue());
  1167. }
  1168. },
  1169. {
  1170. type : 'html',
  1171. id : 'imgpreviewid',
  1172. style : 'width:400px;height:200px;',
  1173. html: '<div>xx</div>'
  1174. }
  1175. ]
  1176. }
  1177. ]
  1178. },
  1179. {
  1180. type : 'hbox',
  1181. align: 'center',
  1182. height: 110,
  1183. widths: [ '25%', '50%'],
  1184. children :
  1185. [
  1186. {
  1187. type : 'vbox',
  1188. children :
  1189. [
  1190. {
  1191. type : 'checkbox',
  1192. id : 'autostartid',
  1193. label : lang.autoStart,
  1194. 'default' : 'checked',
  1195. style : 'margin-top:15px;',
  1196. onChange : commitValue,
  1197. commit : commitValue,
  1198. setup : loadValue
  1199. },
  1200. {
  1201. type : 'checkbox',
  1202. id : 'showtitleid',
  1203. label : lang.showTitle,
  1204. 'default' : 'checked',
  1205. onChange : commitValue,
  1206. commit : commitValue,
  1207. setup : loadValue
  1208. },
  1209. {
  1210. type : 'checkbox',
  1211. id : 'showcontrolid',
  1212. label : lang.showControls,
  1213. 'default' : 'checked',
  1214. onChange : commitValue,
  1215. commit : commitValue,
  1216. setup : loadValue
  1217. },
  1218. {
  1219. type : 'checkbox',
  1220. id : 'showthumbid',
  1221. label : lang.showThumbs,
  1222. 'default' : 'checked',
  1223. onChange : commitValue,
  1224. commit : commitValue,
  1225. setup : loadValue
  1226. },
  1227. {
  1228. type : 'checkbox',
  1229. id : 'openOnClickId',
  1230. label : lang.openOnClick,
  1231. 'default' : 'checked',
  1232. onChange : commitValue,
  1233. commit : commitValue,
  1234. setup : loadValue
  1235. }
  1236. ]
  1237. },
  1238. {
  1239. type: 'select',
  1240. id: 'imglistitemsid',
  1241. label: lang.picturesList,
  1242. multiple: false,
  1243. style : 'height:125px;width:250px',
  1244. items: [],
  1245. onChange : function( api ) {
  1246. //unselectIfNotUnique(this);
  1247. selectFirstIfNotUnique(this);
  1248. }
  1249. },
  1250. {
  1251. type : 'vbox',
  1252. children :
  1253. [
  1254. {
  1255. type : 'button',
  1256. id : 'previewbtn',
  1257. style : 'margin-top:15px;margin-left:25px;',
  1258. label : lang.previewMode,
  1259. onClick : function() {
  1260. previewSlideShow(this.getDialog());
  1261. }
  1262. },
  1263. {
  1264. type : 'button',
  1265. id : 'removeselectedbtn',
  1266. style : 'margin-left:25px;',
  1267. //style : 'display:none;',
  1268. label : lang.imgDelete,
  1269. onClick : function() {
  1270. removeSelected(this.getDialog());
  1271. }
  1272. },
  1273. {
  1274. type : 'button',
  1275. id : 'editselectedbtn',
  1276. style : 'margin-left:25px;',
  1277. //style : 'display:none;',
  1278. label : lang.imgEdit,
  1279. onClick : function() {
  1280. editeSelected(this.getDialog());
  1281. }
  1282. },
  1283. {
  1284. type : 'hbox',
  1285. children :
  1286. [
  1287. {
  1288. type : 'button',
  1289. id : 'upselectedbtn',
  1290. style : 'width:32px; margin-left:25px;',
  1291. //style : 'display:none;',
  1292. label : lang.arrowUp,
  1293. onClick : function() {
  1294. upDownSelected(this.getDialog(), -1);
  1295. }
  1296. },
  1297. {
  1298. type : 'button',
  1299. id : 'downselectedbtn',
  1300. style : 'width:32px;',
  1301. //style : 'margin-left:5px;',
  1302. //style : 'display:none;',
  1303. label : lang.arrowDown,
  1304. onClick : function() {
  1305. upDownSelected(this.getDialog(), 1);
  1306. }
  1307. }
  1308. ]
  1309. }
  1310. ]
  1311. }
  1312. ]
  1313. },
  1314. {
  1315. type : 'hbox',
  1316. children :
  1317. [
  1318. // {
  1319. // type : 'text',
  1320. // id : 'pictWidthtid',
  1321. // label : lang.pictWidth,
  1322. // maxLength : 3,
  1323. // style : 'width:100px;',
  1324. // 'default' : '300',
  1325. // onChange : function( api ) {
  1326. // var intRegex = /^\d+$/;
  1327. // if(intRegex.test(this.getValue()) == false) {
  1328. // console.log("setValue0: ", this.getValue());
  1329. // this.setValue(300);
  1330. // } else {
  1331. // console.log("setValue1: ", this.getValue());
  1332. // }
  1333. // this.getDialog().params.updateVal(this.id, this.getValue());
  1334. // displaySelected(this.getDialog());
  1335. // },
  1336. // commit : commitValue,
  1337. // setup : loadValue,
  1338. // },
  1339. {
  1340. type : 'text',
  1341. id : 'pictheightid',
  1342. label : lang.pictHeight,
  1343. maxLength : 3,
  1344. style : 'width:100px;',
  1345. 'default' : '300',
  1346. onChange : function( api ) {
  1347. var intRegex = /^\d+$/;
  1348. if(intRegex.test(this.getValue()) == false) {
  1349. this.setValue(300);
  1350. }
  1351. this.getDialog().params.updateVal(this.id, this.getValue());
  1352. displaySelected(this.getDialog());
  1353. },
  1354. commit : commitValue,
  1355. setup : loadValue
  1356. },
  1357. {
  1358. type : 'text',
  1359. id : 'speedid',
  1360. label : lang.displayTime,
  1361. maxLength : 3,
  1362. style : 'width:100px;',
  1363. 'default' : '5',
  1364. onChange : function( api ) {
  1365. var intRegex = /^\d+$/;
  1366. if(intRegex.test(this.getValue()) == false) {
  1367. this.setValue(5);
  1368. }
  1369. this.getDialog().params.updateVal(this.id, this.getValue());
  1370. displaySelected(this.getDialog());
  1371. },
  1372. commit : commitValue,
  1373. setup : loadValue
  1374. },
  1375. {
  1376. type : 'text',
  1377. id : 'animspeedid',
  1378. label : lang.transitionTime,
  1379. style : 'width:100px;',
  1380. maxLength : 4,
  1381. 'default' : '500',
  1382. onChange : function( api ) {
  1383. var intRegex = /^\d+$/;
  1384. if(intRegex.test(this.getValue()) == false) {
  1385. this.setValue(500);
  1386. }
  1387. this.getDialog().params.updateVal(this.id, this.getValue());
  1388. displaySelected(this.getDialog());
  1389. },
  1390. commit : commitValue,
  1391. setup : loadValue
  1392. },
  1393. {
  1394. type : 'select',
  1395. id : 'transitiontypeid',
  1396. label : lang.transition,
  1397. // add-gallery effects 'slide-vert', 'resize', 'fade', 'none' or false
  1398. // effect: 'slide-hori',
  1399. items : [ [ lang.tr1, 'none' ], [ lang.tr2, 'resize' ], [ lang.tr3, 'slide-vert' ], [ lang.tr4, 'slide-hori' ], [lang.tr5, 'fade'] ],
  1400. 'default' : 'resize',
  1401. style : 'width:100px;',
  1402. commit : commitValue,
  1403. setup : loadValue,
  1404. onChange : commitValue
  1405. }
  1406. ]
  1407. }
  1408. ]
  1409. }
  1410. ]
  1411. }
  1412. ],
  1413. onLoad: function() {
  1414. },
  1415. // Invoked when the dialog is loaded.
  1416. onShow: function() {
  1417. this.dialog = this;
  1418. this.slideshowDOM = null;
  1419. this.openCloseStep = true;
  1420. this.fakeImage = null;
  1421. var slideshowDOM = null;
  1422. this.imagesList = [];
  1423. this.params = [];
  1424. // To get dimensions of poster image
  1425. this.previewImage = editor.document.createElement( 'img' );
  1426. this.okRefresh = true;
  1427. var fakeImage = this.getSelectedElement();
  1428. if ( fakeImage && fakeImage.data( 'cke-real-element-type' ) && fakeImage.data( 'cke-real-element-type' ) == 'slideShow' )
  1429. {
  1430. this.fakeImage = fakeImage;
  1431. slideshowDOM = editor.restoreRealElement( fakeImage );
  1432. }
  1433. // Create a new <slideshow> slideshowDOM if it does not exist.
  1434. if ( !slideshowDOM) {
  1435. this.params.push(['slideshowid', numbering( 'slideShow' )]);
  1436. // Insert placeHolder image
  1437. initImgListFromFresh(this);
  1438. // Invoke the commit methods of all dialog elements, so the dialog.params array get Updated.
  1439. this.commitContent(this);
  1440. // console.log( "Params New -> " + this.params );
  1441. // console.log( "Images New -> " + this.imagesList );
  1442. } else {
  1443. this.slideshowDOM = slideshowDOM;
  1444. // Get the reference of the slideSjow Images Container
  1445. var slideShowContainer = getImagesContainerBlock(this, slideshowDOM);
  1446. if (slideShowContainer == null) {
  1447. alert("BIG Problem slideShowContainer !!");
  1448. return false;
  1449. }
  1450. var slideshowid = slideshowDOM.getAttribute('id');
  1451. if (slideshowid == null) {
  1452. alert("BIG Problem slideshowid !!");
  1453. return false;
  1454. }
  1455. this.params.push(['slideshowid', slideshowid]);
  1456. // a DOM has been found updatet images List and Dialog box from this DOM
  1457. initImgListFromDOM(this, slideShowContainer);
  1458. // Init params Array from DOM
  1459. // Copy all attributes to an array.
  1460. var domDatas = slideshowDOM.$.dataset;
  1461. var param;
  1462. for ( param in domDatas ) {
  1463. this.params.push( [ param, domDatas[ param ] ] );
  1464. }
  1465. // Invoke the setup methods of all dialog elements, to set dialog elements values with DOM input data.
  1466. this.setupContent(this, true);
  1467. //updateFramePreview(this);
  1468. this.newSlideShowMode = false;
  1469. // console.log( "Params Old -> " + this.params );
  1470. // console.log( "Images Old -> " + this.imagesList );
  1471. }
  1472. this.openCloseStep = false;
  1473. previewSlideShow(this);
  1474. },
  1475. // This method is invoked once a user clicks the OK button, confirming the dialog.
  1476. // I just will return false, as the real OK Button has been redefined
  1477. // -This was the only way I found to avoid dialog popup to close when hitting the keyboard "ENTER" Key !!
  1478. onOk: function() {
  1479. // var okr = this.okRefresh;
  1480. // if (this.okRefresh == true) {
  1481. // console.log('OKOKOK 0 :'+this.okRefresh);
  1482. // this.okRefresh = false;
  1483. // this.commitContent(this);
  1484. // myVar = setTimeout(
  1485. // function(obj){
  1486. // obj.okRefresh = true;
  1487. // },500, this);
  1488. // }
  1489. return false;
  1490. },
  1491. onHide: function() {
  1492. cleanAll(this);
  1493. }
  1494. };
  1495. });