/** * The slideshow dialog definition. * Copyright (c) 2003-2013, Cricri042. All rights reserved. * Targeted for "ad-gallery" JavaScript : http://adgallery.codeplex.com/ * And "Fancybox" : http://fancyapps.com/fancybox/ */ /** * Debug : var_dump * * @var: Var * @level: Level max * */ function removeDomainFromUrl(string) { "use strict"; return string.replace(/^https?:\/\/[^\/]+/i, ''); } var IMG_PARAM = {URL:0, TITLE:1, ALT:2, WIDTH:3, HEIGHT:4}, pluginPath = '//lib.amic.ru/js/'; //removeDomainFromUrl(CKEDITOR.plugins.get( 'slideshow' ).path), BASE_PATH = removeDomainFromUrl(CKEDITOR.basePath), //SCRIPT_JQUERY = "https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js", SCRIPT_JQUERY = pluginPath+"3rdParty/jquery.min.js", SCRIPT_ADDGAL = pluginPath+"3rdParty/ad-gallery/jquery.ad-gallery.min.js", CSS_ADDGAL = pluginPath+"3rdParty/ad-gallery/jquery.ad-gallery.css", SCRIPT_FANCYBOX = pluginPath+'3rdParty/fancybox2/jquery.fancybox.pack.js?v=2.1.5', CSS_FANCYBOX = pluginPath+"3rdParty/fancybox2/jquery.fancybox.css?v=2.1.5"; function var_dump(_var, _level) { "use strict"; var dumped_text = ""; if(!_level) { _level = 0; } //The padding given at the beginning of the line. var level_padding = ""; var j; for(j=0; j<_level+1; j+=1) { level_padding += " "; } if(typeof(_var) == 'object') { //Array/Hashes/Objects var item; var value; for(item in _var) { if (_var.hasOwnProperty(item)) { value = _var[item]; if(typeof(value) == 'object') { // If it is an array, dumped_text += level_padding + "'" + item + "' ...\n"; dumped_text += var_dump(value, _level+1); } else { dumped_text += level_padding +"'"+ item +"' => \""+ value +"\"\n"; } } } } else { //Stings/Chars/Numbers etc. dumped_text = "===>"+ _var +"<===("+ typeof(_var) +")"; } return dumped_text; } var listItem = function( node ) { "use strict"; return node.type == CKEDITOR.NODE_ELEMENT && node.is( 'li' ); }; var ULItem = function( node ) { "use strict"; return node.type == CKEDITOR.NODE_ELEMENT && node.is( 'ul' ); }; var iFrameItem = function( node ) { "use strict"; return node.type == CKEDITOR.NODE_ELEMENT && node.is( 'iframe' ); }; Array.prototype.pushUnique = function (item){ "use strict"; var i; for ( i = 0; i < this.length ; i+=1 ) { if (this[i][0] == item[0]) { return -1; } } this.push(item); return this.length - 1; }; Array.prototype.updateVal = function (item, data){ "use strict"; var i; for ( i = 0; i < this.length ; i+=1 ) { if (this[i][0] == item) { this[i] = [item, data]; return true; } } this[i] = [item, data]; return false; }; Array.prototype.getVal = function (item){ "use strict"; var i; for ( i = 0; i < this.length ; i+=1 ) { if (this[i][0] == item) { return this[i][1]; } } return null; }; // Our dialog definition. CKEDITOR.dialog.add( 'slideshowDialog', function( editor ) { "use strict"; var lang = editor.lang.slideshow; //---------------------------------------------------------------------------------------------------- // COMBO STUFF //---------------------------------------------------------------------------------------------------- // Add a new option to a CHKBOX object (combo or list). function addOption( combo, optionText, optionValue, documentObject, index ) { combo = getSelect( combo ); var oOption; if ( documentObject ) { oOption = documentObject.createElement( "OPTION" ); } else { oOption = document.createElement( "OPTION" ); } if ( combo && oOption && oOption.getName() == 'option' ) { if ( CKEDITOR.env.ie ) { if ( !isNaN( parseInt( index, 10) ) ) { combo.$.options.add( oOption.$, index ); } else { combo.$.options.add( oOption.$ ); } oOption.$.innerHTML = optionText.length > 0 ? optionText : ''; oOption.$.value = optionValue; } else { if ( index !== null && index < combo.getChildCount() ) { combo.getChild( index < 0 ? 0 : index ).insertBeforeMe( oOption ); } else { combo.append( oOption ); } oOption.setText( optionText.length > 0 ? optionText : '' ); oOption.setValue( optionValue ); } } else { return false; } return oOption; } // Remove all selected options from a CHKBOX object. function removeSelectedOptions( combo ) { combo = getSelect( combo ); // Save the selected index var iSelectedIndex = getSelectedIndex( combo ); // Remove all selected options. var i; for ( i = combo.getChildren().count() - 1 ; i >= 0 ; i-=1 ) { if ( combo.getChild( i ).$.selected ) { combo.getChild( i ).remove(); } } // Reset the selection based on the original selected index. setSelectedIndex( combo, iSelectedIndex ); } //Modify option from a CHKBOX object. function modifyOption( combo, index, title, value ) { combo = getSelect( combo ); if ( index < 0 ) { return false; } var child = combo.getChild( index ); child.setText( title ); child.setValue( value ); return child; } function removeAllOptions( combo ) { combo = getSelect( combo ); while ( combo.getChild( 0 ) && combo.getChild( 0 ).remove() ) { /*jsl:pass*/ } } // Moves the selected option by a number of steps (also negative). function changeOptionPosition( combo, steps, documentObject, dialog ) { combo = getSelect( combo ); var iActualIndex = getSelectedIndex( combo ); if ( iActualIndex < 0 ) { return false; } var iFinalIndex = iActualIndex + steps; iFinalIndex = ( iFinalIndex < 0 ) ? 0 : iFinalIndex; iFinalIndex = ( iFinalIndex >= combo.getChildCount() ) ? combo.getChildCount() - 1 : iFinalIndex; if ( iActualIndex == iFinalIndex ) { return false; } var re = /(^IMG_\d+)/; // Modify sText in final index var oOption = combo.getChild( iFinalIndex ), sText = oOption.getText(), sValue = oOption.getValue(); sText = sText.replace(re, "IMG_"+iActualIndex); modifyOption( combo, iFinalIndex, sText, sValue ); // do the move oOption = combo.getChild( iActualIndex ); sText = oOption.getText(); sValue = oOption.getValue(); oOption.remove(); // alert(sText+ " / "+ sValue); // var result = re.exec(sText); sText = sText.replace(re, "IMG_"+iFinalIndex); // alert(sText); oOption = addOption( combo, sText, sValue, ( !documentObject ) ? null : documentObject, iFinalIndex ); setSelectedIndex( combo, iFinalIndex ); // update dialog.imagesList var valueActual = dialog.imagesList[iActualIndex]; var valueFinal = dialog.imagesList[iFinalIndex]; dialog.imagesList[iActualIndex] = valueFinal; dialog.imagesList[iFinalIndex] = valueActual; return oOption; } function getSelectedIndex( combo ) { combo = getSelect( combo ); return combo ? combo.$.selectedIndex : -1; } function setSelectedIndex( combo, index ) { combo = getSelect( combo ); if ( index < 0 ) { return null; } var count = combo.getChildren().count(); combo.$.selectedIndex = ( index >= count ) ? ( count - 1 ) : index; return combo; } function getOptions( combo ) { combo = getSelect( combo ); return combo ? combo.getChildren() : false; } function getSelect( obj ) { if ( obj && obj.domId && obj.getInputElement().$ ) { return obj.getInputElement(); } else if ( obj && obj.$ ) { return obj; } return false; } function unselectAll(dialog) { var editBtn = dialog.getContentElement( 'slideshowinfoid', 'editselectedbtn'); var deleteBtn = dialog.getContentElement( 'slideshowinfoid', 'removeselectedbtn'); editBtn = getSelect( editBtn ); editBtn.hide(); deleteBtn = getSelect( deleteBtn ); deleteBtn.hide(); var comboList = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid'); comboList = getSelect( comboList ); var i; for ( i = comboList.getChildren().count() - 1 ; i >= 0 ; i-=1 ) { comboList.getChild( i ).$.selected = false; } } function unselectIfNotUnique(combo) { var dialog = combo.getDialog(); var selectefItem = null; combo = getSelect( combo ); var cnt = 0; var editBtn = dialog.getContentElement( 'slideshowinfoid', 'editselectedbtn'); var deleteBtn = dialog.getContentElement( 'slideshowinfoid', 'removeselectedbtn'); var i, child; for ( i = combo.getChildren().count() - 1 ; i >= 0 ; i-=1 ) { child = combo.getChild( i ); if ( child.$.selected ) { cnt++; selectefItem = child; } } if (cnt > 1) { unselectAll(dialog); return null; } else if (cnt == 1) { editBtn = getSelect( editBtn ); editBtn.show(); deleteBtn = getSelect( deleteBtn ); deleteBtn.show(); displaySelected(dialog); return selectefItem; } return null; } function displaySelected (dialog) { if (dialog.openCloseStep == true) { return; } var previewCombo = dialog.getContentElement( 'slideshowinfoid', 'framepreviewid'); if ( previewCombo.isVisible()) { previewSlideShow(dialog); } else { editeSelected(dialog); } } function selectFirstIfNotUnique(combo) { var dialog = combo.getDialog(); combo = getSelect( combo ); var firstSelectedInd = 0; var i, child, selectefItem; for ( i = 0; i < combo.getChildren().count() ; i+=1 ) { child = combo.getChild( i ); if ( child.$.selected ) { selectefItem = child; firstSelectedInd = i; break; } } setSelectedIndex(combo, firstSelectedInd); displaySelected(dialog); } function getSlectedIndex(dialog) { var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid'); return getSelectedIndex( combo ); } //---------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------- function removePlaceHolderImg(dialog) { var urlPlaceHolder = BASE_PATH + 'plugins/slideshow/icons/placeholder.png' ; if ((dialog.imagesList.length == 1) && (dialog.imagesList[0][IMG_PARAM.URL] == urlPlaceHolder)) { // Remove the place Holder Image var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid'); combo = getSelect( combo ); var i = 0; // Remove image from image Array dialog.imagesList.splice(i, 1); // Remove image from combo image list combo.getChild( i ).remove(); } } function updateImgList(dialog) { removePlaceHolderImg(dialog); var preview = dialog.previewImage; var url = preview.$.src; var ratio = preview.$.width / preview.$.height; var w = 50; var h = 50; if (ratio > 1) { h = h/ratio; } else { w = w*ratio; } var oOption; var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid'); var ind = dialog.imagesList.pushUnique([url, '', '', w.toFixed(0), h.toFixed(0)]); if (ind >= 0) { oOption = addOption( combo, 'IMG_'+ind + ' : ' + url.substring(url.lastIndexOf('/')+1), url, dialog.getParentEditor().document ); // select index 0 setSelectedIndex(combo, ind); // Update dialog displaySelected(dialog); } } function editeSelected(dialog) { var combo = dialog.getContentElement( 'slideshowinfoid', 'imglistitemsid'); var iSelectedIndex = getSelectedIndex( combo ); var value = dialog.imagesList[iSelectedIndex]; combo = dialog.getContentElement( 'slideshowinfoid', 'imgtitleid'); combo = getSelect( combo ); combo.setValue(value[1]); combo = dialog.getContentElement( 'slideshowinfoid', 'imgdescid'); combo = getSelect( combo ); combo.setValue(value[2]); combo = dialog.getContentElement( 'slideshowinfoid', 'imgpreviewid'); combo = getSelect( combo ); //console.log( "VALUE IMG -> " + value[iSelectedIndex] ); var imgHtml = '