slideshow.js 56 KB

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